Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
A little more tinkering with the code resulted in this.
//| test06.mq5 |
//| Sergey Gritsay |
//| https://www.mql5.com/ru/users/sergey1294 |
//+------------------------------------------------------------------+
#property copyright "Sergey Gritsay"
#property link "https://www.mql5.com/ru/users/sergey1294"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetMillisecondTimer(1);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
string text=NULL;
int symbol_total=SymbolsTotal(true);
for(int i=0; i<symbol_total; i++)
{
string symbol=SymbolName(i,true);
if(CheckExchTime(symbol,TimeCurrent()))text+="\n"+symbol+": Торговля разрешена";
else text+="\n"+symbol+": Торговля запрещена";
}
Comment(text);
}
//+------------------------------------------------------------------+
bool CheckExchTime(string symbol,datetime times)
{
MqlDateTime last_time;
MqlDateTime start_time;
MqlDateTime end_time;
datetime trade_time_start=0;
datetime trade_time_end=0;
datetime start=0;
datetime end=0;
ResetLastError();
datetime expiration=(datetime)SymbolInfoInteger(symbol,SYMBOL_EXPIRATION_TIME);
if(expiration!=0 && times>=expiration)return(false);
TimeToStruct(times,last_time);
if(SymbolInfoSessionTrade(symbol,(ENUM_DAY_OF_WEEK)last_time.day_of_week,0,trade_time_start,trade_time_end))
{
TimeToStruct(trade_time_start,start_time);
TimeToStruct(trade_time_end,end_time);
start=StringToTime((string)last_time.year+"."+(string)last_time.mon+"."+(string)last_time.day+" "+(string)start_time.hour+":"+(string)start_time.min+":00");
end=StringToTime((string)last_time.year+"."+(string)last_time.mon+"."+(string)last_time.day+" "+(string)end_time.hour+":"+(string)end_time.min+":00");
if(start==end)return(true);
if(times>start && times<end)return(true);
}
//else Print("SymbolInfoSessionTrade(0) failed, error = ",GetLastError());
if(SymbolInfoSessionTrade(symbol,(ENUM_DAY_OF_WEEK)last_time.day_of_week,1,trade_time_start,trade_time_end))
{
TimeToStruct(trade_time_start,start_time);
TimeToStruct(trade_time_end,end_time);
start=StringToTime((string)last_time.year+"."+(string)last_time.mon+"."+(string)last_time.day+" "+(string)start_time.hour+":"+(string)start_time.min+":00");
end=StringToTime((string)last_time.year+"."+(string)last_time.mon+"."+(string)last_time.day+" "+(string)end_time.hour+":"+(string)end_time.min+":00");
if(start==end)return(true);
if(times>start && times<end)return(true);
}
//else Print("SymbolInfoSessionTrade(1) failed, error = ",GetLastError());
return(false);
}
//+------------------------------------------------------------------+
Result
Your function solved it for me here.
Thank you!!!