Hello,
need a function to detect if a market is closed for FX symbol .
My solution
does not work: date begin and end always are 1970-01-01.
Is this because the Symbol is a FX contract ?
Do i something wrong ?
Thank you
This article is not really focused on my problem: get a simple method which tells you if market is open (ready for placing trades).
If you mean using SymbolInfoSessionQuote instead of SymbolInfoSessionTrade, no, makes no difference.
This article is not really focused on my problem: get a simple method which tells you if market is open (ready for placing trades).
If you mean using SymbolInfoSessionQuote instead of SymbolInfoSessionTrade, no, makes no difference.
One section of this article is exactly focused at your problem, there is a mql5 script with a complete example of code for SymbolInfoSessionTrade.
Oh sorry, didn't see the link.
Thank you. Basically there is a timestamp and date seems not to be important.
My new version works so far (but returns market open for expired contracts as well...)
bool market_closed(string symbol) { if(StringLen(symbol) > 1) { datetime begin=0; datetime end=0; datetime now=TimeCurrent(); uint session_index=0; MqlDateTime today; TimeToStruct(now,today); if( SymbolInfoSessionTrade(symbol,(ENUM_DAY_OF_WEEK ) today.day_of_week,session_index,begin,end) == true) { string snow=TimeToString(now,TIME_MINUTES|TIME_SECONDS); string sbegin=TimeToString(begin,TIME_MINUTES|TIME_SECONDS); string send=TimeToString(end-1,TIME_MINUTES|TIME_SECONDS); now=StringToTime(snow); begin=StringToTime(sbegin); end=StringToTime(send); if(now >= begin && now <= end) return false; return true; } } return false; }
Oh sorry, didn't see the link.
Thank you. Basically there is a timestamp and date seems not to be important.
My new version works so far (but returns market open for expired contracts as well...)
Which symbol did you use ?
Oh sorry, didn't see the link.
Thank you. Basically there is a timestamp and date seems not to be important.
My new version works so far (but returns market open for expired contracts as well...)
tyvm for the code saved me much work. I have changed it slightly and seems to be working for me now. checks if market is open.
bool market_open(string symbol) { if(StringLen(symbol)>1) { datetime begin=0; datetime end=0; datetime now=TimeTradeServer(); uint session_index=0; MqlDateTime today; TimeToStruct(now,today); if(SymbolInfoSessionTrade(symbol,(ENUM_DAY_OF_WEEK) today.day_of_week,session_index,begin,end)==true) { string snow=TimeToString(now,TIME_MINUTES|TIME_SECONDS); string sbegin=TimeToString(begin,TIME_MINUTES|TIME_SECONDS); string send=TimeToString(end-1,TIME_MINUTES|TIME_SECONDS); now=StringToTime(snow); begin=StringToTime(sbegin); end=StringToTime(send); if(now>=begin && now<=end) return true; return false; } else return false; } Print("invalid symbol!!!!!"); return false; }
tyvm for the code saved me much work. I have changed it slightly and seems to be working for me now. checks if market is open.
I use this simple code
you should replace "total index symbol" with yours
bool market_closed(string symbol) { string total_index_symbol="total index symbol"; long lastbar_time=SeriesInfoInteger(symbol,PERIOD_D1,SERIES_LASTBAR_DATE); long Tlastbar_time=SeriesInfoInteger(total_index_symbol,PERIOD_D1,SERIES_LASTBAR_DATE); if(((Tlastbar_time-lastbar_time)/3600/24)>1){ return true;} else {return false;} }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
need a function to detect if a market is closed for FX symbol .
My solution
does not work: date begin and end always are 1970-01-01.
Is this because the Symbol is a FX contract ?
Do i something wrong ?
Thank you