CustomSymbolSetSessionQuote

지정된 심볼 및 평일에 대해 지정된 시세 세션의 시작 및 종료 시간을 설정합니다.

bool  CustomSymbolSetSessionQuote(
   const string      symbol_name,         // 심볼 이름
   ENUM_DAY_OF_WEEK  day_of_week,         // 평일
   uint              session_index,       // 세션 인덱스
   datetime          from,                // 세션 시작 시간
   datetime          to                   // 세션 종료 시간
   );

매개변수

symbol_name

[in]  사용자 지정 심볼 이름.

ENUM_DAY_OF_WEEK

[in]  평일, ENUM_DAY_OF_WEEK 열거 값.

uint

[in]  시작 시간과 종료 시간을 설정할 세션의 인덱스. 세션 인덱싱은 0부터 시작합니다.

from

[in]  00:00부터의 세션 시작 시간(초), 변수의 데이터 값은 무시됩니다.

to

[in]  00:00부터 세션 종료 시간(초), 변수의 데이터 값은 무시됩니다.

값 반환

성공하면 true, 그렇지 않으면 false. 오류에 대한 정보를 얻으려면 GetLastError() 함수를 호출.

주의

지정된 session_index를 가진 세션이 이미 있는 경우, 이 함수는 단순히 세션의 시작과 끝을 편집합니다.

세션에 대해 0 시작 및 종료 매개변수가 전달될 경우(from=0 and to=0), session_index가 아래로 이동하는 동안 해당 세션은 삭제됩니다.

세션은 순차적으로 추가할 수 있습니다. 즉 인�H가 0인 세션이 이미 있는 경우에만 session_index=1을 추가할 수 있습니다. 이 규칙이 위반되면 새 세션이 생성되지 않고 함수 자체는 'false'를 반환합니다.

 

예:

//+------------------------------------------------------------------+
//|                                  CustomSymbolSetSessionQuote.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   CUSTOM_SYMBOL_NAME     Symbol()+".C"           // 사용자 지정 심볼 명
#define   CUSTOM_SYMBOL_PATH     "Forex"                 // 심볼이 생성될 그룹의 이름
#define   CUSTOM_SYMBOL_ORIGIN   Symbol()                // 사용자 정의 심볼의 기반이 되는 심볼 명
 
#define   SESSION_0_FROM         D'1970.01.01 00:15:00'  // 세션 0 시작 시간
#define   SESSION_0_TO           D'1970.01.01 11:59:00'  // 세션 0 종료 시간
#define   SESSION_1_FROM         D'1970.01.01 12:15:00'  // 세션 1 시작 시간
#define   SESSION_1_TO           D'1970.01.01 23:59:00'  // 세션 1 종료 시간
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 사용자 정의 심볼을 생성할 때 오류 코드를 가져옵니다.
   int create=CreateCustomSymbol(CUSTOM_SYMBOL_NAMECUSTOM_SYMBOL_PATHCUSTOM_SYMBOL_ORIGIN);
   
//--- 오류 코드가 0(심볼 생성 성공)도 아니고 5304(심볼이 이미 생성됨)도 아닌 경우 - 그대로 둠
   if(create!=0 && create!=5304)
      return;
    
//--- 기본 심볼과 세션 인덱스가 포함된 헤더를 인쇄하고
//--- 월요일부터 금요일까지 요일별 루프에서 각 쿼트 세션의 시작 및 종료 시간을 저널에 출력합니다.
   for(int session=0session<2session++)
     {
      PrintFormat("Quote session %d of '%s' symbol from which the custom '%s' was created"sessionCUSTOM_SYMBOL_ORIGINCUSTOM_SYMBOL_NAME); 
      for(int day_of_week=MONDAYday_of_week<SATURDAYday_of_week++) 
         SymbolInfoSessionQuotePrint(CUSTOM_SYMBOL_ORIGIN, (ENUM_DAY_OF_WEEK)day_of_weeksession);     
     }
     
//--- 두 세션의 루프에서
   bool res=true;
   for(int session=0session<2session++)
     {
      datetime from = SESSION_0_FROM;
      datetime to   = SESSION_0_TO;
      if(session>0)
        {
         from = SESSION_1_FROM;
         to   = SESSION_1_TO;
        }
      //--- 각 요일의 맞춤 심볼에 대한 쿼트 세션 시간 설정
      ResetLastError();
      for(int day_of_week=MONDAYday_of_week<SATURDAYday_of_week++)
         res &=CustomSymbolSetSessionQuote(CUSTOM_SYMBOL_NAME, (ENUM_DAY_OF_WEEK)day_of_weeksessionfromto);
     }
 
//--- 세션 설정 시 오류가 발생한 경우 저널에 해당 메시지를 표시합니다.
   if(!res)
      Print("CustomSymbolSetSessionQuote() failed. Error "GetLastError());
   
//--- 사용자 정의 심볼과 세션 인덱스로 헤더를 인쇄하고
//--- 월요일부터 금요일까지 요일별 루프에서 각 쿼트 세션의 시작 및 종료 시간을 저널에 출력합니다.
   for(int session=0session<2session++)
     {
      PrintFormat("Quote session %d of custom symbol '%s' based on '%s'"sessionCUSTOM_SYMBOL_NAMECUSTOM_SYMBOL_ORIGIN); 
      for(int day_of_week=MONDAYday_of_week<SATURDAYday_of_week++) 
         SymbolInfoSessionQuotePrint(CUSTOM_SYMBOL_NAME, (ENUM_DAY_OF_WEEK)day_of_weeksession);     
     }
     
//--- 차트 주석에 스크립트 종료 키에 대한 힌트를 표시합니다.
   Comment(StringFormat("Press 'Esc' to exit or 'Del' to delete the '%s' symbol and exit"CUSTOM_SYMBOL_NAME));
//--- Esc 또는 Del 키를 눌러 무한 루프를 종료할 때까지 기다립니다.
   while(!IsStopped() && TerminalInfoInteger(TERMINAL_KEYSTATE_ESCAPE)==0)
     {
      Sleep(16);
      //--- Del을 누르면 생성된 사용자 정의 심볼이 삭제됩니다.
      if(TerminalInfoInteger(TERMINAL_KEYSTATE_DELETE)<0)
        {
         if(DeleteCustomSymbol(CUSTOM_SYMBOL_NAME))
            PrintFormat("Custom symbol '%s' deleted successfully"CUSTOM_SYMBOL_NAME);
         break;
        }
     }
//--- 종료하기 전에 차트를 삭제
   Comment("");
   /*
   결과:
   Quote session 0 of 'EURUSDsymbol from which the custom 'EURUSD.Cwas created
   - Monday     00:15 - 23:55
   - Tuesday    00:15 - 23:55
   - Wednesday  00:15 - 23:55
   - Thursday   00:15 - 23:55
   - Friday     00:15 - 23:55
   Quote session 1 of 'EURUSDsymbol from which the custom 'EURUSD.Cwas created
   - Monday     Session not set
   - Tuesday    Session not set
   - Wednesday  Session not set
   - Thursday   Session not set
   - Friday     Session not set
   Quote session 0 of custom symbol 'EURUSD.Cbased on 'EURUSD'
   - Monday     00:15 - 11:59
   - Tuesday    00:15 - 11:59
   - Wednesday  00:15 - 11:59
   - Thursday   00:15 - 11:59
   - Friday     00:15 - 11:59
   Quote session 1 of custom symbol 'EURUSD.Cbased on 'EURUSD'
   - Monday     12:15 - 23:59
   - Tuesday    12:15 - 23:59
   - Wednesday  12:15 - 23:59
   - Thursday   12:15 - 23:59
   - Friday     12:15 - 23:59
   */
  }
//+------------------------------------------------------------------+
//| Create a custom symbol, return an error code                     |
//+------------------------------------------------------------------+
int CreateCustomSymbol(const string symbol_nameconst string symbol_pathconst string symbol_origin=NULL)
  {
//--- 사용자 정의 심볼의 기반이 될 심볼명을 정의합니다.
   string origin=(symbol_origin==NULL ? Symbol() : symbol_origin);
   
//--- 사용자 정의 심볼 생성에 실패했고 오류 5304가 아닌 경우 저널에 이를 보고합니다.
   ResetLastError();
   int error=0;
   if(!CustomSymbolCreate(symbol_namesymbol_pathorigin))
     {
      error=GetLastError();
      if(error!=5304)
         PrintFormat("CustomSymbolCreate(%s, %s, %s) failed. Error %d"symbol_namesymbol_pathoriginerror);
     }
//--- 성공
   return(error);
  }
//+------------------------------------------------------------------+
//| 사용자 정의 심볼 삭제                                               |
//+------------------------------------------------------------------+
bool DeleteCustomSymbol(const string symbol_name)
  {
//--- 종합시세 창에서 심볼 숨기기
   ResetLastError();
   if(!SymbolSelect(symbol_namefalse))
     {
      PrintFormat("SymbolSelect(%s, false) failed. Error %d"GetLastError());
      return(false);
     }
      
//--- 사용자 정의 심볼 삭제에 실패한 경우 이를 저널에 보고하고 'false'를 반환합니다.
   ResetLastError();
   if(!CustomSymbolDelete(symbol_name))
     {
      PrintFormat("CustomSymbolDelete(%s) failed. Error %d"symbol_nameGetLastError());
      return(false);
     }
//--- 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 지정된 쿼트 세션의 시작 및 종료 시간 보내기                            |
//| 지정된 심볼 및 요일에 대한 저널                                      |
//+------------------------------------------------------------------+ 
void SymbolInfoSessionQuotePrint(const string symbolconst ENUM_DAY_OF_WEEK day_of_weekconst uint session_index
  { 
//--- 쿼트 세션의 시작과 끝을 기록하는 변수를 선언합니다.
   datetime date_from;  // session start time 
   datetime date_to;    // session end time 
    
//--- 열거형 상수로부터 요일 이름을 생성합니다.
   string week_day=EnumToString(day_of_week); 
   if(week_day.Lower()) 
      week_day.SetChar(0ushort(week_day.GetChar(0)-32)); 
  
//--- 심볼 및 요일별로 쿼트 세션에서 데이터를 가져옵니다.
   if(!SymbolInfoSessionQuote(symbolday_of_weeksession_indexdate_fromdate_to)) 
     { 
      int err=GetLastError();
      string message=(err==4307 ? StringFormat("- %-10s Session not set"week_day) : 
                      StringFormat("SymbolInfoSessionQuote(%s, %s, session %d) failed. Error %d"symbolweek_daysession_indexGetLastError()));
      Print(message); 
      return
     } 
      
//--- 지정된 쿼트 세션에 대한 데이터를 저널로 보냅니다.
   PrintFormat("- %-10s %s - %s"week_dayTimeToString(date_fromTIME_MINUTES), TimeToString(date_toTIME_MINUTES)); 
  }

 

추가 참조

SymbolInfoSessionQuote, Symbol info, TimeToStruct, Date structure