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

Retrieve values in the past of the graph

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

    Retrieve values in the past of the graph

    Hello,

    I need to retrieve values in the past.
    In OnBarUpdate() I get an index error. I can only recover at index 0. How can I work around this problem please? I specify that I really need to do this with a strategy because I have to check certain prices in the past to trigger a trade.

    Thanks for your help

    #2
    Hello jodu49,

    A simple way to figure out the problem is to use the error information to see when this happened. Was the error on bar -1 or 0 or later in processing on a much higher number?

    Generally you need a condition placed before the code where you check past data, that condition is to stop at that point if there is not that many bars processed yet. If you are on bar 0 you can only check 0 BarsAgo because you are at the very first datapoint being processed.

    Once the script has processed X bars you could look back X bars ago as shown below using 5. You could change that 5 to reflect whatever value you had used.

    Code:
    if(CurrentBar < 5) return; 
    Print(Close[5]);

    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Austiner87, Today, 11:24 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by ETFVoyageur, 04-30-2024, 02:04 PM
    10 responses
    75 views
    0 likes
    Last Post ETFVoyageur  
    Started by Drone360x, Today, 10:27 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by Salahinho99, Yesterday, 04:13 AM
    2 responses
    26 views
    0 likes
    Last Post Salahinho99  
    Started by truepenny, Today, 03:45 AM
    4 responses
    21 views
    0 likes
    Last Post truepenny  
    Working...
    X