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

Stopping indicator calculating before latest bar

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

    Stopping indicator calculating before latest bar

    Hi guys

    When you insert this code:

    Code:
    if(CurrentBar < 10)
                {return;}
    the indicator isn't calculated for the first 10 bars of the chart.

    However, I'm working on something which is not a conventional indicator but I need the calculations to stop 10 bars from now, i.e. from the right of the chart.

    I'd be very grateful for any advice about what the equivalent of the above code is in order to achieve this.

    Thanks in advance.

    #2
    something like this for a single session ?

    Code:
     
    if(CurrentBar > Bars.BarsSinceSession - 10 )
    return;

    Comment


      #3
      Hello arbuthnot,

      It may be easier to just reference the bar values of 10 bars ago instead of trying to Stop OnBarUpdate from being calculated. For example:

      Code:
      Print("The value of the Close 10 bars ago is "+Close[10]);
      That way all of your calculations will be based on the values 10 bars back. You may see the following thread for more references.
      JCNinjaTrader Customer Service

      Comment


        #4
        Much obliged, JC, for your idea. I followed your methodology and I certainly got some results! But, of necessity, the results are each delayed by 10 bars. So how to get round this?

        What I did was create another indicator whose purpose is to shift the results back, as it were, by roughly doing as follows:
        Code:
        result = IndicatorName(10).Plot0[-10];
        The negative in the [...] does the trick.

        And thanks, Marco, for your suggestion. I'd actually tried using Bars.BarsSinceSession but it just doesn't seem to work - although it should! I must have left out something essential...

        Comment


          #5
          Originally posted by arbuthnot View Post
          Much obliged, JC, for your idea. I followed your methodology and I certainly got some results! But, of necessity, the results are each delayed by 10 bars. So how to get round this?

          What I did was create another indicator whose purpose is to shift the results back, as it were, by roughly doing as follows:
          Code:
          result = IndicatorName(10).Plot0[-10];
          The negative in the [...] does the trick.

          And thanks, Marco, for your suggestion. I'd actually tried using Bars.BarsSinceSession but it just doesn't seem to work - although it should! I must have left out something essential...
          Not quite. A negative index on a Plot is appropos of nothing. It is pegged to 0. What you are plotting is the same as plotting the current value. If you want to Plot a past value, you need to use a positive index.

          How do you mean you want to get around the delay? If you ask to Plot the value 10 bars ago, then it IS the same as asking for a 10-bar delay. Did I misunderstand the question?

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Haiasi, 04-25-2024, 06:53 PM
          5 responses
          75 views
          0 likes
          Last Post alancurry  
          Started by ZeroKuhl, Today, 04:31 PM
          0 responses
          15 views
          0 likes
          Last Post ZeroKuhl  
          Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
          54 responses
          5,337 views
          0 likes
          Last Post Gaterz
          by Gaterz
           
          Started by ETFVoyageur, 05-07-2024, 07:05 PM
          11 responses
          76 views
          0 likes
          Last Post -=Edge=-  
          Started by _Zero_, 04-10-2020, 03:21 PM
          145 responses
          7,902 views
          6 likes
          Last Post johng2
          by johng2
           
          Working...
          X