TimeDaylightSavings Doesn't Work On Backtesting

 

As the title, TimeDaylightSavings() doesn't work when I run backtest for a year, it always Print out "true".

Expected: I want to detect the time while running the backtest is considered daylight saving time or not

int OnInit() {
//---
  trade.SetExpertMagicNumber(1);
//---
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//---
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
  if(HasNewCandle()) Print("is Day light saving: ", TimeDaylightSavings() == 0);
}

bool HasNewCandle() {
  //--- current time
  long lastBarTime = SeriesInfoInteger(Symbol(), Period(), SERIES_LASTBAR_DATE);
  //--- memorize the time of opening of the last bar in the static variable
  static long lastTime = lastBarTime;

  //--- still not have new candle
  if(lastTime == lastBarTime) return false;
  
  //--- if the time differs
  lastTime = lastBarTime;
  return true;
}
Documentation on MQL5: Date and Time / TimeDaylightSavings
Documentation on MQL5: Date and Time / TimeDaylightSavings
  • www.mql5.com
TimeDaylightSavings - Date and Time - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Le Minh Duc: TimeDaylightSavings

There are limitations when simulating time in the Strategy Tester. No historical records are kept for time-zone and daylight savings, so they cannot be simulated.