How to check if the market is closed in MT4
To get symbol quote and trade sessions please use example below.
public bool IsQuoteSession(QuoteClient qc, string symbol)
{
ConSessions[] sessionsForWeek = qc.GetSymbolInfo("EURUSD").Ex.sessions;
var todaySessions = sessionsForWeek[(int)qc.ServerTime.DayOfWeek];
foreach (var item in todaySessions.quote)
{
var start = new DateTime(qc.ServerTime.Year, qc.ServerTime.Month, qc.ServerTime.Day, item.open_hour, item.open_min, 0);
var end = new DateTime(qc.ServerTime.Year, qc.ServerTime.Month, qc.ServerTime.Day, item.close_hour, item.close_min, 0);
if (qc.ServerTime > start && qc.ServerTime < end)
return true;
}
return false;
}
public bool IsTradeSession(QuoteClient qc, string symbol)
{
ConSessions[] sessionsForWeek = qc.GetSymbolInfo("EURUSD").Ex.sessions;
var todaySessions = sessionsForWeek[(int)qc.ServerTime.DayOfWeek];
foreach (var item in todaySessions.trade)
{
var start = new DateTime(qc.ServerTime.Year, qc.ServerTime.Month, qc.ServerTime.Day, item.open_hour, item.open_min, 0);
var end = new DateTime(qc.ServerTime.Year, qc.ServerTime.Month, qc.ServerTime.Day, item.close_hour, item.close_min, 0);
if (qc.ServerTime > start && qc.ServerTime < end)
return true;
}
return false;
}