Trading Sessions¶
Following the release of cTrader Windows 4.5, the API now includes the MarketSessions
interface. It allows for attaining information about current market sessions and using this data in your cBots/indicators.
Trading Sessions in Algo Development¶
The MarketSession
type is an enum
with values representing various trading sessions (such as Singapore
or London
).
In turn, the MarketSessions
property is of the MarketSession
type. To get all current market sessions, use it as follows.
1 |
|
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 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 NewSessions
and PreviousSessions
, which work as follows.
NewSessions
contains all current sessions including any sessions that have just started. The value ofNewSessions
is always equal to the value of theMarketSessions
property of a cBot/indicator.PreviousSessions
also contains all current sessions but it also contains any past sessions that have just ended. Its value is equal to the value of theMarketSessions
property of a cBot/indicator before theMarketSessionsChanged
was triggered.
For a more detailed look at how NewSessions
and 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.
Trading Sessions During Backtesting¶
The 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.