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 Belfortbucks, Today, 09:29 PM
          0 responses
          6 views
          0 likes
          Last Post Belfortbucks  
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          151 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Working...
          X