avatar
CheckTime

hellboys06 12 24th Jun, 2020

CPP 2.48 KB
                                           
                         //+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
bool checKtime(string starttime,string endtime) {
   string dt    = TimeToString(TimeCurrent()); 
   string DTstr = TimeToString(TimeCurrent(),TIME_DATE);
   string start = DTstr + " " + starttime;   
   string end   = DTstr + " " + endtime;
   StringToTime(start);
   StringToTime(end);
   StringToTime(dt); 
                                            
   if( start<end  ) if( dt>=start && dt<end ) return(true);
   if( start>=end ) if( dt>=start || dt<end ) return(true);
   return(false);
 }
/*you should add above code in global scope and use it in OnTick in this way:

if( checKtime("02:00:00","22:00:00") )
  {
     //Do Something ...
  }*/

//This can be optimized:


bool checktime(string starttime, string endtime) 
{ 
   return checktime(TimeToString(starttime), TimeToString(endtime));
   }
   
bool checktime(datetime start, datetime end)
   {
   datetime dt    = TimeCurrent();
   return start<end ? (dt>=start && dt<end) : (dt>=start || dt<end);
}

//--------------------------------------------------------------------------------------------------------------------------------//
/*you can see here that I am allowing trades between the hours of 7am and 9am then 1pm and 3 pm. */

bool enableTrade()
{
   if((Hour() >= 7 && Hour() <= 9) || (Hour() >= 13 && Hour() <= 15))
   {
   return true;
   }
   return false;
}
//Optimizing:
bool enableTrade()
{
   return (Hour() >= 7 && Hour() <= 9) || (Hour() >= 13 && Hour() <= 15);
}

/*Then need to call the function just before entering the trade and declare it to be true for the trade to work.

 if(enableTrade() == true)
 ....
 */
//-----------------------------------------------------------------------
bool enableTrade()
{

  double choThanh[2] = {9,12};
   return  ArrayBsearch(choThanh, Hour());
 }
//-------------------------------------------------------Option 3
bool checkTime3(int _start, int _end, int i) 
{
   int currT = TimeHour(Time[i]) < 10 ? (TimeHour(Time[i]) * 1000 + TimeMinute(Time[i])) : (TimeHour(Time[i]) * 100 + TimeMinute(Time[i]));
   return (currT >= _start && currT < _end) ? true : false;
}
/*   int startTime = 1530;
      int endTime = 2200;
    if(checkTime3(startTime, endTime, 1)); // returns check for last candle's starting time*/
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data

Comments

Authentication required

You must log in to post a comment.

Log in
    There are no comments yet.