Not logged in
Viewing 3 posts - 1 through 3 (of 3 total)

Forums>StrategyQuant>General Discussion>Assistance on code to get backtest to work

  • #268819 |
    43 Posts

    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?




    1823 Posts


    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

    43 Posts

    Fantastic thanks Tomas, really appreciate all your assistance. Will try it out.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.