Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator issue during playback connection

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

    Indicator issue during playback connection

    Hello Ninjatrader team,

    I'm having a recurrent issue with on-chart indicators during playback connection, while testing my strategy. When I start playback and enable my strategy, everything works perfectly for few minutes and then one of the indicators (e.g. a native Ninjatrader Indicator, in this case the EMA in Cyan color) suddenly starts plotting from 0 (or 1000), compressing all the chart data as you can see in the attached picture. I'm backtesting with NQ replay data.

    If I pause the replay then disable and re-enable the strategy, everything goes back to normal, until it happens agains after some time.

    What is the reason for this reset in EMA (it happened with other indicators as well), and how to solve it. It is rendering the whole playback session tests unusable, and I'm losing hours of backtesting time.

    Appreciate if you can suggest a remedy for this issue.
    Last edited by ZenYoda; 07-02-2024, 10:26 AM.

    #2
    Hello ZenYoda,

    Thank you for posting.

    If you remove the EMA indicator from the chart do you see any gaps in data within your chart?
    Christopher J.NinjaTrader Customer Service

    Comment


      #3
      Hi Christopher,

      there are no gaps. If I pause the replay, disable and then re-enable the strategy, everything goes back to normal. here is a screenshot after doing just that. Also, I'm using max speed in replay, not sure if this relevant.

      Comment


        #4
        If you replay data for the same time without the strategy being enabled do you see the same behavior? Also is this a strategy you created or a strategy you purchased from a 3rd party vendor?
        Christopher J.NinjaTrader Customer Service

        Comment


          #5
          The indicator is loaded from the strategy. If I disable the strategy the indicator will not show up. It’s a strategy I developed, and the indicator is the EMA from Ninjatrader. You can see that the other indicators below the chart are not having the same issue.

          Comment


            #6
            Hello ZenYoda,

            Do you see the same behavior with the SampleMACrossover included with NinjaTrader?

            To confirm the strategy is calling AddChartIndicator() with the EMA()?
            Does the strategy add any additional series?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              1. No, It is not happening with the Sample MA Crossover strategy.

              2. Yes here is the code added for the EMA:

              if (State == State.DataLoaded)

              EMA1 = EMA (EMAPeriod);
              if (EMAChk)
              {
              EMA1.Plots[0].Brush = Brushes.Cyan;
              if (EMAShow) AddChartIndicator(EMA1);
              }

              3. Yes, the 1 tick series can be added if backtest mode is selected (It is not in this case):

              if (State == State.Configure)
              {
              if (BackTestOn)
              {
              AddDataSeries(Data.BarsPeriodType.Tick, 1);
              OrderExecSeries = 1;
              }

              Comment


                #8
                Hello ZenYoda,

                May I have you run the repair from the NinjaTrader 8.1.3.1 installer (or update to the latest release)?
                https://account.ninjatrader.com/welcome-download

                Then test using the attached exported test script.
                TestEMA_NT8.zip

                I was not able to reproduce using the test script.

                Below is a link to a video of the test.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea;

                  I did the repair and tested your strategy (TestEMA) but it did not have any issues. I uploaded a video of what's happening when I use my strategy.


                  Comment


                    #10
                    Hello ZenYoda,

                    If the test script I provided is not reproducing, the issue is likely with your custom script.

                    Try using the test script I have provided as a starting point and slowly add code to it, retesting after each change.

                    What is the last change before the behavior returns?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,

                      The strategy has more than 1000 lines of code, is there a better way to debug the issue?
                      It will be difficult to follow the path you suggested above.

                      In one instance the EMA disappeared completely from the Chart and the other indicators are broken (see screenshot attached).
                      I also noticed that the indicator now has 2 instances (A & B in the second screenshot below), one which is starting from zero, and the other one which is still within the chart / candles boundaries.

                      And one more thing, the only place where the strategy is affecting the plot on the chart is in the state DataLoaded, where the plot and AddChartIndicator are called. So how can this issue be related to other code in the strategy?

                      Could it be related to lack of system resources or poor market data quality?

                      Click image for larger version  Name:	Screenshot 2024-07-03 at 07.49.16.png Views:	0 Size:	351.2 KB ID:	1309579 Click image for larger version

Name:	Screenshot 2024-07-03 at 08.02.05.png
Views:	76
Size:	441.9 KB
ID:	1309582
                      Attached Files
                      Last edited by ZenYoda; 07-02-2024, 11:05 PM.

                      Comment


                        #12
                        Hello ZenYoda,

                        The script is dynamically adding series with conditions which is not supported, there may be other unsupported code as well causing the issue.

                        Unfortunately, without a reduced test script with only the code necessary to reproduce, I wouldn't be able to say what specifically is causing the issue.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea;

                          Ok noted. Bear with me then I have couple of questions to narrow things down.
                          1. It's unsupported to dynamically add data series, so I'll take this off for now.
                          2. Is it supported to conditionally add indicators in State.DataLoaded? sample code below:
                            • EMA1 = EMA (EMAPer);
                              ​if (EMAChk)
                              {
                              EMA1.Plots[0].Brush = Brushes.Cyan;
                              if (EMAShow) AddChartIndicator(EMA1);
                              }
                          3. I got an error today during playback today while trying to comment (//) some code to isolate the issue as you suggested, that could possibly offer a clue:

                            Indicator 'EMA': Error on calling 'OnBarUpdate' method on bar 980: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
                          4. Then I got the following error and the strategy got disabled: Strategy 'TestAlgo': Error on calling 'OnBarUpdate' method on bar 1014: Object reference not set to an instance of an object.​
                          Appreciate your patience and your help.​
                          Last edited by ZenYoda; 07-03-2024, 07:06 AM.

                          Comment


                            #14
                            Hello ZenYoda,

                            Yes, dynamically calling an indicator is acceptable.

                            With the error:

                            "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart"
                            This message indicates an invalid index was used.

                            For any index to be valid, it must be less than the size of the collection. With BarsAgo values, CurrentBar would be the size of the collection.
                            As one example, calling Close[1] when CurrentBar is 0 (the very first bar) will cause this error.
                            The reason for this is because there will not be a bar ago; essentially there is not enough data at bar 0 look back one bar.
                            The script will start from the far left of the chart at the very beginning where the CurrentBar will equal 0 and then start working to the right, calling OnBarUpdate() for each bar.
                            In this specific example, it would be needed to wait for the second bar to be built (from all series if there are multiple series added), to ensure that you have enough data to call a index 1 bar ago.
                            The general idea is to ensure that for any index used as a bars Ago value, that this index must be less than the CurrentBar value.
                            This is especially important when multiple series are added to a single script as the data for all series may not start at the same time.

                            Below is a link to the help guide on this specific example of an indexing error.


                            Also, below are links to the help guide on CurrentBar and CurrentBars.



                            Indexing errors can also occur when using an invalid index with arrays or collections and with method calls that require an index such as <string>.Substring.
                            Below are public links to 3rd party educational sites on arrays and index out of range errors.
                            https://www.dotnetperls.com/array
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank you Chelsea for the clarifications,

                              One thing though, the error I got was on bar 980 and not on bar 0, so this is a bit puzzling, and I have existing guardrails in the code already. I'm only using the chart series (I removed the conditional series addition as you suggested.

                              protected override void OnBarUpdate()
                              {
                              if (CurrentBars[0] < 15) return;
                              ...

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              61 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              40 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              21 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              23 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              51 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X