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

How to reset a dictionary when starting a strategy mid-day?

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

    How to reset a dictionary when starting a strategy mid-day?

    Hi there!

    I'm trying to reset a dictionary (called hypo_results) when I activate a strategy in the middle of the day. Currently, the strategy runs on previous data since I have the instrument set to 24 hours.

    I'm trying this with no luck:

    Code:
    // If this is the first tick of a new bar, start all this material
                if (IsFirstTickOfBar)                    
                {    
                    //  Set the proper time for the bar
                    if (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) < 93000)        { currentHour = 0; }                                    
                    else if (ToTime(Time[0]) >= 93000 && ToTime(Time[0]) < 103000)        { currentHour = 1; }    
                    else if (ToTime(Time[0]) >= 103000 && ToTime(Time[0]) < 113000)        { currentHour = 2; }
                    else if (ToTime(Time[0]) >= 113000 && ToTime(Time[0]) < 123000)        { currentHour = 3; }
                    else if (ToTime(Time[0]) >= 123000 && ToTime(Time[0]) < 133000)        { currentHour = 4; }
                    else if (ToTime(Time[0]) >= 133000 && ToTime(Time[0]) < 143000)        { currentHour = 5; }
                    else if (ToTime(Time[0]) >= 143000)                                    { currentHour = 6; }
    
                    tickCount = 1;    
    
                    // Use this to reset all related dictionaries
                    if (currentHour == 0 && !dayReset)    
                    {
                        hypo_results.Clear();                                                // Clear all results from the main dictionary
                        dayReset = true;                                                    // Close out the reset
                    }
                }​
    I'm usually stopping, changing code, compiling and clicking the checkbox for the strategy to run it to the Output window. But it generates a lot of older computation on the day that's transpired so far. I'm running the strategy in real-time.

    Any suggestions? Is my code incorrect?

    #2
    Hello, thanks for writing in. The dictionary can be reset in OnStateChange, during State.Transition, or you can exclusively run your code in real time only by adding if(State == State.RealTime) within OnBarUpdate so that code does not run in State.Historical.

    Please let me know if this does not resolve.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      State.Transition worked like a charm. Thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      7 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X