Different backtest results depending of ATR code placement

Forums ProRealTime English forum General trading discussions Different backtest results depending of ATR code placement

  • This topic has 3 replies, 2 voices, and was last updated 9 months ago by avatarJS.
Viewing 4 posts - 1 through 4 (of 4 total)
  • #227481

    Hello!

    I have a question regarding an ATR stop loss/profit code snippet. Here is two different codes, that produce very different backtest results. I would expect it to be the same. Why does the backtest differ when I have the stop loss and target profit outside of the “if”-statement? I guess its probably obvious for someone with more coding experience than me. Thanks in advance!

    Code 1:

     

    Code 2:

     

    #227487
    JS

    Hi,

    When you put the SL and the TP in the “IF” statement, they are only placed once, but when you put them outside the “IF” statement, they are placed every time while “ATR” values change…

    As a result, the two codes work with different “ATR” values, hence the difference…

    2 users thanked author for this post.
    #227641

    Thanks so much JS!  To me it sounds more “correct” to then place it outside of the “IF” statement then? Or would you say none is more correct than the other?

    #227671
    JS

    Hi Sandelius,

    Personally, I would always put the SL and TP within the “IF” statement because it follows the logic of your system…

    Logic “Under certain conditions, you want to enter into a transaction and then place an SL and TP…”

    (Outside the “IF” statement it is “out of control”)

    1 user thanked author for this post.
Viewing 4 posts - 1 through 4 (of 4 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login