Announcement

Collapse
No announcement yet.

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.

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      566 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X