How to obtain session index(for SymbolInfoSessionTrade)

 

Hi. I trying to find out how to obtain the session index of the current trade day. for the function:

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
   );

Improperly formatted code edited by moderator.

I cannot find this info anywhere. I presume I can simply use 0 but some brokers have early closes to sessions for specific symbols on specific days so this is less than ideal.

 

You may find a solution in this code: 

https://www.mql5.com/en/forum/373227#comment_26436497

In my experience most brokers do not offer reliable data for those fields. Usually you won't get what you want even if you code it.

How to check 'Market is closed' befor opening a position? - My expert advisor is trying to open a position immediately at time 00.00, because the market is closed during Friday night and
How to check 'Market is closed' befor opening a position? - My expert advisor is trying to open a position immediately at time 00.00, because the market is closed during Friday night and
  • 2021.07.13
  • www.mql5.com
My expert advisor is trying to open a position immediately at time 00:00. I get 'market is closed' ( trade_retcode_market_closed , error code: 10018) message, because the trading is start only at time 00:01: how can i check in advance if it is possible to open a position
 

Please always use the CODE button (Alt-S) when inserting code.

Code button in editor

 
79017673: Hi. I trying to find out how to obtain the session index of the current trade day. for the function:I cannot find this info anywhere. I presume I can simply use 0 but some brokers have early closes to sessions for specific symbols on specific days so this is less than ideal.

You start with the session index "0", and then increment the index, and repeat the process until the function returns "false".

By then you will have collected the data for each session and established how many sessions there are in total for that day of the week.

It is uncommon, but different days can theoretically have a different number of sessions.

Reason: