Chart Strategies. Основы

Functionality of Chart Strategies allows receiving and processing the whole set of data available in indicators and performing trading operations on the basis of these data.

The ChartStrategy class is inherited from the Indicator class. Thus, strategies have the full functionality of indicators.

Помимо функционала индикаторов, в стратегиях имеются дополнительные свойства и методы, отвечающие за торговый функционал:

Properties:

  • Security - trading instrument
  • Portfolio - selected portfolio
  • Connector - trading connection
  • MyTrades - list of trades
  • Orders - list of orders
  • CurrentPosition - volume of the strategy current position
  • AveragePrice - average price of the strategy current position
  • State - strategy state (could be Stopped, Started and Suspended)

Main strategy public methods:

  • OpenOrder - method of opening a new order
  • ModifyOrder - method of modifying an order
  • CancelOrder - method of cancelling an order
  • ShrinkPrice - rounding the transferred price to the trading instrument tick size
  • RaiseShowNotification - method, allowing visualization of notifications in the platform

Strategy virtual methods, which, if necessary, have to be redefined in the created strategy:

  • OnStarted - is called when a strategy is started
  • OnSuspended - is called when a strategy is suspended (for example, in situations when a chart with a strategy has been closed)
  • OnStopping - is called before stopping a strategy
  • OnStopped - is called when a strategy has been stopped
  • OnCurrentPositionChanged - is called when changing the strategy current position
  • CanProcess - returns whether it is possible to trade at this moment. By default, the method checks whether a strategy has been started and the most recent bar is processed at this moment.

Strategy positions.

Every strategy holds its position inside. This position could differ from the general position on the account.

The account general position could be received through the TradingManager.Position property.

The strategy internal position could be received through the CurrentPosition and AveragePrice properties.

Important! When a strategy is stopped, its internal position is reset to zero. It is extremely desirable to redefine the OnStopping method and realize the logic of closing internal positions and cancelling the posted orders in it.