private Dictionary<double, NinjaTrader.NinjaScript.DrawingTools.Line> MyLines= new Dictionary<double, NinjaTrader.NinjaScript.DrawingTools.Line>();
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Class level variable Dictionary is getting cleared in various time inerval
Collapse
X
-
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:Tags: None
-
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
-
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
637 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
366 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
572 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment