Code for the multiple time ranges for allowing to trade

 

I just know to allow time to trade with the single time range example from 3:58 to 04:04, but now i want to multiple time ranges for allowing to trade, example i want the time to trade from 3:58 to 04:04 , from 14:58 to  15:02, from 16:58 to 17:02. Pls help me. Thank all so much

 Below is the code for single time range example from 3:58  to 04:04


 int     Start_Hour     = 3;

int     Start_Min      = 58;

 int     End_Hour       = 4;
 int     End_Min        = 4;

bool TimeAllowed(datetime time=-1) {

   int HOUR,MIN;

   if(time==-1) {

      HOUR=Hour();

      MIN=Minute();

      }else{

      HOUR=TimeHour(time);

      MIN=TimeMinute(time);

      }

bool TradeAllow=true;

   if (Start_Hour>End_Hour) { 

      if (HOUR<Start_Hour && HOUR>End_Hour) TradeAllow=false;

      }else{ 

      if (HOUR<Start_Hour || HOUR>End_Hour) TradeAllow=false;

      }

   if (HOUR==Start_Hour && MIN<Start_Min) TradeAllow=false;

   if (HOUR==End_Hour && MIN>=End_Min)  TradeAllow=false;

   if (TradeAllow) return(true); else return(false);

   }


 

Forum on trading, automated trading systems and testing trading strategies


When you post code please use the CODE button (Alt-S)!

Use the CODE button


Reason: