Hi,
i would recommend you to change TimeFilter to this:bool TimeFilter(string Sh,string Eh) { datetime Strat=StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)+" " +Sh); datetime End =StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)+" "+ Eh); if((Time[0]>=Strat && Time[0]<=End)) { return(true); } return(false); }
Best regards
Hi,
i would recommend you to change TimeFilter to this:Best regards
thanks my friend but still dont work
Hi,
next i would try to output the values (Strat, End, Time) with the Print()-statement - maybe there is something wrong with the converting of the time values.
Best regards
Hi,
next i would try to output the values (Strat, End, Time) with the Print()-statement - maybe there is something wrong with the converting of the time values.
Best regards
thanks friend , if u found the probleme plz contact me
Hi,
i took the liberty of cleaning up your code a little - now it works fine in my environment.extern bool MON = true; input string StartH1 ="03:00"; input string EndH1 ="21:00"; extern bool TUE = true; input string StartH2 ="03:00"; input string EndH2 ="21:00"; extern bool WED = true; input string StartH3 ="03:00"; input string EndH3 ="21:00"; extern bool THU = true; input string StartH4 ="03:00"; input string EndH4 ="21:00"; extern bool FRI = true; input string StartH5 ="03:00"; input string EndH5 ="21:00"; input bool UseTimeFilter=true; bool Trade =false; void OnTick() { Trade = false; if ((UseTimeFilter == true) && (MON == true) && (DayOfWeek() == 1)) { if (TimeFilter(StartH1, EndH1) == true) Trade = true; } if ((UseTimeFilter == true) && (TUE == true) && (DayOfWeek() == 2)) { if (TimeFilter(StartH2, EndH2) == true) Trade = true; } if ((UseTimeFilter == true) && (WED == true) && (DayOfWeek() == 3)) { if (TimeFilter(StartH3, EndH3) == true) Trade = true; } if ((UseTimeFilter == true) && (THU == true) && (DayOfWeek() == 4)) { if (TimeFilter(StartH4, EndH4) == true) Trade = true; } if ((UseTimeFilter == true) && (FRI == true) && (DayOfWeek() == 5)) { if (TimeFilter(StartH5, EndH5) == true) Trade = true; } Print("Trade: ", Trade); } bool TimeFilter(string Sh, string Eh) { datetime Start = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Sh); datetime End = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Eh); if ((Time[0] >= Start) && (Time[0] <= End)) { return(true); } return(false); }
Best regards
- Werner Klehr: i took the liberty of cleaning up your code a little
if ((UseTimeFilter == true) && (WED == true) && (DayOfWeek() == 3))
You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.
Your code if ((Time[0] >= Start) && (Time[0] <= End)) { return(true); } return(false);
Simplify your code.
Increase Order after stoploss - MQL4 programming forum #1.3 (2017.05.29)return Time[0] >= Start && Time[0] <= End;
-
You don't handle the case where end < begin, e.g. start at 5 PM and end at 5 AM. For that you have to abandon comparing datetimes and instead just compare the time.
Find bar of the same time one day ago - MQL4 programming forum (2017.10.06) - Do you really want to include the first second of End?
Don't hard code constants.
if (UseTimeFilter && OkTradeWed && DayOfWeek() == WEDNESDAY)
Hi,
i took the liberty of cleaning up your code a little - now it works fine in my environment.Best regards
yeah its work realy good ..thanks my friend
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
can some one slove it .. why its dont work