Hi
I would like to make EA trade from 00:01 till 23:00. Also if there's any open position, to be closed on 23:15.
How can I write the code, so the hours and minutes (above specified) be written by the code?
TimeToString(TimeGMT(),TIME_MINUTES));replace TimeGMT() with any Time function you wish e.g. TimeTradeServer or TimeCurrent
This does not look right:
TimeCurrent() is of type datetime and you are comparing with a string.
Also TimeGMT() is based on terminal time with daylight saving - TimeCurrent() is server time - it is possible they will never match
static datetime a = TimeGMT()+PeriodSeconds(PERIOD_M1); if(TimeGMT()==a){ Print("Time matched"); a=0; // reset }today market is close so see this example with TimeGMT
static datetime a = TimeGMT()+PeriodSeconds(PERIOD_M1); if(TimeGMT()==a){ Print("Time matched"); a=0; // reset }
You are setting it to 60 secs in the future - will it ever match? You can test/debug it with a script even when the market is closed
How can I write the code, so the hours and minutes (above specified) be written by the code?
if ((TimeLocal() >= D'00:01') && ((TimeLocal() <= D'23:00'))) // Between 00:01 and 23:00.
- fxsaber #:
if ((TimeLocal() >= D'00:01') && ((TimeLocal() <= D'23:00'))) // Between 00:01 and 23:00.
Wrong. You are comparing to a fixed date, not today date.
-
TimeLocal and TimeGMT are probably wrong. All chart times are server times.
- István Reich #: if (time.hour == 23 && time. min == 15) {
This assumes every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart.
- Martin: I would like to make EA trade from 00:01 till 23:00. Also if there's any open position, to be closed on 23:15.
#define HR0001 60 #define HR2300 82800 // (23*3600) #define HR2315 83700 // (23*3600+15*60) int now = time(); if(now >= HR2315) close_all(); if(now >= HR0001 && now < HR2300) trade_now();
date/time (2017)
Find bar of the same time one day ago - MQL4 programming forum (2017)When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and minutes can be.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I would like to make EA trade from 00:01 till 23:00. Also if there's any open position, to be closed on 23:15.
How can I write the code, so the hours and minutes (above specified) be written by the code?