Hello everyone,
I wrote this small function to print yes when it is 5 minutes before midnight in my broker time but it currently prints yes 5 mins after the next candle open.
I have tried different variations of the code and the closest I have ever gotten was to print yes 5 mins before 20:00, once I go beyond 20:00 it starts returning "wrong datetime"
I even tried writing the function such that when TimeHour() == 23 and TimeMinutes() >= 55 Print ("Yes"); but in ST where I have tried to test it, nothing is printed.
Please kindly assist.
Thank you.
You want to print "yes" on broker time but have you checked if TimeCurrent() is really your broker time or TimeTradeServer() is your broker time?
Try to print everything and you can solve it.
bool PrintYesFiveMinutesBeforeEndOfDay() { bool resu = false; datetime currentTime = TimeCurrent(); Print("currenttime : ",currentTime); int tradingDayEndHour = 0; int tradingDayEndMinute = 0; datetime endOfDay = StrToTime(StringFormat("%04d.%02d.%02d %02d:%02d:00", Year(), Month(), Day(), tradingDayEndHour, tradingDayEndMinute)); Print("endofDay ",endOfDay); long timeRemaining = endOfDay - currentTime; Print("timeremaining ",(datetime)timeRemaining); // Check if it's 5 minutes before midnight if(timeRemaining > 0 && timeRemaining <= 300)// && TimeHour(currentTime) < tradingDayEndHour) { Print("yes"); resu = true; } else Print("no "); return resu; }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
I wrote this small function to print yes when it is 5 minutes before midnight in my broker time but it currently prints yes 5 mins after the next candle open.
I have tried different variations of the code and the closest I have ever gotten was to print yes 5 mins before 20:00, once I go beyond 20:00 it starts returning "wrong datetime"
I even tried writing the function such that when TimeHour() == 23 and TimeMinutes() >= 55 Print ("Yes"); but in ST where I have tried to test it, nothing is printed.
Please kindly assist.
Thank you.