enum every 15 minutes

To add comments, please log in or register
Joao Luiz Sa Marchioro
3956
Joao Luiz Sa Marchioro  

I would like to make a time enum every 15 minutes, I have seen some robots with well-made systems and others made in the wrong way, including using _ to enable enumeration. I would like to do it correctly, tried the form below but the MT5 will not accept. If anyone can help, I appreciate it.

enum time{"15:00","15:15","15:30"}
Marco vd Heijden
Moderator
8156
Marco vd Heijden  
Documentation on MQL5: Language Basics / Data Types / Integer Types / Enumerations
Documentation on MQL5: Language Basics / Data Types / Integer Types / Enumerations
  • www.mql5.com
After the enumeration is declared, a new integer-valued 4-byte data type appears. Declaration of the new data type allows the compiler to strictly control types of passed parameters, because enumeration introduces new named constants. In the above example, the January named constant has the value of 0, February - 1, December - 11. : If a...
whroeder1
17943
whroeder1  
Joao Luiz Sa Marchioro: I would like to make a time enum every 15 minutes,
  1. That makes no sense. Tell us what you are trying to do.
  2. Checking for the quarter hour is easy.
    void OnTick(){
       static bool isQuarter = 0;  bool wasQuarter = isQuarter;
       isQuarter = ( TimeCurrent() / 60 ) % 15 != 0;
       if(isQuarter && ! wasQuarter) // quarter of the hour
              Find bar of the same time one day ago - Simple Trading Strategies - MQL4 and MetaTrader 4 - MQL4 programming forum
Joao Luiz Sa Marchioro
3956
Joao Luiz Sa Marchioro  
whroeder1 :
  1. It makes no sense. Tell us what you are trying to do.
  2. Checking the room for an hour is easy. <br> <br> <br> MetaTrader 4 - MQL4 and MetaTrader 4 - MQL4 Trading Forum

The idea was to make it easier to use in the strategy tester. I've seen robots with time systems that work well, but I could not replicate. My knowledge is still small.

Joao Luiz Sa Marchioro
3956
Joao Luiz Sa Marchioro  
I finally got the code to optimize by time every 15 minutes.

I will post the code to help anyone who has the same problem.

Special thanks to Denis Macedo and Lucas M. Costa who gave me the tip to find the best solution.

enum horario
  {
   hr01,//09:05
   hr02,//09:15
   hr03,//09:30
   hr04,//09:45
   hr05,//10:00
   hr06,//10:15
   hr07,//10:30
   hr08,//10:45
   hr09,//11:00
   hr10,//11:15
   hr11,//11:30
   hr12,//11:45
   hr13,//12:00
   hr14,//12:15
   hr15,//12:30
   hr16,//12:45
   hr17,//13:00
   hr18,//13:15
   hr19,//13:30
   hr20,//13:45
   hr21,//14:00
   hr22,//14:15
   hr23,//14:30
   hr24,//14:45
   hr25,//15:00
   hr26,//15:15
   hr27,//15:30
   hr28,//15:45
   hr29,//16:00
   hr30,//16:15
   hr31,//16:30
   hr32,//16:45
   hr33,//17:00
   hr34,//17:15
   hr35,//17:28
   hr36,//17:45
   hr37,//17:53
  };

input horario Inicio=0;//Hora de Início das Operações [formato 00:00]
input horario Termino=36;//Hora de Paralisação das Operações [formato 00:00]
input horario DayTrade=34;//DayTrade fechamento de todas as Operações [formato 00:00]

MqlDateTime inicio,termino,daytrade;


int OnInit()
{
   TimeToStruct(StringToTime(TimeFunction(Inicio)),inicio);
   TimeToStruct(StringToTime(TimeFunction(Termino)),termino);
   TimeToStruct(StringToTime(TimeFunction(DayTrade)),daytrade);

// Verificação de inconsistências nos parâmetros de entrada
   if(inicio.hour>termino.hour || (inicio.hour==termino.hour && inicio.min>termino.min))
     {
      Alert(__FUNCTION__," Parâmetros de Horário inválidos!");
      printf("Parâmetros de Horário inválidos!");
      return INIT_FAILED;
     }

   Print("Abertura = ",inicio.hour,":",inicio.min,
         " / Fechamento = ",termino.hour,":",termino.min,
         " / Day Trade = ",daytrade.hour,":",daytrade.min
         );
}

void OnTick()
{

   if((stm.hour<=inicio.hour && stm.min<=inicio.min) || (stm.hour>=termino.hour && stm.min>termino.min)){tradeenabled=0;}

}

//--- Function
string TimeFunction(horario time)
  {
   switch(time)
     {
      case 0: return ("09:05");break;
      case 1: return ("09:15");break;
      case 2: return ("09:30");break;
      case 3: return ("09:45");break;
      case 4: return ("10:00");break;
      case 5: return ("10:15");break;
      case 6: return ("10:30");break;
      case 7: return ("10:45");break;
      case 8: return ("11:00");break;
      case 9: return ("11:15");break;
      case 10:return ("11:30");break;
      case 11:return ("11:45");break;
      case 12:return ("12:00");break;
      case 13:return ("12:15");break;
      case 14:return ("12:30");break;
      case 15:return ("12:45");break;
      case 16:return ("13:00");break;
      case 17:return ("13:15");break;
      case 18:return ("13:30");break;
      case 19:return ("13:45");break;
      case 20:return ("14:00");break;
      case 21:return ("14:15");break;
      case 22:return ("14:30");break;
      case 23:return ("14:45");break;
      case 24:return ("15:00");break;
      case 25:return ("15:15");break;
      case 26:return ("15:30");break;
      case 27:return ("15:45");break;
      case 28:return ("16:00");break;
      case 29:return ("16:15");break;
      case 30:return ("16:30");break;
      case 31:return ("16:45");break;
      case 32:return ("17:00");break;
      case 33:return ("17:15");break;
      case 34:return ("17:28");break;
      case 35:return ("17:45");break;
      case 36:return ("17:53");break;
     }
   return(IntegerToString(time));
  }



Mohammad Bazrkar
2584
Mohammad Bazrkar  
Joao Luiz Sa Marchioro:
I finally got the code to optimize by time every 15 minutes.

I will post the code to help anyone who has the same problem.

Special thanks to Denis Macedo and Lucas M. Costa who gave me the tip to find the best solution.


I am using similar include file with 5 minute interval :

enum ENUM_TIME{ //elapsed minutes
   TIME_00_00 = 0, // 00:00
   TIME_00_05, // 00:05
   TIME_00_10, // 00:10
   TIME_00_15, // 00:15
   TIME_00_20, // 00:20
   TIME_00_25, // 00:25
...
};

with this variable declaring

input ENUM_TIME startTime1 = TIME_08_00; // Server Start Time for EA (1)

and this codes for checking time

   MqlDateTime today; TimeToStruct(TimeCurrent(), today);
   int dayMinute = today.hour*60+today.min;
   bool isWH = (dayMinute>startTime1*5 && dayMinute<endTime1*5) ;

shown code is calculating elapsed minutes of current day; then it is comparing elapsed time with enum value * 5min ... no switch and extra function for time calculation.

nicholi shen
1870
nicholi shen  

These uses of enums for time intervals is a good example of over-engineering. An enum is essentially a named integer, and it doesn't help the code if all you need is an integer to iterate from the input variable using the optimizer. Why not just use a simple int?

input int inp_M15_bar = 0;

//start=0, step=1, stop=95
To add comments, please log in or register