You can consider using TimeGMT instead of broker time.
Closing at 23:59 will not work because usually brokers close trading 5 minutes before the session rollover.
Theorically the best approach should be to use SessionInfoTrade to retrieve correct trading times and do operations according to that.
Practically, the low liquidity and potential slippages may lead this operations more dangerous than leaving trades opened over weekend.
Also, for buy trades you will surely pay a huge spread when reopening at 00:01, having almost certainly a worse opening price.
Fabio Cavalloni #:
Practically, the low liquidity and potential slippages may lead this operations more dangerous than leaving trades opened over weekend.
Practically, the low liquidity and potential slippages may lead this operations more dangerous than leaving trades opened over weekend.
Yes, that the reason, i am trying to close 1 hour or maybe 3 hour before market close.
Fabio Cavalloni #:
buy trades you will surely pay a huge spread when reopening at 00:01,
buy trades you will surely pay a huge spread when reopening at 00:01,
I am not instantly taking trade, That the reason i wanted new trade to be taken by EA after X hours to avoid Huge spread.
I made little fix and i am trying like this but still something is missing :
extern int MinuteToAvoid = 60; void MarketHoursMonitor() { datetime serverTime = TimeCurrent(); int dayOfWeek = TimeDayOfWeek(serverTime); datetime todayMidnight = StringToTime(TimeToString(serverTime, TIME_DATE) + " 00:00"); datetime sessionOpenOffset, sessionCloseOffset; if (SymbolInfoSessionTrade(Symbol(), (ENUM_DAY_OF_WEEK)dayOfWeek, 0, sessionOpenOffset, sessionCloseOffset)) { datetime realSessionOpen = todayMidnight + sessionOpenOffset; datetime realSessionClose = todayMidnight + sessionCloseOffset; //--------- Friday: Close all trades 1 hour before market close ---------// if (dayOfWeek == 5) { datetime closeAllTime = realSessionClose - (MinuteToAvoid * 60); // 1 hour before session close if (serverTime >= closeAllTime) { // Close trades } } //--------- Monday: Open after 1 hour of market opening ---------// if (dayOfWeek == 1) { datetime oneHourAfterOpen = realSessionOpen + (MinuteToAvoid * 60); // 1 hour after session open if (serverTime >= oneHourAfterOpen) { // Open new trade or allow trading } } } }

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
Hello,
I am trying to achieve two operation, On friday before market close, close all the open trade before X hour and On monday after market open, Start taking new trade after X hour. I am trying like this
Main problem is Different broker have different timezone, This work according to broker timezone StrToTime(dateToday + " 23:59") and StrToTime(dateToday + " 00:01")
What should i do to make it work?