Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The backtesting of the strategy is wrong.

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

    The backtesting of the strategy is wrong.

    Hi

    I have a very weird behavior when backtesting a strategy. In the specific example of the screenshot, you can see 2 cases. Both cases are entering short position and targeting the close of the next bar. In both cases, the TP should be hit, but weirdly, for the first case the SL is hit but for the second case the TP is hit. Could someone maybe explain to me what is the issue here?

    Thank you

    #2
    What does your code look like? Where exactly is your TP supposed to be and when is it placed? You are targeting the close, but is it exactly at the close? or is there an offset? What is your calculations based off of? OnBarClose? OnPriceChange or OnEachTick? Let's start from there and see where that takes us.

    Comment


      #3
      So for my TP and SL I have configured a user input, which I can use to provide from the strategy analyser. The user input is being used inside the take profit and atop loss elements with calculation type ticks.
      on the example of the screenshot, the brick size is 40 ticks and there is a trend threshold set to 20 (it is a custom renko bar). The TP is set to 20 ticks. It is set to calculate the TP from the entry signal.
      my calculation is based of each tick, but also tried per bar close and it did not fix it.

      Comment


        #4
        I'm not too sure if it matters unless it's being tested live, but what are the times for these blocks? Is it all in quick succession being too fast to fill properly? It looks like it should work. Are you using anything to simulate accurate fills that might be the reason it's not getting filled earlier?

        Comment


          #5
          Hello,

          Thank you for your post.

          Please review the help guide page on the differences on real-time vs backtest.



          Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics. Instead these are filled based on logical rules from processing historical data.
          • When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data.
            • This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known
            • Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.
          Intra-bar granularity adds a second data series such as a 1 tick series using AddDataSeries() so that the strategy or indicator has the individual ticks in the historical data in between the High and Low of the primary series.

          In NinjaTrader 8, there have been two new enhancements so that programmers may not have to manually add this secondary series and code the script for high accuracy fills (Order Fill Resolution) or for intra-bar actions (TickReplay) depending on the needs of the script.
          Note: bar types that are IsRemoveLastBarSupported cannot be used with TickReplay and generally cause inaccurate results when backtesting in historical data.
          Note: High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

          Please see this support article for a detailed explanation:

          https://support.ninjatrader.com/s/ar...ar-granularity​​

          Comment


            #6
            Hi NinjaTrader_Gaby

            Thank you for the reply. Is it possible to achieve the above without coding, by using the strategy builder?

            Best regards

            Comment


              #7
              If you are using Calculate.OnEachTick or OnPriceChange, and/or your strategy is multi-series, you will need to manually implement intrabar granularity for accurate order fills, which is not possible using the Strategy Builder. You would also need to enable Tick Replay if you are using OnEachTick or OnPriceChange.

              If you're using Calculate.OnBarClose, and your strategy is single-series, you could try using High Order Fill Resolution in the Strategy Analyzer instead.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              43 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              124 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              65 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X