Sie verpassen Handelsmöglichkeiten:
- Freie Handelsapplikationen
- Über 8.000 Signale zum Kopieren
- Wirtschaftsnachrichten für die Lage an den Finanzmärkte
Registrierung
Einloggen
Sie stimmen der Website-Richtlinie und den Nutzungsbedingungen zu.
Wenn Sie kein Benutzerkonto haben, registrieren Sie sich
Ein wenig mehr Bastelei mit dem Code führte zu diesem Ergebnis.
//| 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);
}
//+------------------------------------------------------------------+
Ergebnis
Ihre Funktion hat das Problem für mich gelöst.
Ich danke Ihnen!!!