장 마감 - 페이지 2

 

다음과 같이 거래 시간 확인을 변경해야 한다고 제안합니다.

bool CheckExchTime()
{
   MqlTick cur_tick[ 1 ];
   MqlDateTime cur_time;
   if ( CopyTicks (Symbol(), cur_tick, COPY_TICKS_INFO , 0 , 1 )== 1 )
  {
     TimeToStruct (cur_tick[ 0 ].time, cur_time);
     ulong trade_time = cur_time.hour * 3600 + cur_time.min * 60 + cur_time.sec;
     if (((trade_time >= time_st_mon) && (trade_time < 50370 )) ||
       ((trade_time >= time_st_day) && (trade_time < 67470 )) ||
       ((trade_time >= time_st_evn) && (trade_time < 85770 )))
    {
       return ( true );
    }
  }
   return ( false );
}
 
prostotrader :

세레자!

TimeCurrent에 대한 도움말 읽기 - 이것은 SERVER 시간이라고 말합니다.

Возвращает последнее известное время сервера , время прихода последней котировки по одному из выбранных в "Обзоре рынка" символов.

틱이 없으면 주말 또는 비 거래 시간, TimeCurrent는 변경되지 않습니다.

그리고 TimeTradeServer 는 작동하지 않으며 컴퓨터의 현지 시간을 보여줍니다.

어드바이저를 실행하면 쉽게 확인할 수 있습니다.

//+------------------------------------------------------------------+
int OnInit ()
  {
//--- create timer
   EventSetTimer ( 1 );
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- destroy timer
   EventKillTimer ();
  }
//+------------------------------------------------------------------+
void OnTimer ()
  {
   Comment (
           "\n TimeCurrent: " , TimeCurrent (),
           "\n TimeTradeServer: " , TimeTradeServer (),
           "\n TimeLocal: " , TimeLocal (),
           "" );
  }
//+------------------------------------------------------------------+

컴퓨터의 시간이 변경되면 TimeTradeServer 도 변경되어 컴퓨터 시간 TimeLocal 을 표시합니다.

 
Sergey Chalyshev :

틱이 없으면 주말 또는 비 거래 시간, TimeCurrent는 변경되지 않습니다.

그리고 TimeTradeServer 는 작동하지 않으며 컴퓨터의 현지 시간을 보여줍니다.

어드바이저를 실행하면 쉽게 확인할 수 있습니다.

//+------------------------------------------------------------------+
int OnInit ()
  {
//--- create timer
   EventSetTimer ( 1 );
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- destroy timer
   EventKillTimer ();
  }
//+------------------------------------------------------------------+
void OnTimer ()
  {
   Comment (
           "\n TimeCurrent: " , TimeCurrent (),
           "\n TimeTradeServer: " , TimeTradeServer (),
           "\n TimeLocal: " , TimeLocal (),
           "" );
  }
//+------------------------------------------------------------------+

컴퓨터의 시간이 변경되면 TimeTradeServer 도 변경되어 컴퓨터 시간 TimeLocal 을 표시합니다.

그리고 TimeTradeServer를 통해 먼저 거래 시간을 확인한 다음 (시간이 거래되는 경우) 더 정확한 확인을 위해

내가 위에서 쓴 함수?

추가됨

물론 이 기호에 대한 따옴표가 없을 수 있으므로 이것은 옵션이 아닙니다.

 

나는 내 머리를 조금 깨고이 구현에 대해 생각하는 그러한 옵션을 썼습니다.

//+------------------------------------------------------------------+
//|                                                       test03.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"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart ()
  {
//---
   if (CheckExchTime()) Print ( "Торговля разрешена" );
   else Print ( "Торговля запрещена" );
  }
//+------------------------------------------------------------------+
bool CheckExchTime()
  {
   MqlTick last_tick;
   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 ();
   if ( SymbolInfoTick ( _Symbol ,last_tick))
     {
       TimeToStruct (last_tick.time,last_time);
       Print (last_tick.time, ": Bid = " ,last_tick.bid, " Ask = " ,last_tick.ask, " Last = " ,last_tick.last, "  Volume = " ,last_tick.volume);
       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= __DATE__ +(start_time.hour* 60 +start_time.min)* 60 ;
         end= __DATE__ +(end_time.hour* 60 +end_time.min)* 60 ;
         Print ( "trade_time_start = " ,trade_time_start, " trade_time_end = " ,trade_time_end);
         Print (start, " - " ,end);
         if (start==end) return ( true );
         if (last_tick.time>start && last_tick.time<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= __DATE__ +(start_time.hour* 60 +start_time.min)* 60 ;
         end= __DATE__ +(end_time.hour* 60 +end_time.min)* 60 ;
         Print ( "trade_time_start = " ,trade_time_start, " trade_time_end = " ,trade_time_end);
         Print (start, " - " ,end);
         if (start==end) return ( true );
         if (last_tick.time>start && last_tick.time<end) return ( true );
        }
       else Print ( "SymbolInfoSessionTrade(1) failed, error = " , GetLastError ());
     }
   else Print ( "SymbolInfoTick() failed, error = " , GetLastError ());
   return ( false );
  }
//+------------------------------------------------------------------+


...

 
prostotrader :

개발자 여러분!

글쎄, 당신은 언제 거래소의 시간과 단말의 시간을 동기화합니까?

Mikalas, 이것은 확실히 개발자를 위한 질문이 아닙니다. 이것은 브로커 관리자가 수행합니다. 당신은 그들을 목표로해야합니다 :-))
 

코드에 대해 조금 더 생각해 보면 이런 일이 발생했습니다.

//+------------------------------------------------------------------+
//|                                                       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 );
  }
//+------------------------------------------------------------------+

결과


 
Sergey Gritsay :

코드에 대해 조금 더 생각해 보면 이런 일이 발생했습니다.


당신은 우리가 말하는 것을 이해합니까?
 
prostotrader :
당신은 우리가 말하는 것을 이해합니까?
제가 잘 이해하지 못했을 수도 있고, 거래소의 거래 시간 외에 시장이 닫히지 않도록 솔루션이 필요한 방법을 이해했습니다.
 
Sergey Gritsay :
제가 잘 이해하지 못했을 수도 있고, 거래소의 거래 시간 외에 시장이 닫히지 않도록 솔루션이 필요한 방법을 이해했습니다.

솔루션은 프로그래머가 아니라 개발자(또는 브로커에 의존하는 경우 브로커)가 제공합니다.

제공한 코드는 CURRENT EXCHANGE 시간 을 확인하지 않습니다.

 

지금은 이 솔루션을 고수하고 있습니다.

bool CheckTradingTime( MqlDateTime &tick_time)
{
   datetime lk_time = TimeTradeServer (tick_time);
   if ( ( tick_time.day_of_week == int (FirstDay)) ||
       ( tick_time.day_of_week == int (SecondDay))) //выходные
  {
     return ( false );
  }
#ifdef DEBUG
   if ((tick_time.hour >= 0 ) && (tick_time.hour < 6 ))   // DEBUG 6-00
  {
     return ( false );
  }
#else
  
if ((tick_time.hour >= 0 ) && (tick_time.hour < 10 ))
  {
     return ( false );
  }
#endif
// 13 * 3600 + 59 * 60 + 30 = 50370 - 13:59:30
// 14 * 3600                = 50400 - 14:00:00
// 14 * 3600 + 30           = 50430 - 14:00:30
// 14 * 3600 + 60           = 50460 - 14:01:00

// 18 * 3600 + 44 * 60 + 30 = 67470 - 18:44:30
// 18 * 3600 + 45 * 60      = 67500 - 18:45:00
// 18 * 3600 + 45 * 60 + 30 = 67530 - 18:45:30
// 18 * 3600 + 46 * 60      = 67560 - 18:46:00

// 19 * 3600                = 68400 - 19:00:00
// 19 * 3600 + 60           = 68460 - 19:01:00  

// 23 * 3600 + 49 * 60 + 30 = 85770 - 23:49:30
// 23 * 3600 + 50 * 60      = 85800 - 23:50:00
// 23 * 3600 + 50 * 60 + 30 = 85830 - 23:50:30
// 23 * 3600 + 51 * 60      = 85860 - 23:51:00
//---
  lk_time = TimeCurrent (tick_time);
   ulong trade_time = tick_time.hour * 3600 + tick_time.min * 60 + tick_time.sec;  
//---                    //10:00:02                      
   if (((trade_time >= time_st_mon) && (trade_time < 50370 )) ||
      ((trade_time >= time_st_day) && (trade_time < 67470 )) ||
      ((trade_time >= time_st_evn) && (trade_time < 85770 )))
  {
     return ( true );
  }

return ( false );


}


먼저 TimeTradeServer 를 사용합니다. 현재 "더러운" 시간을 얻습니다.

모든 세션이 "중첩"되는 주말과 시간(거래)을 확인하고,

그런 다음 TimeCurrent 를 사용하십시오.

세션 내 시간을 확인하려면 서버의 현재 시간.

추가됨

그러나 이 검사에는 한 가지 중요한 단점이 있습니다.

컴퓨터의 현지 시간이 서버의 시간보다 크면 모든 것이 정상이지만

현지 시간이 더 짧으면 큰 문제가 나타납니다.

거래 서버 시간과 현지 시간의 차이로 거래 시작을 건너뛰세요. :(

따라서 TimeCurrent 가 필요합니다.

마지막으로 알려진 인용 시간뿐만 아니라 항상 서버 시간을 반환했습니다.

추가됨

또 다른 단점

시세는 청산에 오지 않으므로 청산에 TimeCurrent를 사용하는 것은(예: 보류 중인 주문을 제거하기 위해) 무의미합니다.

사유: