How to check Market Open/Closed in MT5 ? - page 4

 
Jeronymite #:

Having experimented with all this in MT5, I have several questions. First though, I want to do this to ensure that no matter where on the globe my EA is used, I can always give an accurate answer to the question "Is the market for this symbol with this broker still active/open or not?" That applies to any symbol, any broker, any exchange, any global timezone in which a trader is trading. This includes Forex. I recognise that different brokers may have different times for the same symbol. That's fine, and all the more reason for this to be able to provide a reliably accurate determination of open/closed.

So, my questions:

  1. The recommended way to determine this seems to be to use SymbolInfoSessionTrade and SymbolInfoSessionQuote. Is that correct? If not, what is preferred?
  2. Using SymbolInfoSessionTrade/Quote, what timezone is used for the Day of Week specified, and in what timezone are the retrieved session times specified?
  3. In 2 above, it is reasonable to assume that for exchange-based symbols (e.g. futures), this would be the timezone of the exchange. Is that correct? If not, what timezone must be used?
  4. If 3 above is correct, can one determine the exchange timezone for these types of symbols in MT5? If not, what is recommended to find this?
  5. For non-exchange-based symbols (e.g. Forex), what timezone is required for the Day of Week specified, and in what timezone are the retrieved session times specified?

    Assume that the questions above are able to be answered fully and accurately, and for any symbol with any broker, and that the relevant session times and dates are correctly determined and specified in a known timezone.

  6. To determine active/closed requires a datetime comparison. It seems that using TimeTradeServer is the required reference time for comparison with retrieved session times. Is that correct? If not, what is required?
  7. Is it safe to assume that 6 above works for all exchange-based symbols?
  8. What reference time is required for non-exchange-based symbols?

I appreciate answers to the questions. Any code that is comprehensive for any symbol, any broker, any timezone used by a trader, would be most welcome.

Thanks.

Simple code I use

void OnTick()
  {
   //Print("The market is close? ", market_closed(_Symbol));
  }
//+------------------------------------------------------------------+
bool market_closed(string symbol)
  {
   datetime daytime = iTime(symbol, PERIOD_D1, 0);
   MqlDateTime tm;
   TimeCurrent(tm);
//==
   MqlDateTime sm;
   TimeToStruct(daytime, sm);

   if(sm.day_of_week != tm.day_of_week)
     {
      return true;
     }
   return false;
  }
//+------------------------------------------------------------------+
 
Chioma Obunadike #:

Simple code I use

Thanks, Chioma Obunadike.

Unfortunately, I don't think that is sufficient to meet the requirements I've specified. It's possible for the market to close at a time of day that is earlier than the end of the day and so there may be several hours before the day of the week changes during which the market is closed, but the test you make would say it is open because the day of the week has not yet changed. It also might fail when an exchange-based session crosses midnight in the trader's local timezone but the session is still open in the exchange timezone in the same (previous) day.

Further contributions would be most welcome.

Thanks.

How to check Market Open/Closed in MT5 ?
How to check Market Open/Closed in MT5 ?
  • 2024.04.01
  • Chioma Obunadike
  • www.mql5.com
Please, how I can check if market is open or closed in MT5, I cant find answer...
 
Have a look on CloseOnWeekend_ea.mq5
 
amrali #:
Have a look on CloseOnWeekend_ea.mq5

Many thanks, amrali. That looks like it might be a good solution. You've obviously put in a lot of thought and effort! I will look at it in detail and respond there if need.

Thanks!