Setting EA to Time Constraints

 

Hello all,


I have been working on programming my trading strategy and need a little help on the last part.

I want to constrain my EA to operate between Sunday and Thursday and only trade from 23:00CST to 12:00CST.


this is what I have tried thus far and cannot seem to get it to work on back testing... 


Please help! 


if(
      (StringSubstr(timeHoursMinutes,0,5)>"23:00")||
      (StringSubstr(timeHoursMinutes,0,5)<"12:00")
   )
      
   {
   if( signal1=="BUY" && BuyPlaced==false && signal2=="BUY")
      {        
         trade.PositionClose(sellTicket);
         sellTicket=0;
         trade.Buy(Lot,NULL,Ask,StopLoss,(Ask+TakeProfit*_Point),NULL);       
      } 

  
   if( signal1=="SELL" && SellPlaced==false && signal2=="SELL")
      {        
         trade.PositionClose(buyTicket);
         buyTicket=0;
         trade.Sell(Lot,NULL,Bid,StopLoss,(Bid-TakeProfit*_Point),NULL);       
      } 
   
     if(
         (StringSubstr(timeHoursMinutes,0,5)>"12:00")||
         (StringSubstr(timeHoursMinutes,0,5)<"23:00")
       )
      {
      trade.PositionClose(sellTicket);
      trade.PositionClose(buyTicket);
      }
 

You won't want to compare string versions of times.

Convert the times into components using StringToTime, then compare days to days, hours to hours, minutes to minutes, etc.

https://www.mql5.com/en/docs/convert/stringtotime

https://www.mql5.com/en/docs/constants/structures/mqldatetime

Reason: