Ii ahve seen examples such as trailstopbuilderexample and others but they all have their trailing stop defined differently. Below is how my order gets manged and i was looking to add trailing stop option...
#region OnOrderUpdate protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { if (orderState == OrderState.Filled && order.Name == "BT") { double ask = GetCurrentAsk(); double bid = GetCurrentBid(); string oco = Guid.NewGuid().ToString(); if (order.IsLong) { double tp = Instrument.MasterInstrument.RoundToTickSize(averageFillPrice + ProfitTarget * TickSize); if (ProfitTarget > 0 && tp.ApproxCompare(ask) > 0) { targetOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, filled, tp, 0, oco, "PT"); } double sl = Instrument.MasterInstrument.RoundToTickSize(averageFillPrice - StopLoss * TickSize); if (StopLoss > 0 && sl.ApproxCompare(bid) < 0) { stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, filled, 0, sl, oco, "SL"); } } if (order.IsShort) { double tp = Instrument.MasterInstrument.RoundToTickSize(averageFillPrice - ProfitTarget * TickSize); if (ProfitTarget > 0 && tp.ApproxCompare(bid) < 0) { targetOrder = SubmitOrderUnmanaged(0, OrderAction.BuyToCover, OrderType.Limit, filled, tp, 0, oco, "PT"); } double sl = Instrument.MasterInstrument.RoundToTickSize(averageFillPrice + StopLoss * TickSize); if (StopLoss > 0 && sl.ApproxCompare(ask) > 0) { stopOrder = SubmitOrderUnmanaged(0, OrderAction.BuyToCover, OrderType.StopMarket, filled, 0, sl, oco, "SL"); } } } } #endregion
Comment