//+------------------------------------------------------------------+ //| NewBar.mqh | //| AnimateDread | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "AnimateDread" #property link "https://www.mql5.com" bool NewBar() { datetime cTime[]; ArraySetAsSeries(cTime, true); static datetime LastTime = 0; // CopyTime can return 0/fail (history not yet synced right after attach, or a data gap on an // illiquid symbol) leaving cTime empty - indexing cTime[0] unguarded would raise an "array out // of range" runtime error and abort this tick's processing (skipping bar-close-triggered logic // like autosave/era boundaries) with no diagnostic. if(CopyTime(Symbol(), Period(), 0, 1, cTime) <= 0 || ArraySize(cTime) == 0) { Print(__FUNCTION__ + ": CopyTime failed or returned no data (error " + IntegerToString(GetLastError()) + ") - treating this tick as not-a-new-bar."); return false; } bool ret = cTime[0] > LastTime && LastTime > 0; LastTime = cTime[0]; return ret; }