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 NullPointStrategies, Today, 05:17 AM
    0 responses
    46 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    66 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X