select trading time and avoid swap time to trade

 

Good morning, 

I use a simple code to trade before 8 AM or after 18:00 PM. What I would like to do is to avoid trading during the swap time. I mean not to trade after 23:30 PM and not before 1:30 AM. 

I guess for you it is a simple code but I really need to be sure of it. Could you please help?

thanks


bool sleep = false;

  if

   (

Hour() <= 7 || 

  Hour() >= 18 

   )

      sleep = true;


 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Forum rules and recommendations - General - MQL5 programming forum (2023)
              Messages Editor

  3. Your code
    bool sleep = false;
      if( Hour() <= 7 ||  Hour() >= 18 ) sleep = true;
    Simplified.
    bool sleep =  Hour() <= 7 ||  Hour() >= 18;

  4. Romain Genillon: I mean not to trade after 23:30 PM and not before 1:30 AM.

    You have to stop using hours
              Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)

    #define HR2330 84600 // 23*3600+30*60
    #define HR0130  5400 //  1*3600+30*60
       int now = time();
    bool sleep =  now < HR0130 || now >= HR2330;
    Note: "not before" means less than.
 
many thanks helps a lot!