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

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 AaronKoRn, Today, 09:49 PM
          0 responses
          6 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Today, 08:42 PM
          0 responses
          9 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Today, 07:51 PM
          0 responses
          10 views
          0 likes
          Last Post strategist007  
          Started by StockTrader88, 03-06-2021, 08:58 AM
          44 responses
          3,976 views
          3 likes
          Last Post jhudas88  
          Started by rbeckmann05, Today, 06:48 PM
          0 responses
          9 views
          0 likes
          Last Post rbeckmann05  
          Working...
          X