Assistance on code to get backtest to work
2 replies
mattedmonds
3 years ago #268819
I have an EA that trades against the trend in M1 timeframe, looking for a reversal. It can get big drawdowns when the 20 pip stop loss is hit and it re-opens a position again.
I have added code to try to stop this from happening by using at the start of the trade entry condition:
Closed P/L in Pips > -19
or Bars since Order Closed > 500 (in M1 this is 500 minutes)
The problem that I have is that it wont start the first trade in backtest as it won’t meet either of these conditions, so it doesn’t trade.
To try to resolve this I added:
or Market Positions Count = 0
which I would have assumed would get the first trade started, but it still isn’t back testing. Any suggestions to get it to work?
Thanks,
Matt
tomas262
3 years ago #268871
Hello,
you can add this into your condition to make the strategy open the first trade even if there was no trade previously open
if (Bars since Order Closed == -1) OR (… your existing condition …)
If the function cannot find a previous order (it will be the first trade) it return value = -1
Let me know if that helped
mattedmonds
3 years ago #268877
Fantastic thanks Tomas, really appreciate all your assistance. Will try it out.
Viewing 2 replies - 1 through 2 (of 2 total)