ATM. Sample Stop&Profit
Пример базовой стратегии выставления стоп лосс и тейк профита.
При каждом изменении текущей позиции стратегия отменяет предыдущие ордера и выставляет новые на расстоянии 20 тиков от цены позиции.
public class SampleStopProfit : ATMStrategy { protected override void OnActivated() { Process(); } protected override void OnCurrentPositionChanged() { Process(); } private void Process() { if (!IsActivated) return; CancelAllOrders(); if (CurrentPosition == 0) return; var take = new Order { Security = Security, Portfolio = Portfolio, Type = OrderTypes.Limit, Direction = CurrentPosition > 0 ? OrderDirections.Sell : OrderDirections.Buy, Price = AveragePrice + 20 * Security.TickSize * (CurrentPosition > 0 ? 1 : -1), QuantityToFill = Math.Abs(CurrentPosition), Comment = "TP", }; OpenOrder(take); var stop = new Order { Security = Security, Portfolio = Portfolio, Type = OrderTypes.Stop, Direction = CurrentPosition > 0 ? OrderDirections.Sell : OrderDirections.Buy, TriggerPrice = AveragePrice - 20 * Security.TickSize * (CurrentPosition > 0 ? 1 : -1), QuantityToFill = Math.Abs(CurrentPosition), Comment = "TP", }; OpenOrder(stop); } private void CancelAllOrders() { foreach (var order in Orders.Where(t=>t.State==OrderStates.Active)) { CancelOrder(order); } } }
Сервис поддержки клиентов работает на платформе UserEcho