Hi everyone,
I have a question: I want that the strategy makes only one trade a day or that it can makes more than one but only if the first trade of the day has a positive profit.
I have tried this but nothing changes in the performance report:
if (TradesToday(Date[0])=0)
then condition1 = True ;
if condition1 and ,,,,,,,then buy at market..
any suggestion?
Many thanks
Zanna
How to code one trade a day or...
-
- Posts: 47
- Joined: 03 Jan 2023
- Been thanked: 3 times
Re: How to code one trade a day or...
Zanna
Since no one else will have a go, ill give it an attempt. Still new but want to help where possible. As I rely on people replying to my posts hopefully. I think you can use the keywords Dailylosers or numlostrades but I am not sure if they are specific to each strategy or the overall portfolio. Doesn't say in the function description, perhaps an MC staff member can answer? How about doing something like this:
Since no one else will have a go, ill give it an attempt. Still new but want to help where possible. As I rely on people replying to my posts hopefully. I think you can use the keywords Dailylosers or numlostrades but I am not sure if they are specific to each strategy or the overall portfolio. Doesn't say in the function description, perhaps an MC staff member can answer? How about doing something like this:
Code: Select all
input: Losslimit (1);
vars: Allowedtotrade(False);
If date<>date[1] and Dailylosers(Currentdate)<= losslimit then Allowedtotrade = True;
If Allowedtotrade then begin
{ entry conditions}
end;
-
- Posts: 47
- Joined: 03 Jan 2023
- Been thanked: 3 times
Re: How to code one trade a day or...
I was thinking about this and was reading the Turtle strategy. They have a filter in which you don't take the trade if the last trade was a win.
Does anyone know how to get around this logic issue?
You could code something easy enough saying dont trade if the last trade was a win but then how do you track account for the results of the trade you didn't take.. ?
Global variable? I might post in separate post
Does anyone know how to get around this logic issue?
You could code something easy enough saying dont trade if the last trade was a win but then how do you track account for the results of the trade you didn't take.. ?
Global variable? I might post in separate post
Re: How to code one trade a day or...
Hi and thanks for your help. I have tried also your suggestion but doesn't work. I thinks that the reserved word tradestoday doesn't work .
It seems an easy istruction to code but I can't find the solution
It seems an easy istruction to code but I can't find the solution
-
- Posts: 47
- Joined: 03 Jan 2023
- Been thanked: 3 times
Re: How to code one trade a day or...
Did you try daily losers and numlostrades keywords? I don't really do intraday strategies so its not something I have researched yet or am familiar with. I would also like to know this piece of code. It could be a nice function to have saved. If I have time this week I may play around with one of my strategies on the intraday and see if I can limit the trades taken.
Hopefully someone else jumps in with some ideas/input
Hopefully someone else jumps in with some ideas/input
-
- Posts: 47
- Joined: 03 Jan 2023
- Been thanked: 3 times
Re: How to code one trade a day or...
Zanna
Was playing around with this function today "limit losing trades" and got the start of something which appears to work. Need to double-check works on diff instruments/timeframes but you can make a function like this below. A counter and then create a "loss_per_day" input value that you can use in the entry condition.
Also if your interested I am trying to set up a telegram group/ maybe discord in which people new to MC can share strategy code or come together to upvote ideas and get them build by professional for super cheap per person. See below seems you new and could be interested.
https://t.me/+h8iTLItDWGAxNGY0
Was playing around with this function today "limit losing trades" and got the start of something which appears to work. Need to double-check works on diff instruments/timeframes but you can make a function like this below. A counter and then create a "loss_per_day" input value that you can use in the entry condition.
Code: Select all
variables: Closed_netprofit(0), Counter(0), trade_losses(0);
Closed_netprofit = i_ClosedEquity;
if date<>date[1] then begin
counter=0;
end;
if Closed_netprofit < Closed_netprofit[1] then
Counter=Counter+1;
trade_losses =counter;
limit_losing_trades = trade_losses;
https://t.me/+h8iTLItDWGAxNGY0
- rrams
- Posts: 129
- Joined: 10 Feb 2011
- Location: USA
- Has thanked: 7 times
- Been thanked: 70 times
- Contact:
Re: How to code one trade a day or...
Hello Zanna,
The TradesToday function does work as intended, (although it should more appropriately be called EntriesToday). It may not have worked for you because of any of the following reasons:
1. You forgot to reset the condition1 back to false after every bar.
2. You didn't get enough signals to trigger multiple entries per day.
3. You misunderstood the difference between a trade, an entry and a position.
4. Your symbol has a trading session that spans multiple days.
...or some other reason. It is impossible to tell without all the code.
Here is an example of a complete trading system that only takes one trade per day unless the first position that was entered and closed in the day is profitable. In that case it takes unlimited trades for the day:
You may want something different. You didn't specify what to do with overnight positions that carry a profit into the next day. Or you might want your profit window to encompass session times not calendar times. Consider paying a small fee to me or others to write exactly what you need as the coding can be a little tricky.
The TradesToday function does work as intended, (although it should more appropriately be called EntriesToday). It may not have worked for you because of any of the following reasons:
1. You forgot to reset the condition1 back to false after every bar.
2. You didn't get enough signals to trigger multiple entries per day.
3. You misunderstood the difference between a trade, an entry and a position.
4. Your symbol has a trading session that spans multiple days.
...or some other reason. It is impossible to tell without all the code.
Here is an example of a complete trading system that only takes one trade per day unless the first position that was entered and closed in the day is profitable. In that case it takes unlimited trades for the day:
Code: Select all
// Multiple trades per day if the first trade closed profitable.
vars: TradeProfit(true), N(0), MP(0);
MP=MarketPosition;
TradeProfit=true;
// One or more closed positions held today.
if ExitDate(1)=D then
begin // Scan all CLOSED entries for the first
for N=1 to MaxPositionsAgo-1 // one of the day and check if profitable.
begin
if EntryDate(N)<>D then break
else if PositionProfit(N)>0 then TradeProfit=true else TradeProfit=false;
end;
end;
// Allow open positions to be closed.
if MP>0 and C<C[1] then sell next bar market;
if MP<0 and C>C[1] then buytocover next bar market;
// Enter new positions if allowed.
if MP=0 and TradeProfit and C<C[1] then sellshort next bar market;
if MP=0 and TradeProfit and C>C[1] then buy next bar market;
Re: How to code one trade a day or...
Thanks Rramms,
Maybe the problem is that I haven't written the reset the condition1 back to false after every bar.
How I code it?
For example
I want to enter a long trade only once a day.
But how I have explained the function tradestoday seems don't work
Maybe the problem is that I haven't written the reset the condition1 back to false after every bar.
How I code it?
For example
Code: Select all
if tradestoday(0)=0 then condition1=true;
if condtion1 and c>highd(0) then buy next bar at market;
]if mp=1 and c<lowd(0) then sell next bar at market;
But how I have explained the function tradestoday seems don't work
Last edited by zanna77 on 29 Mar 2023, edited 3 times in total.
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
- rrams
- Posts: 129
- Joined: 10 Feb 2011
- Location: USA
- Has thanked: 7 times
- Been thanked: 70 times
- Contact:
Re: How to code one trade a day or...
zanna,
Are you using realtime Synchronous AutoTrading mode? If that is the case then the EntryDate() keyword is going to give you trouble and a different solution is necessary.
Are you using realtime Synchronous AutoTrading mode? If that is the case then the EntryDate() keyword is going to give you trouble and a different solution is necessary.