Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATR average of the last 21 bars vs ATR of last bar

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

    ATR average of the last 21 bars vs ATR of last bar

    Hi,
    I'm trying to create a formula that would enable me to compare an average of the last Bar ATR vs last 21 Bars average ATR.
    Here is what I've got:
    Code:
    double atrbar1 = ATR(1)[1];
    double atrbars21 = ATR(21)[1];
    or should I just use it like this?:
    Code:
    double atrbar1 = ATR(1)[1];
    double atrbars21 = ATR(21);
    Or maybe something else?
    Thank you



    #2
    Hello Ludwik,

    The barsAgo [1] index means 1 bar ago, or the previous bar and not the current bars value. Do you want the current bars value?

    private ATR atr1, atr21;

    In OnStateChange() when State is State.DataLoaded:
    atr1 = ATR(1);
    atr21 = ATR(21);

    In OnBarUpdate():
    Print(string.Format("{0} | atr1[0]: {1}, atr21[0]: {2}", Time[0], atr1[0], atr21[0]));
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Ludwik,

      The barsAgo [1] index means 1 bar ago, or the previous bar and not the current bars value. Do you want the current bars value?

      private ATR atr1, atr21;

      In OnStateChange() when State is State.DataLoaded:
      atr1 = ATR(1);
      atr21 = ATR(21);

      In OnBarUpdate():
      Print(string.Format("{0} | atr1[0]: {1}, atr21[0]: {2}", Time[0], atr1[0], atr21[0]));
      Thank you for your reply Chelsea,

      I would actually haven't made myself clear enough. I would like to get an ATR value of the last closed bar ATR[1] (not the current bar) vs an average ATR 'series' value of the previous bars starting at ATR[2] up to ATR[21]. Is the code, which you wrote suitable for it?

      I've read an ATR documentation but I'm still struggling to figure out the difference between
      ATR(1)[1] and ATR (1)
      I think that's where my confusion is coming from. The only thing I understand is that ATR[1] is getting the value of the last closed bar. But I'm still struggling to understand how to get an average of the series of bars from Bar 2 to Bar 21

      Comment


        #4
        Hello Ludwik,

        The [1] bracket is a bars ago index of 1 bar ago. An indicator returns a plot series. A Series<T> has a slot for each bar on the chart.

        The (1) is the method call with a parameter supplied. For the ATR this parameter is the 'Period', which is the number of bars used for the calculation.

        Below is a link to the help guide on the ATR indicator and Series.



        If Calculate is OnBarClose, the CurrentBar, or most recently updated bar [0], is the most recently fully closed bar and not the building bar. If Calculate is OnPriceChange or OnEachTick the CurrentBar is the bar that is building and not fully closed.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you Chelsea

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          46 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          66 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X