Couple of points.
Best to run off serverTime where possible, TimeCurrent(); - Daylight savings happens at different times accross the world.
Having time comparitors in OnTick() doesn't work as Ticks are movements in price and can jump specific seconds as your checking against 17:00:00 == 17:00:00
Use OnTimer set to seconds or just compare Hours Minutes with toggler maybe.
I always add a couple of seconds when dealing with iClose() - even the bar at index 0 has a close value and occationally iClose() will screw up the index when referencing at 01 milliseconds.
I punched out this if it helps.
int OnInit() { //--- //--- create a timer with a 1 second period EventSetTimer(1); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- //--- destroy the timer after completing the work EventKillTimer(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTimer() { //--- double NYClose; MqlDateTime Local, NYTime; NYTime.hour = 17; NYTime.min = 00; NYTime.sec = 02; if(TimeToStruct(TimeLocal(), Local)) { if((Local.hour == NYTime.hour && Local.min == NYTime.min && Local.sec == NYTime.sec)) { NYClose = iClose(Symbol(), Period(), 1); Print("New York Close", NYClose); } } }

- www.mql5.com
Couple of points.
Best to run off serverTime where possible, TimeCurrent(); - Daylight savings happens at different times accross the world.
Having time comparitors in OnTick() doesn't work as Ticks are movements in price and can jump specific seconds as your checking against 17:00:00 == 17:00:00
Use OnTimer set to seconds or just compare Hours Minutes with toggler maybe.
I always add a couple of seconds when dealing with iClose() - even the bar at index 0 has a close value and occationally iClose() will screw up the index when referencing at 01 milliseconds.
I punched out this if it helps.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Trying to get the EA to return the closing price at 5pm and store the value in a variable.
This should be done every tick so at 5pm the next day it stores the new close price. Can anyone help?
string five = "17:00";
double NYClose;
void OnTick()
{
NY = StrToTime(five);
if(TimeLocal() == NY)
{
NYClose = iClose(NULL,PERIOD_CURRENT,1);
}
}