What Are Trading Sessions¶
Following the release of cTrader desktop 4.5, the Automate API now includes the
MarketSessions property. It allows for attaining information about current market sessions and using this data in your cBots/indicators.
How to Use Trading Sessions in Algo Development¶
MarketSession type is an
enum with fields representing various trading sessions (such as
In turn, the
MarketSessions property is of the
MarketSession type. To get all current market sessions, use it as follows.
The value of the
MarketSessions property should match the sessions that are displayed in the 'Trading sessions' field in the lower-left corner of the cTrader desktop UI.
You can use the
HasFlag method to check whether the current sessions contain a specific session.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
You can also handle the
MarketSessionsChanged event to detect and react to any changes in market sessions. The
MarketSessionChangedEventArgs class has two properties, namely
PreviousSessions, which work as follows.
NewSessionscontains all current sessions including any sessions that have just started. The value of
NewSessionsis always equal to the value of the
MarketSessionsproperty of a cBot/indicator.
PreviousSessionsalso contains all current sessions but it also contains any past sessions that have just ended. Its value is equal to the value of the
MarketSessionsproperty of a cBot/indicator before the
For a more detailed look at how
PreviousSessions work, refer to the below example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
In the log, you should see two new entries for each session change. These entries will inform you of what the past trading sessions were and what they are now.
How Trading Sessions Work During Backtesting¶
MarketSessions property works on both live and backtesting environments. During backtesting, this property will contain the sessions relative to the chosen backtest timings. In other words, you can use it to access trading sessions that were active during a specific historic trading period.