Announcement

Collapse
No announcement yet.

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]);

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    80 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X