Time check in onTick only runs on one chart (global variables shared between charts?)

 

Hi! I'm trying to figure out why this code only fires on one chart at 1AM, even though the EA is actually attached to multiple charts at the same time.

Is my assumption wrong that globally scoped variables only apply to the chart that was attached? or are they in fact shared across charts?


int lastCheckedDayOfYear;
string checkTime = "01:00";

void OnTick()
  {
   if(lastCheckedDayOfYear!=getDay(TimeCurrent()))
     {
      // Is it time to perform a license check?
      if(TimeToString(TimeCurrent(),TIME_MINUTES)==checkTime)
        {
         if(check_license(Serial_key, "TIME_CHECK")==false)
           {
            ExpertRemove();
           }
         lastCheckedDayOfYear=getDay(TimeCurrent());
        }
     }
  }


I'm having trouble figuring this out from the docs (https://www.mql5.com/en/docs/basis/variables/global), and can't really see if there's another way around this.

Any ideas?


Documentation on MQL5: Language Basics / Variables / Global Variables
Documentation on MQL5: Language Basics / Variables / Global Variables
  • www.mql5.com
Global Variables - Variables - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1. void OnTick()
      {
       if(lastCheckedDayOfYear!=getDay(TimeCurrent()))
         {
          // Is it time to perform a license check?
          if(TimeToString(TimeCurrent(),TIME_MINUTES)==checkTime)

    I assume getDay does what it implies (same as my date function below). You want a new day at 1:00. But the date changes at 00:00. You will never get both at the same time and the rest never runs.

  2. There can be minutes between ticks during the Asian session, think M1 chart. What happens if there is no tick during the checkTime minute?

  3. datetime nextCheck=0;
    int checkTime = 3600; // 01:00
    void OnTick()
      {
       if(TimeCurrent() >= nextCheck)
         {
          nextCheck=Tomorrow()+checkTime;
              Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)