Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator that calls itself

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

    Indicator that calls itself

    Good day to you all,
    Is there an instruction that invokes the indicator that is being built of the precedent bar?

    similar to the instruction "PREV" of MetaStock:

    "Self Referencing Formulas Using PREV
    The PREV constant allows you to create self-referencing formulas. A self referencing formula is one that is able to reference the "previous" period's value of itself.
    For example, the following is an example of a self referencing formula:
    ((H+L+C)/3) + PREV
    This simple formula divides the high, low, and closing prices by 3 and then adds this value to yesterday's value of the ((H+L+C)/3)."


    thank you very much

    #2
    Hi Picita, there is no PREV function, but you can certainly access the previous value of an indicator. The EMA indicator would be a good example of this, it uses Value[1] to get the last value of itself, which is then used in the new calculation.

    If you wanted to sum the close of a bar series, for example, you could do something like this:
    Code:
    dataSeries.Set(Close[0] + dataSeries[1]);
    AustinNinjaTrader Customer Service

    Comment


      #3
      I think the situation is more complicated
      because in this case there is a call to the function itself:

      in Metastock
      pr:= (H+L)/2;
      sp:= (pr+(2*Ref(pr,-1))+(2*Ref(pr,-2))+Ref(pr,-3))/6;
      cycle:= Mov(Power(1-(.5*a),2)*(sp-(2*Ref(sp,-1))+Ref(sp,-2))+(2*(1-a))*PREV-(Power(1-a,2)*Ref(PREV,-1)) , a*1000,S);


      in this case
      PREV = cycle[1]

      Comment


        #4
        Picita, we can't provide support for MetaStock features/methods. In this example, Ref() just pulls a previous value from some "data series" (not sure the metastock name for it).

        You could basically re-write the code you just posted with cycle[1] instead of PREV, as you've mentioned. If you need the sp value from two bars ago, you could do sp[2] instead of Ref(sp, -2).
        AustinNinjaTrader Customer Service

        Comment


          #5
          The syntax is certainly different: the functionality is the same. The previous value of any indicator to the CurrentBar is the reference PlotSeries[1], or, alternatively, Value[1] if there is only one plot.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          591 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          343 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          556 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          553 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X