Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Question regarding MaximumBarsLookBack

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

    Question regarding MaximumBarsLookBack

    Hi,

    If MaximumBarsLookBack is set to 256 and I create an indicator, say an SMA, with a period longer than 256, say 500, what will the effect be? Will it calculate the SMA values properly using the full 500 period window or will it use only 256? Even worse, since the storage of a dataseries is implemented as a ring list when MaximumBarsLookBack is set to 256, will it wrap around to the start of the list when the index is past 256 and generate garbage values that aren't related to reality at all?

    Regards,

    Luke

    #2
    My guess is that the SMA500 will be calculated correctly.
    The lookback period of 256 refers to how many entrys there can be in the dataseries of the SMA(500).This means that you can retrieve "historical" values of the SMA(500) for bar 0 to bar -256.
    So SMA(500)[256] gives you the SMA500 of bar -256 to -756

    Marco

    Comment


      #3
      Originally posted by marcow View Post
      My guess is that the SMA500 will be calculated correctly.
      The lookback period of 256 refers to how many entrys there can be in the dataseries of the SMA(500).This means that you can retrieve "historical" values of the SMA(500) for bar 0 to bar -256.
      So SMA(500)[256] gives you the SMA500 of bar -256 to -756

      Marco
      Thanks for the response Marco. I'm not convinced you're correct however.

      Here is the code for NT's SMA indicator:

      Code:
      protected override void OnBarUpdate() 
      { 
      
           if (CurrentBar == 0) 
                Value.Set(Input[0]);
           else { 
                 double last = Value[1] * Math.Min(CurrentBar, Period); 
                 if (CurrentBar >= Period) 
                       Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period)); 
                else  
                     Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1)); 
                }
      }
      You can see there is a reference in the formula to Input[Period]. If the input series only has 256 bars in it and the period is 500, I don't see how it could return a correct result.
      Last edited by HitTheCity; 02-27-2013, 11:19 PM.

      Comment


        #4
        Luke, how do you determine the input would only have 256 bars? In that event a 500 bar SMA could not be calculated fully.

        The lookback setting for the data series objects only determines how many bars back would be accessible programmatically - this is to conserve memory since most studies don't need extensive referencing.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by HitTheCity View Post
          Thanks for the response Marco. I'm not convinced you're correct however.

          Here is the code for NT's SMA indicator:

          Code:
          protected override void OnBarUpdate() 
          { 
           
               if (CurrentBar == 0) 
                    Value.Set(Input[0]);
               else { 
                     double last = Value[1] * Math.Min(CurrentBar, Period); 
                     if (CurrentBar >= Period) 
                           Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period)); 
                    else  
                         Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1)); 
                    }
          }
          You can see there is a reference in the formula to Input[Period]. If the input series only has 256 bars in it and the period is 500, I don't see how it could return a correct result.
          I presume that you are talking about the SMA of an OHLC member? In which case, Input refers to an OHLC value. Those values have nothing to do with, and are not limited by MaximumBarsLookBack.

          Comment


            #6
            Originally posted by koganam View Post
            I presume that you are talking about the SMA of an OHLC member? In which case, Input refers to an OHLC value. Those values have nothing to do with, and are not limited by MaximumBarsLookBack.
            Correct koganam, I was in that instance refering to an OHLC member. So does this mean Marcow's interpretation was correct? i.e. If MaximumBarsLookBack is set to 256, you can only retrieve the last 256 'historical' values of an SMA(500), but that those values will be calculated correctly based off a period of 500?

            What about the following scenario when MaximumBarsLookBack is set to 256:

            SMA(SMA(100), 500));

            In that case, the input to the outside SMA is not an OHLC value, but another indicator's dataseries. In this case, would the outside SMA with period specified as 500 be able to only access the last 256 values of the inside SMA?

            Comment


              #7
              Originally posted by koganam View Post
              I presume that you are talking about the SMA of an OHLC member? In which case, Input refers to an OHLC value. Those values have nothing to do with, and are not limited by MaximumBarsLookBack.
              Sorry, after further reading, can you clarify what the difference is between an OHLC member and a dataseries is? According to http://www.ninjatrader.com/support/helpGuides/nt7/index.html?ontermination.htm MaximumBarsLookBack effects every object that implements the IDataSeries interface, which, according to http://www.ninjatrader.com/support/helpGuides/nt7/index.html?barsrequired2.htm, both Indicators and all types of DataSeries do.

              Comment


                #8
                Originally posted by HitTheCity View Post
                Correct koganam, I was in that instance refering to an OHLC member. So does this mean Marcow's interpretation was correct? i.e. If MaximumBarsLookBack is set to 256, you can only retrieve the last 256 'historical' values of an SMA(500), but that those values will be calculated correctly based off a period of 500?

                What about the following scenario when MaximumBarsLookBack is set to 256:

                SMA(SMA(100), 500));

                In that case, the input to the outside SMA is not an OHLC value, but another indicator's dataseries. In this case, would the outside SMA with period specified as 500 be able to only access the last 256 values of the inside SMA?
                Your inner entity is a Plot. MaximumBarsLookBack is always infinite for Plots.

                ref: http://www.ninjatrader.com/support/h...rslookback.htm

                Comment


                  #9
                  Originally posted by HitTheCity View Post
                  Sorry, after further reading, can you clarify what the difference is between an OHLC member and a dataseries is? According to http://www.ninjatrader.com/support/helpGuides/nt7/index.html?ontermination.htm MaximumBarsLookBack effects every object that implements the IDataSeries interface, which, according to http://www.ninjatrader.com/support/helpGuides/nt7/index.html?barsrequired2.htm, both Indicators and all types of DataSeries do.
                  OHLC form a barSeries. BarSeries are a different entity from DataSeries..

                  ref: http://www.ninjatrader.com/support/h...rslookback.htm

                  Comment


                    #10
                    Originally posted by koganam View Post
                    OHLC form a barSeries. BarSeries are a different entity from DataSeries..

                    ref: http://www.ninjatrader.com/support/h...rslookback.htm
                    I think the way we're both quoting refs from the help guide isn't working correctly. It seems the URI doesn't update when you click a different topic in the index pane on the left in the help guide. Anyway, that's another problem...

                    Thanks for clarifying, I think I understand the differences now. If I do indeed understand correctly, one consequence of this is that it is in fact not possible to instantiate the built in SMA indicator and NOT have it store an infinite number of bars, since it's values are stored in a Plot type. This may actually explain why I'm having problems with high memory consumption despite setting MaximumBarsLookBack to 256.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by judysamnt7, 03-13-2023, 09:11 AM
                    4 responses
                    57 views
                    0 likes
                    Last Post DynamicTest  
                    Started by ScottWalsh, Today, 06:52 PM
                    4 responses
                    36 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by olisav57, Today, 07:39 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post olisav57  
                    Started by trilliantrader, Today, 03:01 PM
                    2 responses
                    19 views
                    0 likes
                    Last Post helpwanted  
                    Started by cre8able, Today, 07:24 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post cre8able  
                    Working...
                    X