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

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

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by adeelshahzad, Today, 03:54 AM
      4 responses
      25 views
      0 likes
      Last Post adeelshahzad  
      Started by merzo, 06-25-2023, 02:19 AM
      10 responses
      823 views
      1 like
      Last Post NinjaTrader_ChristopherJ  
      Started by frankthearm, Today, 09:08 AM
      5 responses
      17 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      43 views
      0 likes
      Last Post jeronymite  
      Started by yertle, Today, 08:38 AM
      5 responses
      16 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X