Need help with close all Method MT5 Code

 

Hi All,

I need help with This code, it compiles without Errors but when test it , it's not working .

I hope you guys help solve this problem 😊


//+------------------------------------------------------------------+
//| Close All Positions At Certain Time                              |
//+------------------------------------------------------------------+ 

 enum daysOfWeek 
   { 
     Monday = 1, 
     Tuesday = 2, 
     Wednesday = 3, 
     Thursday = 4, 
     Friday = 5
   };
   input  daysOfWeek closday    =    5;
   input int    Close_Hour      =   18;

bool TimeCheck()
{
      bool Result=true;
      bool closday = true;
      bool Close_Hour = true;
       MqlDateTime TimeNow;
       TimeToStruct(TimeCurrent(),TimeNow);
     // Closday
      if  ( TimeNow.day_of_week >= closday ) 
          closday = true;
     // Close_Hour
       if (  TimeNow.hour >= Close_Hour )  Close_Hour = true;
         
   {
               CloseAllPositions();
               
            };     
       
   return(Result);
 }

}
 
zreboo:

Hi All,

I need help with This code, it compiles without Errors but when test it , it's not working .

I hope you guys help solve this problem 😊


Your Booleans are doing nothing as they are always true and your if logic is wrong, try this instead

not tested


   void TimeCheck()
   {
      MqlDateTime TimeNow;
      TimeToStruct(TimeCurrent(),TimeNow);
      if  ( TimeNow.day_of_week >= closday && TimeNow.hour >= Close_Hour )  
      {
         CloseAllPositions();
      }     
   }
 
Paul Anscombe:

Your Booleans are doing nothing as they are always true and your if logic is wrong, try this instead

not tested


Hi   Paul,

Thanks for the help. I tried the code, but it is not compatible with the expert advisor because there are other Function that depend on the Time-Check method and it shows an error. TimeCheck '- expression of' void 'type is illegal

But I think I should simplify the code more and then test it.