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 frankthearm, Yesterday, 09:08 AM
        14 responses
        47 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by gentlebenthebear, Today, 01:30 AM
        2 responses
        13 views
        0 likes
        Last Post gentlebenthebear  
        Started by Kaledus, Today, 01:29 PM
        2 responses
        8 views
        0 likes
        Last Post Kaledus
        by Kaledus
         
        Started by PaulMohn, Today, 12:36 PM
        2 responses
        16 views
        0 likes
        Last Post PaulMohn  
        Started by Conceptzx, 10-11-2022, 06:38 AM
        2 responses
        56 views
        0 likes
        Last Post PhillT
        by PhillT
         
        Working...
        X