//+------------------------------------------------------------------+ //| TimeWindowsTriple.mq4 | //| Programando Forex | //| http://www.programandoforex.com | //+------------------------------------------------------------------+ // El indicador muestra si estamos dentro de una de las ventanas temporales habilitadas (colores verde/rojo). #property copyright "Programando Forex" #property link "http://www.programandoforex.com" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Green #property indicator_color2 Red #property indicator_color3 Yellow #property indicator_width1 4 #property indicator_width2 4 #property indicator_width3 4 #property indicator_minimum 0 #property indicator_maximum 1 //---- buffers double GreenBuffer[]; double RedBuffer[]; double YellowBuffer[]; // Parámetros externos extern string s60 = "*** Horarios para la operativa **********"; //extern bool OperarSiempre? = false; extern string s70 = "*** Configurar Ventana #1 ***"; extern bool Activar_Window1? = true; extern string Window1_Ini= "10:00"; extern string Window1_Fin = "11:00"; extern string s80 = "*** Configurar Ventana #2 ***"; extern bool Activar_Window2? = true; extern string Window2_Ini= "12:00"; extern string Window2_Fin = "13:00"; extern string s90 = "*** Configurar Ventana #3 ***"; extern bool Activar_Window3? = true; extern string Window3_Ini= "23:30"; extern string Window3_Fin = "1:10"; int init() { IndicatorBuffers(3); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexBuffer(0,GreenBuffer); SetIndexBuffer(1,RedBuffer); SetIndexBuffer(2,YellowBuffer); string short_name="TimeWindow"; IndicatorShortName(short_name); SetIndexLabel(0,"In Windows"); SetIndexLabel(1,"Out Windows"); SetIndexLabel(2,"Sunday/Friday Limit"); } int start() { int limit; int counted_bars=IndicatorCounted(); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=0; i oTimeIni) oTimeFin += 86400; // 60s * 60m * 24H if(oTimeBarra < oTimeIni) oTimeIni -= 86400; } if(oTimeIni < oTimeBarra && oTimeBarra < oTimeFin) return(1); // No consultar más. else horario = 0; } if(Activar_Window2?){ // Calcular oTime del tiempo Inicio. Ajustamos un periodo. oTimeIni = StrToTime(Window2_Ini) - (Period()*60); // Calcular oTime del tiempo Fin. Ajustamos un periodo. // Sabemos que una ventana traspasa las 24 horas, ej. de 10:00 a 01:00, porque oTimeFin < oTimeIni. Y le sumamos 24 horas a oTimeFin. oTimeFin = StrToTime(Window2_Fin) + (Period()*60); //if(oTimeFin < oTimeIni) oTimeFin += 86400; // 60s * 60m * 24H if(oTimeFin < oTimeIni){ if(oTimeBarra > oTimeIni) oTimeFin += 86400; // 60s * 60m * 24H if(oTimeBarra < oTimeIni) oTimeIni -= 86400; } if(oTimeIni < oTimeBarra && oTimeBarra < oTimeFin) return(1); // No consultar más. else horario = 0; } if(Activar_Window3?){ // Calcular oTime del tiempo Inicio. Ajustamos un periodo. oTimeIni = StrToTime(Window3_Ini) - (Period()*60); // Calcular oTime del tiempo Fin. Ajustamos un periodo. // Sabemos que una ventana traspasa las 24 horas, ej. de 10:00 a 01:00, porque oTimeFin < oTimeIni. Y le sumamos 24 horas a oTimeFin. oTimeFin = StrToTime(Window3_Fin) + (Period()*60); //if(oTimeFin < oTimeIni) oTimeFin += 86400; // 60s * 60m * 24H if(oTimeFin < oTimeIni){ if(oTimeBarra > oTimeIni) oTimeFin += 86400; // 60s * 60m * 24H if(oTimeBarra < oTimeIni) oTimeIni -= 86400; } if(oTimeIni < oTimeBarra && oTimeBarra < oTimeFin) return(1); // No consultar más. else horario = 0; } return(horario); }