Hi please see: https://www.mql5.com/en/docs/basis/types/integer/enumeration
- www.mql5.com
- That makes no sense. Tell us what you are trying to do.
- 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
- It makes no sense. Tell us what you are trying to do.
- 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.
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)); }
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.
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
Esses usos de enums para intervalos de tempo são um bom exemplo de engenharia excessiva. Um enum é essencialmente um inteiro nomeado, e não ajuda o código se tudo que você precisa é de um inteiro para iterar a partir da variável de entrada usando o otimizador. Por que não apenas usar um simples int?
Because EA should be for anyone to use and not just the person who programmed it.
I am using similar include file with 5 minute interval :
with this variable declaring
and this codes for checking time
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.
Thanks for the cooperation Mohammad
Updatingenum horario
{
hr00,//09:00
hr01,//09:05
hr02,//09:10
hr03,//09:15
hr04,//09:30
hr05,//09:45
hr06,//10:00
hr07,//10:15
hr08,//10:30
hr09,//10:45
hr10,//11:00
hr11,//11:15
hr12,//11:30
hr13,//11:45
hr14,//12:00
hr15,//12:15
hr16,//12:30
hr17,//12:45
hr18,//13:00
hr19,//13:15
hr20,//13:30
hr21,//13:45
hr22,//14:00
hr23,//14:15
hr24,//14:30
hr25,//14:45
hr26,//15:00
hr27,//15:15
hr28,//15:30
hr29,//15:45
hr30,//16:00
hr31,//16:15
hr32,//16:30
hr33,//16:45
hr34,//17:00
hr35,//17:15
hr36,//17:28
hr37,//17:45
hr38,//17:53
hr39,//18:00
};
input horario Inicio=1;//Hora de Início das Operações [formato 00:00]
input horario Termino=38;//Hora de Paralisação das Operações [formato 00:00]
input bool UseDayTrade=true;//Habilitar Operação DayTrade
input horario DayTrade=36;//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
(
"Horários: Abertura = ",inicio.hour,":",inicio.min,
" / Fechamento = ",termino.hour,":",termino.min,
" / Day Trade = ",daytrade.hour,":",daytrade.min,
"\n"
);
}
void OnTick()
{
tradeenabled=1;
if(stm.hour<inicio.hour || (stm.hour<=inicio.hour && stm.min<=inicio.min) ||
(stm.hour>=termino.hour && stm.min>termino.min) || stm.hour>termino.hour)
{tradeenabled=0;}
if(tradeenabled==1)
{
Regras de operação
}
}
//+------------------------------------------------------------------+
//| Função de Horários |
//+------------------------------------------------------------------+
string TimeFunction(horario time)
{
string retorno;
string hora[40]=
{
"09:00","09:05","09:10","09:15","09:30","09:45","10:00","10:15","10:30","10:45",
"11:00","11:15","11:30","11:45","12:00","12:15","12:30","12:45","13:00","13:15",
"13:30","13:45","14:00","14:15","14:30","14:45","15:00","15:15","15:30","15:45",
"16:00","16:15","16:30","16:45","17:00","17:15","17:28","17:45","17:53","18:00"
};
for(int index=0; index<=39; index++)
{
if(index==time){retorno=hora[index];break;}
}
return(retorno);
}
Hi!
Can you tell me what is the "stm" variable?
Thanks in advance!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.