Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Class level variable Dictionary is getting cleared in various time inerval

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

    Class level variable Dictionary is getting cleared in various time inerval

    Hi, I am using below Dictionary code at class level in my script to capture all the line I draw on OnBarUpdate method. What I observed is the Dictionary instance is getting cleared on its own on various time interval. Will NT do reset class level variables ?

    Code:
    private Dictionary<double, NinjaTrader.NinjaScript.DrawingTools.Line> MyLines= new Dictionary<double, NinjaTrader.NinjaScript.DrawingTools.Line>();

    #2
    Hello nandhumca,

    Thank you for your post.

    NinjaTrader wouldn't reset the dictionary at a specific time interval, however, if the code was reloaded the dictionary would be cleared and recomputed from historical data.

    I'm attaching an example script that draws lines at the highs and lows of each 30 minute period that may be tested on a 1 minute chart (I used ES 12-21 for testing). I'm not seeing it clear itself, the dictionary simply gets added to every 30 minutes. Do you see the same testing this example?

    I'd also like to mention it would be best practice to declare the dictionary at class level but to actually create it in State.DataLoaded as per the attached example.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Thanks Kate. Will the reload happen automatically by any chance ? how to track in my code that there is a reload happened ? if the reload happens, class level variable will get reset right even if I initialize the Dictionary in State.DataLoaded ?

      Comment


        #4
        Hello nandhumca,

        Thank you for your note.

        Ninjascript would be reloaded any time historical data reloads, such as when reconnecting occurs, or you've right clicked on a chart and selected "Reload Historical Data". It would also occur with all indicators on a chart if a change is made to one indicator. There is not a way to avoid this. There would also not be a way to track that a reload has occurred, short of using a StreamWriter to create your own log file that tracks when the indicator reaches State.DataLoaded and checking that file to see if it's been restarted. Reloading will reset all variables instantiated within the indicator class.

        Please let us know if we may be of further assistance to you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        650 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        577 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X