Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"Error on calling 'OnStateChange' method: Out-of-range" Why??

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

    "Error on calling 'OnStateChange' method: Out-of-range" Why??

    I am trying to code a strategy for my trading system, I have everything down but I keep on getting the same error when I try to use it.


    [/CODE]I keep on getting this error
    Strategy 'DivergenceIndicator': Error on calling 'OnStateChange' method: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    Any help is appreciated.
    Attached Files

    #2
    Hello,

    Thank you for the post.

    I see that you are accessing series from the OnStateChange override such as High[0] in State.Configure.

    You would need to wait till later states such as DataLoaded or historical to access Series data.

    I would suggest using Comments to find all of the occurrences where there are errors, meaning to comment out your existing logic until you reach a point where you no longer get the error. You could slowly uncomment code and find items that cause errors in OnStateChange and then move them to OnBarUpdate or a correct state such as State.Historical.

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    84 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    150 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    79 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    52 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    59 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X