Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Different results from backtest and strategy analyzer

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

    Different results from backtest and strategy analyzer

    Hello,

    I am getting different results using live simulated and strategy analyzer (see attached). I am using "Tick Replay" to run the strategy analyzer as close as possible to running it live. The backtest gives me different success rate than running it live. Trying to understand what I am doing wrong.
    Attached Files

    #2
    Hello pyraxic,

    To get similar results 1 tick intra-bar granularity is necessary.

    Below is a link to a forum post that discusses this.


    And a link to an example script that writes to file the differences.
    Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. 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.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, Chelsea.

      I went through the video you created as well as all the links in your post. Just to make sure that in order to match the Backtest results with the Real-time data is to add "AddDataSeries()" function to my code as stated in [1]? I do have TickReply enabled in Strategy Analyzer when running the Backtest. Is there anything else I need to do besides adding AddDataSeries() to my code?

      Here is what I have so far. Would this give me the correct results?

      Code:
      else if (State == State.Configure)
        {
          AddDataSeries(Data.BarsPeriodType.Tick, 1);
          MACD1 = MACD(Close, Convert.ToInt32(Fast), Convert.ToInt32(Slow), Convert.ToInt32(Smooth));
          MACD1.Plots[0].Brush = Brushes.DarkCyan;
          MACD1.Plots[1].Brush = Brushes.Crimson;
          AddChartIndicator(MACD1);
        }
      }
      
      protected override void OnBarUpdate()
      {
          if (CurrentBar < BarsRequiredToTrade)
              return;
      
          if (BarsInProgress != 0)
              return;
      
          if (CurrentBars[0] < 1)
              return;
      
          if (BarsInProgress == 0) {
      
              if (IsFirstTickOfBar){
                  TradeTaken = false;
               }
              // Enter Long
              if ((CrossAbove(MACD1.Default, MACD1.Avg, 1)) && TradeTaken == false)
              {
                  EnterLong(1, 1, @"Long");
                  TradeTaken = true;
              }
      
              // Enter Short
              if ((CrossBelow(MACD1.Default, MACD1.Avg, 1)) && TradeTaken == false)
              {
                  EnterShort(1, 1, @"Short");
                  TradeTaken = true;
               }
          }
      }
      [1] https://ninjatrader.com/support/foru...ularity?t=6652
      Last edited by pyraxic; 11-30-2020, 04:00 AM.

      Comment


        #4
        Hello pyraxic,

        Other than adding the 1 tick series, it is necessary to submit the entry orders to that 1 tick series using the BarsInProgress index (likely 1), as you have done in the sample code you have provided.
        EnterLong(1, 1, @"Long");

        This is correct for placing the order to the added tick series.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          After running the strategy, it is closing my position without reaching the profit mark and entering the short positions (see attached).
          Attached Files

          Comment


            #6
            Hello pyraxic,

            Be sure to focus on prints and TraceOrders.

            To confirm, an entry order is being submitted in the opposite direction to reverse the position and this is unexpected?

            Print the time of the bar and all values used in the condition that places that order.

            This will tell you why that condition is evaluating as true on that bar. From there you can decide if you want to change the condition.

            Below is a link to a forum post that demonstrates using Print().


            And a link to the help guide on TraceOrders.


            Provide the output saved to a text file and we will be happy to assist with analyzing the output.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              So let's say my primary chart is based on 1000 tick chart, can my secondary be 100 (AddDataSeries(Data.BarsPeriodType.Tick, 100)? Would that mean that the Backtest will enter trades every 100 ticks if the condition matches instead of 1000 ticks?

              Comment


                #8
                Hello pyraxic,

                Yes, you can add series with different intervals. If a 100 tick bar series is added, that series will have bars that close every 100 ticks and the primary series would have bars that close every 1000 ticks.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                44 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