ATM. Beispiel für Stop&Profit
Ein Beispiel für eine Stop-Loss- und Take-Profit-Strategie.
Jedes Mal, wenn sich die aktuelle Position ändert, storniert die Handelsstrategie vorherige Aufträge und erstellt neue Aufträge, die 20 Ticks vom Positionswert entfernt sind.
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); } } }
Customer support service by UserEcho