Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtester is turning losing trades into winning trades by reversing transactions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Backtester is turning losing trades into winning trades by reversing transactions

    Hi,

    I've made a simple strategy that goes long on a green bar with a limit sell to exit, but if a red bar shows up the limit sell is cancelled and the position reverses to short, then aims to limit buy exit for profit. If it's short and a green bar appears, it reverses to long again.

    I've gotten great results in backtesting until I looked at the actual chart and have found that the backtester is reversing my results, like a trade that should have been a short entry that loses and reverses long, is being called by the backtester as a successful long entry with a profitable selling exit.

    Does anyone have any experience or explanation for backtester completely inverting a losing trade into a winning one like this? It is really skewing my system's statistical results and I don't know what to believe as to its usability

    I also understand that I might just be over-coding and missing something obvious so I'll continue to look at this, but I'd like to know if anyone knows of any issues with backtester mistaking the chronological order of regular managed trades, EnterLong, EnterShort, etc

    thanks!

    #2
    Hello RunnrX,

    If I am understanding what you are looking for in your strategy is to prevent NinjaTrader from reversing your position.

    If this is correct, then you may want to add a check in your condition to make sure that your Position is Flat before entering a trade. As by default using the Managed Approach in NinjaTrader, if there is a signal for the opposite direction NinjaTrader will automatically reverse your position and send a order to close your position and then another order in that direction.

    Here is a link to our Help Guide that goes over how to check a strategies MarketPosition that you may view.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thank you for also looking into this with me!

      What I'm trying to say is hard to explain, but I can try to re-word it.. I actually do like to have positions reverse, some of the time, and that isn't the nature of the problem I'm having.

      It's something more like this:

      I get a signal to go from flat to short. The strategy is designed to go short, and aim for a 6 pip buy-to-cover limit as a profit target. Let's say it never reaches that buy-to-cover level, and price continues to go up to the point that I get a signal to reverse and go long. I should reverse and go long. But here is what I see the backtester showing instead.

      At the short signal, it is displaying a BUY transaction called "profit target" to enter. Then it runs up to the point that the long signal to give up and reverse is showing, and it sells to close, calling that transaction "short entry". It was supposed to be a losing trade according to the way the program is designed, and it live trades like this correctly, but the backtesting mode is recording it "backwards" like that and it makes the trade history log a bunch of profits that should have been losses.

      My strategy only uses EnterLong and EnterShort, and has a managed profit target of 6 pips, and this is backtesting mode so overfill shouldn't be an issue, so I'm just asking if it's a known issue that sometimes the backtester can confuse entries and exits for some reason, because I seem to be finding it in my situation and now I can't go by what the result statistics are telling me.

      I suspect that it might have something to do with it trying to exit on close at the end of a daily session (I'm using 10 minute bars) because it seems to trade fine for the first session and then it gets weird after a few sessions have passed.

      One more thing, is that I'll be away from my computer for the rest of the day so I won't be able to look directly at it but I am also open to the thought that I'm just overlooking something really obvious that I could fix, but what I've written above seems to be my experience anyway.

      Comment


        #4
        Hello RunnrX,

        Thanks for the information.

        It sounds like your short entry was never processed but your Profit Target order was submitted.

        Can you add TraceOrders = true inside of your Initialize() and then open up the Output Window (Control Center -> Tools) and let me know if your Short Entry is being Ignored with Reason why.

        JCNinjaTrader Customer Service

        Comment


          #5
          Hi,

          I'm sorry for the delay in my reply - but I believe I've found the problem.

          I was using an odd session template and it was carrying positions over from intraday sessions to the next one and seemed to be throwing off the orders. I am running the backtester again right now and I can't see any problems with execution anymore.

          Thank you for helping me look through this!

          Comment


            #6
            Hello RunnrX,

            Glad to hear that you have found the problem.

            Let us know if we can be of further assistance.
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X