public override bool ModifyOrderToFill(IBrokerage brokerage, Order order, decimal lastMarketPrice) { // limit orders will process even if they go beyond the market price var symbolProperties = SPDB.GetSymbolProperties(order.Symbol.ID.Market, order.Symbol, order.SecurityType, order.PriceCurrency); var roundOffPlaces = GetDecimalPlaces(symbolProperties.MinimumPriceVariation); var limit = (LimitOrder)order; if (order.Quantity > 0) { // for limit buys we need to increase the limit price limit.LimitPrice = Math.Round(lastMarketPrice * 1.02m, roundOffPlaces); } else { // for limit sells we need to decrease the limit price limit.LimitPrice = Math.Round(lastMarketPrice / 1.02m, roundOffPlaces); } return(true); }
public override bool ModifyOrderToFill(IBrokerage brokerage, Order order, decimal lastMarketPrice) { var symbolProperties = SPDB.GetSymbolProperties(order.Symbol.ID.Market, order.Symbol, order.SecurityType, order.PriceCurrency); var roundOffPlaces = GetDecimalPlaces(symbolProperties.MinimumPriceVariation); var stop = (StopLimitOrder)order; var previousStop = stop.StopPrice; if (order.Quantity > 0) { // for stop buys we need to decrease the stop price stop.StopPrice = Math.Min(stop.StopPrice, Math.Max(stop.StopPrice / 2, Math.Round(lastMarketPrice, roundOffPlaces, MidpointRounding.AwayFromZero))); } else { // for stop sells we need to increase the stop price stop.StopPrice = Math.Max(stop.StopPrice, Math.Min(stop.StopPrice * 2, Math.Round(lastMarketPrice, roundOffPlaces, MidpointRounding.AwayFromZero))); } stop.LimitPrice = stop.StopPrice; return(stop.StopPrice != previousStop); }