SymbolInfoSessionTrade

Allows receiving time of beginning and end of the specified trading sessions for a specified symbol and day of week.

bool  SymbolInfoSessionTrade(
   string            name,                // symbol name
   ENUM_DAY_OF_WEEK  day_of_week,         // day of the week
   uint              session_index,       // session index
   datetime&         from,                // session beginning time
   datetime&         to                   // session end time
   );

Parameters

name

[in]  Symbol name.

ENUM_DAY_OF_WEEK

[in]  Day of the week, value of enumeration ENUM_DAY_OF_WEEK.

uint

[in]  Ordinal number of a session, whose beginning and end time we want to receive. Indexing of sessions starts with 0.

from

[out]  Session beginning time in seconds from 00 hours 00 minutes, in the returned value date should be ignored.

to

[out]  Session end time in seconds from 00 hours 00 minutes, in the returned value date should be ignored.

Return value

If data for the specified session, symbol and day of the week are received, returns true, otherwise returns false.

Example:

#define SYMBOL_NAME   Symbol()
#define SESSION_INDEX 0
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- print the header with a symbol and SESSION_INDEX and
//--- in a loop by day of the week from Mon to Fri, print the start and end times of the trading session in the journal
   PrintFormat("Symbol %s, Trade session %d:"SYMBOL_NAMESESSION_INDEX);
   for(int i=MONDAYi<SATURDAYi++)
      SymbolInfoSessionTradePrint(SYMBOL_NAME, (ENUM_DAY_OF_WEEK)iSESSION_INDEX);
   /*
   result:
   Symbol GBPUSDTrade session 0:
   - 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
   */
  }
//+------------------------------------------------------------------+
//| Send the start and end times of the specified trade session      |
//| for the specified symbol and day of the week to the journal      |
//+------------------------------------------------------------------+
void SymbolInfoSessionTradePrint(const string symbolconst ENUM_DAY_OF_WEEK day_of_weekconst uint session_index)
  {
//--- declare variables to record the beginning and end of the trading session
   datetime date_from;  // session start time
   datetime date_to;    // session end time
   
//--- get data from the trading session by symbol and day of the week
   if(!SymbolInfoSessionTrade(symbolday_of_weeksession_indexdate_fromdate_to))
     {
      Print("SymbolInfoSessionTrade() failed. Error "GetLastError());
      return;
     }
     
//--- create the week day name from the enumeration constant
   string week_day=EnumToString(day_of_week);
   if(week_day.Lower())
      week_day.SetChar(0ushort(week_day.GetChar(0)-32));
 
//--- send data for the specified trading session to the journal
   PrintFormat("- %-10s %s - %s"week_dayTimeToString(date_fromTIME_MINUTES), TimeToString(date_toTIME_MINUTES));
  }

See also

Symbol Properties, TimeToStruct, Data Structures