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

unstable period of various calculations

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

    unstable period of various calculations

    OK, I've moved this conversation here because Ryan asked me to do so.

    Originally posted by NinjaTrader_RyanOlson View Post
    NinjaTrader's definition for a stable indicator is 20 historical bars.
    20 bars - fixed? Regardless of what any applied indicators are or do? Ouch!

    For example, an SMA is not "stable" until N bars, where N = the period. I've read that an EMA should have N*2 bars. I am not sure of the WMA, though I would guess N+1.

    So basically, the NT definition of unstable has nothing to do with reliability. Glad I asked. :-/ If this is something users have to manually override, is there anyone who can discuss the "unrelaible" period of various calculations with me? My mind is stumbling over, say, a triple smoothed average with 3 different periods. x = EMA(WMA(WMA,a),b),c);

    Thank you

    #2
    Not sure where Ryan came up with that definition, 20 bars isn't set in stone... There is a (relatively) easy solution to make sure there is enough data on your charts/for your strategy.

    If you have three different periods for indicators named a, b, and c, you could do this in OnBarUpdate():
    Code:
    protected override void OnBarUpdate()
    {
    // get the maximum period
    int abMax = Math.Max(a, b);
    int bcMax = Math.Max(b, c);
    int maxmax = Math.Max(abMax, bcMax)
    
    // stop the strategy/indicator if there isn't enough information for a stable calculation
    if (CurrentBar < maxmax)
        return;
    }
    Another option would be to set the Min. Bars Required value higher than any period setting you have in the strategy settings.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thank you, Austin. Some clarification, please.

      This is during indicator programming (not strategy) so don't we want calculations to begin before they are plotted, so that the calculations can get past the unstable period into relaible values.

      Code:
      if (CurrentBar < maxmax) return;
      would this prevent any calculations at all.
      In a strategy it makes sense, I agree, but not in the indicator.

      Also, your example implies that for a triple smoothed calculation, the minimum bars required for stability is the largest average. . . I don't follow.
      For a simple example, if I take a 50 MA of a 200 MA, I need more than 200 bars for the final output, because the 50 MA is still not valid -- it did not even start to receive valid data until the 200th bar.

      Maybe that answers part of my question: if I determine the minimum bars for validity of each portion and SUM, then I have defined the unstable period for the overall indicator? A + B + C? Is this logical, or am I missing something?

      Thank you!

      Comment


        #4
        The code I posted stops everything following it in OnBarUpdate(). The return; specifies to "break out" of the current method call (OnBarUpdate()), so once the indicator sees return; it will stop running calculations until another OnBarUpdate() gets called. That is why the code needs to be placed at the very beginning of OnBarUpdate().

        It appears my original code isn't quite correct for your application. It would work for three seperate indicators, not SMA(SMA(200), 50) or something like that.

        I think this could vary for each specific application, but your sum idea seems logical. If we follow your example of 50 MA of a 200 MA. The 200MA won't have correct values until the 200th bar is present. Thus, there would only be one value for the 200MA. So to get a 50MA of a 200MA, it would need 50 data points from the 200MA, which means you'd need a total of 250 bars.
        AustinNinjaTrader Customer Service

        Comment


          #5
          OK, great, Austin.

          So given that I can somehow estimate a "validity" period -- how do I tell NT charting what that period is when plotting this indicator so that it does NOT plot the unstable values?

          Thanks! I really appreciate the help.

          Comment


            #6
            Lost Trade, you can use the if (CurrentBar < yourCalculatedValidityPeriod) {return;} command so it doesn't plot the unstable values. More specifically, if you wanted to run other calculation logic all the time and only not plot when there aren't enough bars, you could do this:
            Code:
            // assume the plot names are ABC and DEF
            if (CurrentBar < yourCalculatedValidityPeriod)
                return;
            else
            {
            ABC.Set(plotValueHere);
            DEF.Set(plotValueHere);
            }
            AustinNinjaTrader Customer Service

            Comment


              #7
              With respect, Austin, I think the else brackets are redundant.

              I get the impression that there is no simple or logical way for my code to contribute to (or set or lengthen) NT's definition of unstable period. . . as referenced in the chart properties.

              I'll sleep on it a while. Thank you for your help.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Waxavi, Today, 02:10 AM
              0 responses
              2 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              2 views
              0 likes
              Last Post TradeForge  
              Started by Waxavi, Today, 02:00 AM
              0 responses
              2 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by elirion, Today, 01:36 AM
              0 responses
              4 views
              0 likes
              Last Post elirion
              by elirion
               
              Started by gentlebenthebear, Today, 01:30 AM
              0 responses
              4 views
              0 likes
              Last Post gentlebenthebear  
              Working...
              X