ATAS
Loading...
Searching...
No Matches
Strategies

Development of a strategy

The Strategy API allows you to create strategies based on the Indicators API to automate your trading process.

In order to develop a strategy it is necessary to:

  1. Develop a project of a library of classes in Visual Studio.
  2. Add a link to ATAS Strategies.dll, which is in the directory with the installed program, in the project.
  3. Create a strategy class and inherit it from ChartStrategy class.
  4. Realize the logic of the strategy operation.
  5. Compile the library.
  6. Place the resulting dll file into the \Documents\ATAS\Strategies directory.
  7. Click on the blinking button for the changes in the list of strategies to take effect.
Updating strategy list

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.

In addition to the functionality of indicators, strategies have additional properties and methods responsible for trading functionality:

Properties:

Main strategy public methods:

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.

You can find the chart strategy in the list of strategies. For this it is necessary:

  1. open the context menu with the right mouse button,
  2. click on the strategy list icon,
  3. in the opened window of the list of strategies, select the strategy you need,
  4. click the Add button.
  5. you can enable / disable the strategy by pressing the control button.
Loading Chart strategy

Additional order options

When developing a strategy, you can set specific order options using the TradingManager strategy property.

Reduced only

Reduced only orders are a risk control mechanism that ensures that when executed, they will only reduce an existing position, preventing any unintended increase in exposure. This feature is particularly important in markets where precise control over positions is crucial for effective risk management.

private void TrySetReduceOnly(Order order)
{
var flags = TradingManager?
.GetSecurityTradingOptions()?
.CreateExtendedOptions(order.Type);
if (flags is not IOrderOptionReduceOnly ro)
return;
ro.ReduceOnly = true;
order.ExtendedOptions = flags;
}

Post only

When you place a Post only order, you are telling the exchange that you want your order to be treated as a maker order only. In other words, you want to ensure that your order doesn't execute as a taker order, which would result in you paying trading fees. If your Post only order would execute immediately as a taker order, it will be canceled instead.

private void TrySetPostOnly(Order order)
{
var flags = TradingManager?
.GetSecurityTradingOptions()?
.CreateExtendedOptions(order.Type);
if (flags is not IOrderOptionPostOnly po)
return;
po.PostOnly = true;
order.ExtendedOptions = flags;
}

Close on trigger

A Close on trigger order is a type of trading order that is executed when a specified trigger condition is met in the market. It's often used for risk management and to automatically close positions or execute specific actions when a certain price level is reached.

private void TrySetCloseOnTrigger(Order order)
{
var flags = TradingManager?
.GetSecurityTradingOptions()?
.CreateExtendedOptions(order.Type);
if (flags is not IOrderOptionCloseOnTrigger ct)
return;
ct.CloseOnTrigger = true;
order.ExtendedOptions = flags;
}