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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    89 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X