Can anyone please help me code for my EA to only trade between 7am and 11am /1PM and 4PM GMT. please could you explain the code so I can learn. much appreciated
- MQL4 Learning
- EA to trade only on certain time periods
- Help! Need Time Filter / Time mgt
Hello you can find some examples here: https://www.mql5.com/en/docs/dateandtime
Documentation on MQL5: Date and Time
- www.mql5.com
This is the group of functions for working with data of datetime type (an integer that represents the number of seconds elapsed from 0 hours of January 1, 1970).
Why do you want to trade on those hours ? Are gold hours or.. ?:)
Adam Woods:
Can anyone please help me code for my EA to only trade between 7am and 11am /1PM and 4PM GMT. please could you explain the code so I can learn. much appreciated
Can anyone please help me code for my EA to only trade between 7am and 11am /1PM and 4PM GMT. please could you explain the code so I can learn. much appreciated
You can copy and paste this function into your EA. but this code is for MT4.
bool enableTrade(){ if(Hour() >= 7 && Hour() <= 11){ return true; } return false; }
7 and 11 is server time. You can change it accordingly.
After that, you use it to initiate a trade for example:
if(enableTrade() == true){ //do your thing here... }
Easy.
Good luck.
Ahmad Zuhairdi Noh:
- Simplify your code
bool enableTrade(){ return Hour() >= 7 && Hour() < 11; }
- OP asked for "between 7am and 11am" your code was [7am … 11:59:59]
i wrote something related to this and i discover that
this datetime c_Trade_1CloseTrades=StrToTime(Trade_1CloseTrades); datetime c_Trade_2CloseTrades=StrToTime(Trade_2CloseTrades); work on strategy tester but not on Live Market .
so i use
this string today = TimeToStr(TimeCurrent(), TIME_DATE); datetime c_Trade_1CloseTrades=StringToTime(today+" "+TimeToStr(StringToTime(Trade_1CloseTrades), TIME_MINUTES)); datetime c_Trade_2CloseTrades=StringToTime(today+" "+TimeToStr(StringToTime(Trade_2CloseTrades), TIME_MINUTES));
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register