Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set / Reset a Plot Series - Error: Index was out of range

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

    Set / Reset a Plot Series - Error: Index was out of range

    Hello,
    can you please help me with Reset() an set the value into Plot series from mouse click handler? My indicator adds a button to the toolbar and when button is turn ON, mouse left click handler waiting for left click into the chart area and finds out bar index for clicked bar. So far, everything works great. Now I need to reset all values in my Plot series named DS and then set value = 1 into Plot series DS only for bars right from clicked bar. I have two for cycles in OnMouseLeftDown(), one for reset DS a one for set value = 1 into DS.

    DS.GetValueAt(i) worked fine for all i, but DS[i] worked only for i = 0 and for i >= 1 will cause error "Unhandled exception: Index was out of range". DS.reset(i) or setting DS[i] = 1 also will cause same error - see line 202, 216, 217 in attached indicator (now commented). I tried to debug it, I searched the help guide and forums but nothing helped. Can you please advise me?

    Thank you.
    asfax
    Attached Files

    #2
    Hello asfax,

    Thank you for the post.

    This is because you are currently outside of the NinjaScript event context. When one of the overrides in your script is called the variables for the script are also present. When you click a button that is not a NinjaScript event so it is now out of sync, you can put it in sync by using a trigger custom event to surround your code.

    https://ninjatrader.com/support/help...ghtsub=trigger

    Code:
    TriggerCustomEvent(o =>
        {
            //your code here
            SomeVolumeData[20] = 5; // set to our new custom value
    
        }, null);
    This would go inside your button event, surrounding the code inside of the event.


    I look forward to being of further assistance.

    Comment


      #3
      Thank you Jesse for explaining and for the quick response.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      67 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      95 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      53 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      108 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      63 views
      0 likes
      Last Post PaulMohn  
      Working...
      X