Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Mirrored strategy: orders missing in backtest/chart of short version???

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

    Mirrored strategy: orders missing in backtest/chart of short version???

    Hi, I have coded a very simple strat and realized that it has a quite linear downward trending equity curve in the backtest. So I decided to code the strat, that does exactly the opposite.
    Then I have found a weird behavior of the backtesting engine that results in many less trades in the mirrored version. As you can see in the attached screenshots, the upper chart has all the correct long trades according to the strat. But the lower chart has only some of the reversed trades of the mirrored strat. Many are missing, which should be there according to the code. In the first comparison you can see the first 4 trades are exactly mirrored from long to short, but the next 8 trades are missing. The next trade should reenter short at 4379.75, exactly where in the lower chart the long entry takes place. THen in other sections all the mirrored trades are there as they should as seen on the other picture.

    I cannot see any reason why those trades are missing. The properties are set exactly the same, the code is just changes, so the short strat does the opposite compared to the long strat. In the historical 1 year performance you can also see that the long version has 11942 trades, while the short version has only 1565 trades, although entry criteria are the same only short instead of long.

    Why could this be happening?

    #2
    Hi philmg, thanks for posting. I moved your post to the Strategy development section of the forum.

    The same code + same data + same parameters will always equal the same results in a backtest. The best way to find the difference is to first look at the list of trades each strategy made, not just the summary view. Change the view on the top left to "Trades" or "Executions" and see where the trades are different. There could be more trades at the beginning or end of the data set. Another way to debug will be to add Print(); throughout the strategy to print the data. Be strategic in where you place the prints like in the entry condition. e.g.

    if(<Entry Condition>)
    {
    Print("Entry Condition Reached");
    Print(Time[0]);
    EnterLong();
    }

    When you run the backtest, you will see the prints show up in the output window.

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Looking at the trades 1 by 1 on the first day you can see that the are exactly the same, only reversed for the first 11, then the short trades just stop for the rest of the day 2/22/2021 and restart on 2/23/2021 and match the long trades again for another couple before diverting again. I don't know how to add the print function in strategy builder. I have to unlock the code for this right?

      Comment


        #4
        Hi, thanks for your reply.

        You do not need to unlock the script to add print, the Print function is in the Misc folder of the actions. If you need to add a Print outside of the conditions, make a new set with no conditions, and just add the Print in the actions, this Print will activate every time time OnBarUpdate is called (all sets run within OnBarUpdate)

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          I have checked the entry conditions with the print function and they are met. The problem remains: In the short version of the strat a most of the trades simply don't show, while a few completely mirror the long version. The short trades just stop for a while and then resume and it seems random. I have only 1 entry condition: If the close is below the 3SMA of the low of the secondary series (which is the same underlying, but 15 min chart), then enter a short limit order at the 3SMA of the low of the secondary series. As you have seen it works for some bars just as the mirrored long version, but more than 50% of the trades just don't show. The short trades stop at some point during the day, so that only the mirrored longs continue. Shorts show up again 00:00 next day, then stop again at some point. It seems really odd. Why would something like this happen?
          Last edited by philmg; 02-21-2022, 02:24 PM.

          Comment


            #6
            What I found out now is that, when I select >1 for "entries per direction", then suddenly the short strat executes all the orders, just as for the mirrored long strat. But it never enter more than 1 trade. What might be causing this?

            Comment


              #7
              Hi philmg , thanks for the follow up. It could be a historical overfill where the exit order and a Set order (like SetStopLoss) both get filled at the same bar historically. If the strategy runs OnEachTick you can set a 1 tick series for the High Order Fill Resolution setting or do not mix Exit orders and SetStopLoss to exit a position if the strategy runs OnBarClose.

              Best regards,
              -ChrisL
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              26 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, Yesterday, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              192 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,234 views
              0 likes
              Last Post xiinteractive  
              Working...
              X