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

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
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Ousher, Yesterday, 11:12 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by You4Life, Yesterday, 08:20 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by focus333, Yesterday, 05:56 PM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by itsthefriz, Yesterday, 04:19 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by johnMoss, Yesterday, 04:06 PM
        0 responses
        8 views
        0 likes
        Last Post johnMoss  
        Working...
        X