trading time filter

 
My friends, what I want to do is to make a breakout system by restricting the trade hours and then to sell if it closes above this hour in the future. For example, the first transaction for GBPUSD will be opened at 11:30. If the next two or three candles are above the close, they will sell if they are below the buy. If the 13:15 candle is below the 11:15 candle, it will still sell. Is something like this possible?
 

1ol:
My friends, what I want to do is to make a breakout system by restricting the trade hours and then to sell if it closes above this hour in the future. For example, the first transaction for GBPUSD will be opened at 11:30. If the next two or three candles are above the close, they will sell if they are below the buy. If the 13:15 candle is below the 11:15 candle, it will still sell. Is something like this possible?

input string   group6 = "Time Filters";//------------------------------------------------
input bool timefilter   = false; //Time Filter Activation
input string TimeStart1 = "08:00";
input string TimeEnd1 = "12:00";
input string TimeStart2 = "16:00";
input string TimeEnd2 = "20:00";
input string TimeStart3 = "01:00";
input string TimeEnd3 = "04:00";
bool tradingallowed = false;
void OnTick()
{
   Sleep(2000);
   string CurrentTime = TimeToString(TimeCurrent(),TIME_MINUTES);
   
   if(timefilter)
   {
      if(StringSubstr(CurrentTime,0,5)==TimeStart1 ||
         StringSubstr(CurrentTime,0,5)==TimeStart2 ||
         StringSubstr(CurrentTime,0,5)==TimeStart3)
         tradingallowed = true;
         
      if(StringSubstr(CurrentTime,0,5)==TimeEnd1 ||
         StringSubstr(CurrentTime,0,5)==TimeEnd2 ||
         StringSubstr(CurrentTime,0,5)==TimeEnd3)
         tradingallowed = false;
   }else
      tradingallowed = true;
}
 

Mehmet Ozen


great

 
  1.       if(StringSubstr(CurrentTime,0,5)==TimeStart1 ||
             StringSubstr(CurrentTime,0,5)==TimeStart2 ||
             StringSubstr(CurrentTime,0,5)==TimeStart3)

    What if there are no ticks that specific minute. There can be minutes between ticks during the Asian session.

  2. When people say between 8 and 12. That doesn't mean 12:00:59.

  3. EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global variables will have been lost. Your global tradingAllowed

  4. When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.

    See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
    Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
    MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)

  5. input double TimeStart1 =  8, TimeEnd1 = 12;
    input double TimeStart2 = 16, TimeEnd2 = 20;
    input double TimeStart3 =  1, TimeEnd3 =  4;
    
       double hod = time() / 3600.0; // Hour of the day.
       if(TimeStart1 <= hod && hod < TimeEnd1
       || TimeStart2 <= hod && hod < TimeEnd2
       || TimeStart3 <= hod && hod < TimeEnd3){ // Trading ok.
              Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)