Backtest shows wrong results

Forums ProRealTime English forum ProOrder support Backtest shows wrong results

Viewing 15 posts - 1 through 15 (of 29 total)
  • #211325


    I’m running a system with a partial close code that shows that it’s closing positions in backtesting, but it doesn’t happen when live. How could this happen? Spread is the same, or even lower live, but this keeps happening. The stoploss also resets itself at completely the wrong level for no apparent reason. It’s quite maddening!

    This is a revised version of my code.

    I’ve attached a couple of pictures that show this issue when the system is live. As you can see in the first picture the system should’ve sold a portion of the position and then moved the stop to breakeven. Instead I logged in to see it had set the stop loss to a completely different, made up level faaar away. I closed it manually. In the second picture you can see that when live the system doesn’t close the positions at nearly the same level as in back test. How is this possible?


    I found another example. Again the system should’ve partially closed the open position in the afternoon, but didn’t, and instead closed the entire position when it hit the ma 450. Again, costing me money.


    Isn’t the MA450 in the TF 1hour completely somewhere else at the moment or am I misunderstanding your code?


    The system runs on 1m TF, on us tech 100(nasdaq). Not sure of the relevance though tbh. The question is, why does the backtest act completely differently to live, when spread etc. are the same.


    Misread your reply. Yes, it’s probably somewhere else at the moment. Again, that’s not relevant?


    Je voudrais le tester : indice ou forex et quelle unité ?


    I don’t speak french.


    I would like to test it: indice or forex and which unit?


    Nasdaq 1m


    Hi @ProRealPierre,

    I’ve only looked at your code superficially but what strikes me is that your Stop Loss is reposted every time by:

    If OK and OnMarket then

    Set Stop Loss SL


    The actual SL is calculated with:

    TimeFrame(1 Hour)

    SL = PositionPrice + AverageTrueRange[14](Close) * PipSize

    So every hour your SL will change and be reinserted… (is this the intention?)

    On the partial closure of positions:

    I don’t know any better that partial closure only works in “backtesting” and not in “live” at IG… but maybe this has changed…???


    Hello @JS,

    Yes, that’s the intention, though I don’t mind changing it if it fixes the problem with the SL. See the first picture I’ve attached to this post. It show’s the SL yesterday being put at 21082, though according to the backtest it should’ve been set to roughly 12010.

    That’s changed then, yes. See the second attached picture which shows another system of mine partially closing the position as it should.


    Glancing over your code … it is full with ambiguities.  This really can’t work. Like JS said, reposting the SL is a first thing I would stay far from.

    Then, you can’t have several SL commands in there in the first place because only the last one executed will be THE one and only which is active.

    Next you have pending Stops which also don’t combine with SL. Oh, it can, if you have very explicit mutual exclusive pieces of code for it. This is quite hard in itself (to make decent) and you seem not to know about it. And thus nothing works.

    Next, what you see from the Backtest, never comprises reality when MTF is in order *and* when pending orders are used (Limit, Stop). Those orders only fall on the main TF limit. However, in practice it will just work fine (in Live). So this is “interpretation” as such (the gain reported by the backtest will act upon the correct price levels of exit (and entry))

    Lastly – and a positive one – you can partially close orders as much as you want. But, do it the correct way (I have no judgment on your code regarding this – I just did not look for it).

    Now tell me this is on PRT-IB and someone might delete my post and I’d have to create a new one. ‘-)


    Thanks for your reply, @PeterSt!

    I see your point. I’ll change the stop to sell at at stop instead of setting the stop loss, and see if that works better.

    Appreciate the help!


    @robertogozzi, or @Nicolas, do you have any idea as to why my system won’t partially close positions? I could understand slippage being the reason in cases where it just touches the level, but that doesn’t look to always be the case(look at the picture “ex3”, for example). Sometimes it just doesn’t partially close. There is seemingly nothing wrong with the code, right? I mean, sometimes it works..


    Would you trust your money to a code that sometimes works? 😉

Viewing 15 posts - 1 through 15 (of 29 total)

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