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

"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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Jltarrau, Today, 05:57 AM
    3 responses
    6 views
    0 likes
    Last Post Jltarrau  
    Started by f.saeidi, Today, 05:56 AM
    2 responses
    8 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by Pattontje, Yesterday, 02:10 PM
    2 responses
    36 views
    0 likes
    Last Post Pattontje  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    7 responses
    27 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by Skifree, Today, 03:41 AM
    2 responses
    8 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X