Only Trade During Market Hours(Asia, UK, UK/US)

 

Hi guys, i'm trying to make my EA only work during open market hours: Asia, UK, UK/US.

My broker is IBFX: +0 GMT

// this should work??
if(tradingHours())
{
   //trade
}

bool tradingHours()
{
  // Asia GMT: 0:00 - 9:00
  // UK GMT: 8:00 - 16:00
  // US GMT: 13:00 - 22:00
  if(Hour()>=0 && Hour()<=22)
  {
   return(true);
  }
  else
  {
    return(false);
  }
}

I would like to have a generic algorithm, which will also consider the hour shifts, +1 hour, -1 hour

 
Is the US session 13:00 to 21:59 or 13:00 to 22:59 ? if it's the former your code is wrong.
 
c0d3:

Hi guys, i'm trying to make my EA only work during open market hours: Asia, UK, UK/US.

  1. There are no ticks when the market is closed. Start isn't called. No code needed
  2. Do you mean all sessions except first two of Sydney (except 5pm ET to 7 pm ET) Then you do NOT want hour=22.
     if(Hour()>=0 && Hour()<22)
    // if(Hour()>=0 && Hour()<=22)
      {
       return(true);
      }
      else
      {
        return(false);
      }
    //// or Simplify ///
    return( Hour()>=0 && Hour()<22 );

  3. If you mean code to allow a range, see my code
 

i made it grater than zero, and less than 21. I'm not in rush to trade the last hours of US, and the open of Asia

Hour()>0 && Hour()<21
Reason: