How to fix the EA sleep during time filter ?

Vondereich

Trader
Aug 25, 2024
19
0
7
37
Hi want to ask, i'm using time filter to trade on mt4.. Here is the code related to it

MQL4:
extern string  TradingTime       = "------------ Trading Time Settings ------------";
extern bool    Trading_On_Monday = true;
extern string  Monday_StartTime  = "00:01"; // Start Trade Time
extern string  Monday_StopTime   = "23:59"; // End Trade Time
 
extern bool    Trading_On_Tuesday = true;
extern string  Tuesday_StartTime  = "00:01"; // Start Trade Time
extern string  Tuesday_StopTime   = "23:59"; // End Trade Time
 
extern bool    Trading_On_Wednesday = true;
extern string  Wednesday_StartTime  = "00:01"; // Start Trade Time
extern string  Wednesday_StopTime   = "23:59"; // End Trade Time
 
extern bool    Trading_On_Thursday = true;
extern string  Thursday_StartTime  = "00:01"; // Start Trade Time
extern string  Thursday_StopTime   = "23:59"; // End Trade Time
 
extern bool    Trading_On_Friday = true;
extern string  Friday_StartTime  = "00:01"; // Start Trade Time
extern string  Friday_StopTime   = "23:59"; // End Trade Time
   datetime candleTime   = iTime(Symbol(), Period(), 0);
   static datetime timeTrade;
   bool     isTradeAllowed       = true;
 
   if(TradingHours() && isTradeAllowed && candleTime && (Continue_Trade))
     {
      if(((Signal_Type==0)&&((TotalOrder(OP_BUY)==0)&& (TotalOrder(OP_SELL)==0))) ||
         ((!Hedge_Mode)&&(Signal_Type==1)&&((TotalOrder(OP_BUY)==0)|| (TotalOrder(OP_SELL)==0))) ||
         ((Hedge_Mode)&&((TotalOrder(OP_BUY)==0)&& (TotalOrder(OP_SELL)==0))))
        {
         if(buyCondition && TradeBuy && TotalOrder(OP_BUY)==0)
           {
            Order(OP_BUY, NamaEA + " [1st]");
            trail_mode = 0;
            timeTrade = candleTime;
            Trend_Buy = true;
            Trend_Sell = false;
           }
         else if(sellCondition && TradeSell && TotalOrder(OP_SELL)==0)
           {
            Order(OP_SELL, NamaEA + " [1st]");
            trail_mode = 0;
            timeTrade = candleTime;
            Trend_Sell = true;
            Trend_Buy = false;
           }
        }
     }
  }
 
bool TradingHours()
{
    if ((DayOfWeek() == 1) && TimeCurrent() > StrToTime(Monday_StartTime) && TimeCurrent() < StrToTime(Monday_StopTime))
        return true;
    else if ((DayOfWeek() == 2) && TimeCurrent() > StrToTime(Tuesday_StartTime) && TimeCurrent() < StrToTime(Tuesday_StopTime))
        return true;
    else if ((DayOfWeek() == 3) && TimeCurrent() > StrToTime(Wednesday_StartTime) && TimeCurrent() < StrToTime(Wednesday_StopTime))
        return true;
    else if ((DayOfWeek() == 4) && TimeCurrent() > StrToTime(Thursday_StartTime) && TimeCurrent() < StrToTime(Thursday_StopTime))
        return true;
    else if ((DayOfWeek() == 5) && TimeCurrent() > StrToTime(Friday_StartTime) && TimeCurrent() < StrToTime(Friday_StopTime))
        return true;
    else
        return false;
}

So the problem is, when the market close during early morning on my timezone, which is around 5 a.m, the ea keep sleep during that time until it open back using the setting above.. which is 00:01

But my setting is almost 24 hours run right.. so what is the issue here ??
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,473
1,586
144
Odesa
www.earnforex.com
So, you mean that the problem is that your EA is "sleeping" even outside of the 23:59-00:01 period? You need to check other conditions that may prevent it from trading. TradingHours() is just one of them.
 

Vondereich

Trader
Aug 25, 2024
19
0
7
37
So, you mean that the problem is that your EA is "sleeping" even outside of the 23:59-00:01 period? You need to check other conditions that may prevent it from trading. TradingHours() is just one of them.
not sure.. after market closed around 5 am gmt +8, the ea starts sleep.. after 00:01 (4pm) or gmt 8 , the ea starts working normally
 

Vondereich

Trader
Aug 25, 2024
19
0
7
37
Why do you keep bringing up local time? Your code is working with server time only.
an example. the ea sleep after market close and reopen during the morning..

i asked on the mql5 forum they said related to

If you want your EA to run continuously for 24 hours, place the code inside the OnTimer function and remove any checks related to TimeCurrent.