Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator lookback perfiod from strategy

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

    Indicator lookback perfiod from strategy

    Hi all,

    When calling an indicator from a strategy, if I need to access the indicator value for all bars on the chart, do I need to do anything special? I am asking on reference to lookback 256 vs. Infinite setting.

    I am doing this for the ZigZag indicator. So I basically have a strategy that calls my custom indicator and my indicator makes use of the zigzag indicator.

    Within my indicator I have the following:

    int z = 1;
    ZigZag zig = ZigZag(DeviationType.Percent, z, false);

    int zzLowBar = zig.LowBar(0, 1, CurrentBar);

    this returns -1 when a low bar can't be found. Looking at the chart visually, I can see that there is a zigzag low only it is many bars back.

    Also, it appears that when I load my study on the chart, the LowBar returns correct values.

    Any ideas what I could be doing wrong?

    Onn

    #2
    Hi Onnb1,

    Thank you for posting.

    The ZigZag indicator does change plots historically when running its calculations. This is due to ZigZag running a loop that can override the plot historically.

    You may want to check that your plot is valid when you are trying to ask it. Visually this can be fine but programmatically it can be different.

    I am attaching a link to a reference sample that will check if the indicator plots are valid before programmatically accessing them
    http://www.ninjatrader.com/support/f...ad.php?t=33061

    Please let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Cal View Post
      Hi Onnb1,

      Thank you for posting.

      The ZigZag indicator does change plots historically when running its calculations. This is due to ZigZag running a loop that can override the plot historically.

      You may want to check that your plot is valid when you are trying to ask it. Visually this can be fine but programmatically it can be different.

      I am attaching a link to a reference sample that will check if the indicator plots are valid before programmatically accessing them


      Please let me know if I can be of further assistance.
      Thanks for following up. I am aware of the way ZigZag changes the plot when price makes new highs/lows and by such resuming the trend. In my case it appears to be something else (long explanation follows so bare with me).

      If you note in my description, I am using
      zig.LowBar(0, 1, CurrentBar);

      I also have a call to in my code.
      zig.HighBar(0, 1, CurrentBar);

      Internally, these two functions check the existence of data and return -1 if they did not find any high/low bars historically within the lookback period..

      Also, as I understand, the ZigZag function does go back and adjust the plots, but adjustments are made to the most recent turning point. I am witnessing calling LowBar on a chart with thousands of bars, with many High/Low turing points - I pass in CurrentBar as the lookback so LowBar is traversing the whole chart but still not not returning with anything. To further confuse things, HighBar does return the right value (see below)

      What I observe is the following:
      1. I have a situtation where the last bar is being processed
      2. I call LowBar and HighBar one after the other.
      3. Visually I can see that the last High was 4 bars ago - HighBar returns this value just fine.
      4. The last low turning point is further away - well more than 256 bars - but it is there. There are many of them. Yet LowBar returns -1.

      The fact that HighBar is returing a value and LowBar is not, and the fact that HighBar is more recent together with the fact that the last low bar is quite a ways away got me thinking that perhaps the zigzag study is not retaining data more than 256 bars ago. Just an idea. Perhaps there is something else I am not aware of.

      Sorry for the long explanation. I hope it helps to clarify this.

      Onn

      Comment


        #4
        Hi Onnb1,

        Yes, you would need to increase your MaximumBarsLookBack time to infinite. You can choose to set it in the code or change the parameters for the strategy when you first apply it. Please note that anything the parameters are set will override the code.

        Please follow the link below on the MaximumBarsLookBack for the NinjaScript.
        http://www.ninjatrader.com/support/h...rslookback.htm

        Please let me know if I can be of further assistance.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Cal View Post
          Hi Onnb1,

          Yes, you would need to increase your MaximumBarsLookBack time to infinite. You can choose to set it in the code or change the parameters for the strategy when you first apply it. Please note that anything the parameters are set will override the code.

          Please follow the link below on the MaximumBarsLookBack for the NinjaScript.


          Please let me know if I can be of further assistance.
          Thanks - so as a general, when I am using an indicator from a strategy (it is not plotted), whatever I have set the strategies MaximumBarsLookBack to see will be applied to the indicator data series - seams pretty obvious from your answer but just want to make sure I understand for now and future reference.

          Onn

          Comment


            #6
            Onnb1,

            Correct, the MaximumBarsLookBack will be applied to the indicator that you are calling from strategy as well.

            - Cal
            Cal H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            637 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            571 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X