Hour condition to close open orders

 

Have this condition not working on my advisor:

   for(int i=0;i<OrdersTotal();i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
         if(CLOSE>STO_Overbought||Hour()==EndHour){
            if(!OrderClose(OrderTicket(),LotsOptimized(),Bid,3,clrGold)){
               Print("OrderClose error ",GetLastError());
               RefreshRates();
               return;
               }
            }
         }
      }

Anyone knows?

 
Incomplete code.
 

Ok I found that through Hour() you get the current candle opentime hour, so it wasn't working on H4.

My question now is how to set Hour limit regardless of the working timeframe.