Asking for help when placing trades while [Market closed]

 
Title says it all, I'm not sure what the most efficient way of doing this is so I am asking here. For EAs that trade on hourly or daily it may try to place trades at 00:00 during/on market close so what is the most efficient way of making wait like 5 minutes before trying to place the same trade again? I have a little code here just for reference. 
void executeBuy(){
   CopyBuffer(handleATR,0,1,1,bufferATR);
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double sl = ask - bufferATR[0] * ATR_SL_multiplier;
   double tp = ask + bufferATR[0] * ATR_TP_multiplier;
   double Lots = calcLots(ask-sl);
   trade.Buy(Lots, _Symbol, ask, sl, tp, "Regular Buy Signal"); 
   Print(__FUNCTION__, " > Buy Order Sent. Retcode: ", trade.ResultRetcode());
   if(trade.ResultRetcode() == TRADE_RETCODE_MARKET_CLOSED){
      // wait five min then try to place trade again
      // if trade is unable to place again because market is close wait another five min before trying again
   }
   
} 
void executeSell(){
   CopyBuffer(handleATR,0,1,1,bufferATR);
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double sl = bid + bufferATR[0] * ATR_SL_multiplier;
   double tp = bid - bufferATR[0] * ATR_TP_multiplier;
   double Lots = calcLots(sl-bid);  
   trade.Sell(Lots, _Symbol, bid, sl, tp, "Regular Sell Signal");
   Print(__FUNCTION__, " > Sell Order Sent. Retcode: ", trade.ResultRetcode());
   if(trade.ResultRetcode() == TRADE_RETCODE_MARKET_CLOSED){
      // wait five min then try to place trade again
      // if trade is unable to place again because market is close wait another five min before trying again
   }
}
 
Casey Courtney:
Title says it all, I'm not sure what the most efficient way of doing this is so I am asking here. For EAs that trade on hourly or daily it may try to place trades at 00:00 during/on market close so what is the most efficient way of making wait like 5 minutes before trying to place the same trade again? I have a little code here just for reference. 

search codebase for time filter or the forum.

 
Casey Courtney:
Title says it all, I'm not sure what the most efficient way of doing this is so I am asking here. For EAs that trade on hourly or daily it may try to place trades at 00:00 during/on market close so what is the most efficient way of making wait like 5 minutes before trying to place the same trade again? I have a little code here just for reference. 

I think I've figured out something that works nicely 

bool retryBuy = false;
bool retrySell = false;

void executeBuy(){
   CopyBuffer(handleATR,0,1,1,bufferATR);
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double sl = ask - bufferATR[0] * ATR_SL_multiplier;
   double tp = ask + bufferATR[0] * ATR_TP_multiplier;
   double Lots = calcLots(ask-sl);
   trade.Buy(Lots, _Symbol, ask, sl, tp, "Regular Buy Signal");
   Print(__FUNCTION__, " > Buy Order Sent. Retcode: ", trade.ResultRetcode());
   if(trade.ResultRetcode() == TRADE_RETCODE_MARKET_CLOSED){
      Print("Trade Failed Because market is closed... Retrying in 5 min");
      retryBuy = true;
   } else {
      retryBuy = false;
   }
   
} 
void executeSell(){
   CopyBuffer(handleATR,0,1,1,bufferATR);
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double sl = bid + bufferATR[0] * ATR_SL_multiplier;
   double tp = bid - bufferATR[0] * ATR_TP_multiplier;
   double Lots = calcLots(sl-bid);  
   trade.Sell(Lots, _Symbol, bid, sl, tp, "Regular Sell Signal");
   Print(__FUNCTION__, " > Sell Order Sent. Retcode: ", trade.ResultRetcode());
   if(trade.ResultRetcode() == TRADE_RETCODE_MARKET_CLOSED){
     Print("Trade Failed Because market is closed... Retrying in 5 min");
     retrySell = true;
   } else {
      retrySell = false;
   }
}

void OnTimer() {
   if (retryBuy == true) {
      executeBuy();
   }
   if(retrySell == true){
      executeSell();
   }
}

You need to add Ctrade and then Event set timer in Oninit of course...