Usually time filter is widely used. For those that need Hours time filter here it is:
Can somebody share time filter that includes both hours and minutes?
Thanks.
extern string TradeStartTime = "8:30"; extern string TradeStopTime = "23:30"; ..................... if(TimeCurrent()>StrToTime(TradeStartTime) && TimeCurrent()<StrToTime(TradeStopTime)) EAActivated = true; else EAActivated = false;
bool EAActivated = (TimeCurrent()>StrToTime(TradeStartTime) && TimeCurrent()<StrToTime(TradeStopTime) );
i think there is a little problem.
If start time 23 and end time 8, it will not recognize.
int DOW = TimeDayOfWeek(now), /* https://forum.mql4.com/33851 // reports DayOfWeek() always returns 5 in the tester. No refresh?*/ DayMask = 1 << DOW; if (Days.Mask & DayMask == 0){ rsn="|Day="+DOW; return;} // int tradeSec.UTC.start = 3600*TradeHr.UTC.Start-86400, // tradeSec.UTC.end = 3600*TradeHr.UTC.End -86400; int hrBeg = (now-tradeSec.UTC.start)%86400, hrEnd = (now-tradeSec.UTC.end )%86400; if (hrBeg > hrEnd){ rsn="|HR"+DoubleToStr(hrBeg/3600.-24.,2); return;}
extern bool MON = TRUE; extern bool TUE = TRUE; extern bool WED = TRUE; extern bool THU = TRUE; extern bool FRI = TRUE; extern bool SAT = TRUE; extern bool SUN = TRUE; extern int HOURS_2TRADE_FROM = 8; extern int HOURS_2TRADE_TO = 16;void WEEKDAYS_2TRADE() { if ((MON && DayOfWeek() == 1) || (TUE && DayOfWeek() == 2) || (WED && DayOfWeek() == 3) || (THR && DayOfWeek() == 4) || (FRI && DayOfWeek() == 5) || (SAT && DayOfWeek() == 6) || (SUN && DayOfWeek() == 0)) HOURS_2TRADE(); } void HOURS_2TRADE() { int LOCAL_PC_TIME = TimeLocal(); int HOURS = TimeHour(LOCAL_PC_TIME); if ((HOUR_2TRADE_FROM < HOUR_2TRADE_TO && HOURS >= HOUR_2TRADE_FROM && HOURS < HOUR_2TRADE_TO) || (HOUR_2TRADE_FROM > HOUR_2TRADE_TO && HOURS < HOUR_2TRADE_TO || HOURS >= HOUR_2TRADE_FROM)) HERE_NEXT_F_EX_TECHNICAL_ANAL(); }
ITS EXTREMELY CLEAR AND AND SIMPLE AND 23-MIDNIGHT-8 ISN'T AN ISSUE ASWELL
//U don't need written or verbal permission to use this code... created thx 2 MQL ref, not decompiler/ remark to WHRoeder;)
I did it this way, it uses server time not local time . . .
// only allow trading between Start_Time and Finish_Time Current_Time = TimeHour(TimeCurrent()); if (Start_Time == 0) Start_Time = 24; if (Finish_Time == 0) Finish_Time = 24; if (Current_Time == 0) Current_Time = 24; if ( Start_Time < Finish_Time ) { if ( (Current_Time < Start_Time) || (Current_Time >= Finish_Time) ) return(0); } if ( Start_Time > Finish_Time ) { if ( (Current_Time < Start_Time) && (Current_Time >= Finish_Time) ) return(0); }
ITS EXTREMELY CLEAR AND AND SIMPLE AND 23-MIDNIGHT-8 ISN'T AN ISSUE ASWELL
No need to SHOUT.
The extern bool means they can not be optimized in the tester. You can change to extern int, but that's still 9 separate variables. It also does not allow fractional hours or minutes needed since Official business hours in London run between 7:30am and 3:30pm GMT especially on lower timeframe charts.
My version does it with three externals, and two compares (not 27,) and allows fractional hours./*++++ Day/Time allowed to open*/{ datetime now = TimeGMT(); int DOW = TimeDayOfWeek(now), /* https://www.mql5.com/en/forum/127483 // reports DayOfWeek() always returns 5 in the tester. No refresh?*/ DayMask = 1 << DOW; // #define DAYS_MAX 0x3F// 1<<6-1=63. (S-F) //extern int Days.Mask = 55; // Not Wed if (Days.Mask & DayMask == 0){ StrApnd(EA.status," Day=",DOW); return; } //extern double TradeHr.UTC.Start = 7.3; // London-1 //extern double TradeHr.UTC.End = 12.9; // NY open int secStart = 3600*TradeHr.UTC.Start, secEnd = 3600*TradeHr.UTC.End, hrBeg = (now-secStart+86400)%86400, hrEnd = (now-secEnd +86400)%86400; if (hrBeg > hrEnd){ double Tminus=hrBeg/3600.-24; StrApnd(EA.status," HR", DoubleToStr(Tminus,2)); return; } /*---- Day/Time allowed to open*/}
of course your does... i have never said there are any disadvantages in your code... just shown one of the alternative way. My lvl doesn't allow me to be as fluent in coding as you are... so i did my best... this is what count i believe.
of course your does... i have never said there are any disadvantages in your code... just shown one of the alternative way. My lvl doesn't allow me to be as fluent in coding as you are... so i did my best... this is what count i believe.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Usually time filter is widely used. For those that need Hours time filter here it is:
Can somebody share time filter that includes both hours and minutes?
Thanks.