장 마감 - 페이지 12 1...56789101112 새 코멘트 Vinicius Pereira De Oliveira 2022.05.01 12:27 #111 Sergey Gritsay # : 코드를 조금 더 조정하면 이런 결과가 나타납니다. //+------------------------------------------------------------------+ //| 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 ); } //+------------------------------------------------------------------+ 결과 귀하의 기능은 여기에서 나를 위해 해결했습니다. 감사해요!!! //+--------------------------------------------------------------------------------------------------------------------+ //| This function checks if the symbol is trading at the current time | //+--------------------------------------------------------------------------------------------------------------------+ bool CheckTradingTime( string symbol) { //--- Local variables datetime times = TimeCurrent (), trade_time_start = 0 , trade_time_end = 0 , start = 0 , end = 0 ; MqlDateTime last_time, start_time, end_time; //--- Check symbol trade end date datetime expiration = ( datetime ) SymbolInfoInteger (symbol, SYMBOL_EXPIRATION_TIME ); if (expiration != 0 && times >= expiration) { return ( false ); } TimeToStruct (times, last_time); //--- Session index: 0 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 ); } } //--- Session index: 1 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 ); } } //--- Check completed return ( false ); } 1...56789101112 새 코멘트 트레이딩 기회를 놓치고 있어요: 무료 트레이딩 앱 복사용 8,000 이상의 시그널 금융 시장 개척을 위한 경제 뉴스 등록 로그인 공백없는 라틴 문자 비밀번호가 이 이메일로 전송될 것입니다 오류 발생됨 Google으로 로그인 웹사이트 정책 및 이용약관에 동의합니다. 계정이 없으시면, 가입하십시오 MQL5.com 웹사이트에 로그인을 하기 위해 쿠키를 허용하십시오. 브라우저에서 필요한 설정을 활성화하시지 않으면, 로그인할 수 없습니다. 사용자명/비밀번호를 잊으셨습니까? Google으로 로그인
코드를 조금 더 조정하면 이런 결과가 나타납니다.
//| 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 );
}
//+------------------------------------------------------------------+
결과
귀하의 기능은 여기에서 나를 위해 해결했습니다.
감사해요!!!