MarketClosed() Method - how to determine day to trade on.
Chris Stols:
Hi There;
Anyone got a suggestion in code snippet i can use to calculate if a symbol can work within a date range properly?
I have the above mentioned code but it fails miserably on the following:
Try this code:
//+------------------------------------------------------------------+ //| Checks if market is currently open for specified symbol | //+------------------------------------------------------------------+ //bool IsMarketOpen(const string symbol) bool CheckSessionTrade(const string symbol) { MqlDateTime STime; datetime time = TimeTradeServer(STime); datetime time_sec = time % PeriodSeconds(PERIOD_D1); //--- datetime from, to; uint session_index=0; while(SymbolInfoSessionTrade(symbol, (ENUM_DAY_OF_WEEK)STime.day_of_week, session_index++, from, to)) if(time_sec >=from && time_sec <= to) return true; //--- return false; } //--- check trading session time if(!CheckSessionTrade(m_PositionForInstrument.ProductName)) { // if failed the check Print("Error: Trading is not allowed [Market closed]."); PlaySound("timeout.wav"); }

You are missing trading opportunities:
- Free trading apps
- Free Forex VPS for 24 hours
- 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
Hi There;
Anyone got a suggestion in code snippet i can use to calculate if a symbol can work within a date range properly?
I have the above mentioned code but it fails miserably on the following: