• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Zig Zag Indicator doesn't plot until 20 bars

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

    Zig Zag Indicator doesn't plot until 20 bars

    The Zig Zag indicator can start plotting after 2 bars, but won't start plotting until 20 bars. It doesn't change BarsRequiredToPlot whose default value is 20.

    #2
    Indicators need a minimum amount of historical bars in order to create a meaningful plot. This is the case with all indicators. All indicators will not visually plot until at least 20 bars of historical data exist on your chart.
    Patrick G.NinjaTrader Customer Service

    Comment


      #3
      The following indicators change the BarsRequiredToPlot so as to plot sooner then the first 20 bars. The code specifically sets BarsRequiredToPlot to a value other than 20.
      • Volume Up Down
      • Range
      • Buy Sell Pressure
      • Buy Sell Volume
      • Current Day OHL
      In the code for Zig Zag indicator

      Code:
              protected override void OnBarUpdate()
              {
                  if (CurrentBar < 2) // Need at least 3 bars to calculate Low/High
                  {
                      zigZagHighSeries[0]        = 0;
                      zigZagLowSeries[0]         = 0;
                      return;
                  }
                  ...
      I have also attached a photo of the Zig Zag indicator with BarsRequiredToPlot set to 3 and highlighted the first 20 bars of this chart. 4 segments of the ZigZag are plotted that won't be if the BarsRequiredToPlot is set to the default value of 20 instead of 3.

      Comment


        #4
        Hello ntbone,

        The ZigZag indicator does not actually use a plot set with plot values.

        Instead this custom renders the lines in OnRender() in the code starting on line 348.

        Because of this, BarsRequiredToPlot does not affect the custom rendered line.

        Changing where this indicator starts rendering would require changing the custom logic within a copy of the script.

        In your screenshot we can see the line starts on bar 8, 12 bars before bar 20.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I have attached a screen shot of the exact same chart from my earlier screen shot with BarsRequiredToPlot for ZigZag set to 20 instead of 3. Notice the custom rendered line now starts after the yellow region. BarsRequiredToPlot seems to be impacting this OnRender code. This is the only code change made to the indicator.

          I am using AAPL on a 1 minute chart from 2019/11/21 with the ZigZag set to 0.1 points.

          Comment


            #6
            Hello ntbone,

            Your inquiry is that when setting BarsRequiredToPlot to less than 20 that the plot does show until 20 bars, is this correct?

            Your last screenshot does not appear to agree with this.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              The yellow region is a drawing I created. The blue line is from the Zig Zag indicator. In my first screen shot in post #3, where BarsRequiredToPlot is set to 3, the blue line shows from the first detected place. In the second screen shot included in post #4 with the code set back to its installed state, the Zig Zag blue line doesn't start until outside the yellow region (which is the first 20 bars). Everything else about the two screen shots is identical.

              Comment


                #8
                Hello ntbone,

                Are you adding prints to understand the behavior better?

                Are you not liking that the ZigZag is able to start before 20 bars?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  With the Zig Zag indicator as installed, it won't plot anything prior to 20 bars despite being capable of plotting earlier.

                  There was no need to print out anything. I apply the indicator to a chart, and notice it won't plot anything for the first 20 bars, then I change the code adding the line BarsRequiredToPlot = 20. I remove the indicator and add it back in (since the code change alone won't apply to the existing indicator) and now I get plots starting much sooner.

                  I am suggesting that the code be changed with BarsRequiredToPlot set to 3 since the code won't do anything until there CurrentBar >= 2.

                  To reproduce the problem
                  1. Apply the Zig Zag indicator to 1 minute chart of AAPL with 390 bars of history. Set the Deviation value to 0.1
                  2. Notice that nothing will show up in the first 20 bars
                  3. Remove the indicator.
                  4. Add the line BarsRequiredToPlot = 3 to the OnStateChange method SetDefaults state.
                  5. Add the Zig Zag back.
                  6. Notice now that the zig zag line will plot within the 20 bar range.
                  I'd also like clarification on some of the information above. Specifically "Because of this, BarsRequiredToPlot does not affect the custom rendered line" which doesn't seem to be true in this case. Changing BarsRequiredToPlot to a smaller value is the only way I have found for the code to render the blue line somewhere in the first 20 bars.

                  Comment


                    #10
                    Hello ntbone,

                    This is true for all of the system scripts in NinjaTrader that have plots.

                    Anything with plots start at 20 bars. You can make a copy and change this in any of the indicators supplied with NinjaTrader.

                    The ZigZag is a different kind of beast because it technically doesn't set plots. (You may notice the values are n/a in the Data Series window)
                    There might be some logic in there to start the rendering after 20 bars, but its still going to be after the point of where the first leg is calculated to start.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      The Volume indicator has plots and the BarsRequired is set to 0 so I am finding inconsistencies. There is no logic that I have found in the Zig Zag indicator that prevents anything aside from the line of code I pointed out that prevents it from doing any calculates until the CurrentBar > 2. Further
                      1. Moving Average indicators (SMA, EMA) can start as soon as the period has passed. If I am looking at a 10 SMA/EMA it can plot as soon as 10 bars into the data. It needs the period # of bars to start plotting. If I am however looking at a 50 SMA, then there won't be any average until 50 bars into the plot. A 200 MA is even further out. In this case BarsRequiredToPlot should ideally be set to the period provided by the user.
                      2. I listed in an earlier post a list of indicators that change the BarsRequiredToPlot to be a value other than the default value of 20. Range and Volume are included in this.
                      3. BarsRequiredToPlot appears to limit the OnRender method from being called until after the chart has BarsRequiredToPlot.
                      I have already gone ahead and made my own copy of ZigZag and made this change. I posted this so that you could update the code officially to match the behavior of the indicator.

                      Comment


                        #12
                        Hello ntbone,

                        Yes, you are correct, there are some exceptions and there are some indicators that don't use plots at all.

                        The VOL and Range indicators are exceptions that do set BarsRequiredToPlot to 0, and begin plotting on the first bar.

                        If you are referring to the unmodified SMA indicator that is supplied by NinjaTrader, this will start plotting after 20 bars, no matter what the Period is set to.

                        Please add the SMA indicator to a chart and count the number of bars before the plot appears.

                        I'm happy to submit a feature request to use your script if you would like. It would be up to the NinjaTrader Development to decide if or when that would be implemented.

                        If you simply want to share this file, you can upload the file for sharing on the User App Share section of the forums.
                        https://ninjatrader.com/support/foru...app-submission
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello ntbone,

                          We have submitted a request to adjust all NinjaTrader 8 system indicators so their BarsRequiredToPlot property is set to the absolute minimum for each indicator. The tracking ID is SFT-4435.

                          As Chelsea mentioned, it will be up to Product Management and Development to determine if/when these changes will be made. Your interest and feedback is tracked, however.

                          We look forward to assisting.
                          JimNinjaTrader Customer Service

                          Comment


                            #14
                            setting Colours in addPlot

                            Comment


                              #15
                              Hello Emma1,

                              Please see:
                              https://ninjatrader.com/support/foru...65#post1081265

                              We request that you do not post the same inquiry multiple times on the forums.

                              Further, this inquiry is not related to the topic of this thread.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Leeroy_Jenkins, Today, 06:54 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Leeroy_Jenkins  
                              Started by rainbow47, Today, 06:10 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post rainbow47  
                              Started by stenberg98, Today, 04:53 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post NinjaTrader_Marco  
                              Started by wukefuha, Today, 03:20 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Marco  
                              Started by mbcmbc, Yesterday, 10:12 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChrisSch  
                              Working...
                              X