protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) { if (execution.Order.Name == ENTER_LONG) { profitTaker = execution.Order.AverageFillPrice + (this.ProfitTicks * TickSize); stopLoss = execution.Order.AverageFillPrice - (this.StopLossTicks * TickSize); } else if (execution.Order.Name == ENTER_SHORT) { profitTaker = execution.Order.AverageFillPrice - (this.ProfitTicks * TickSize); stopLoss = execution.Order.AverageFillPrice + (this.StopLossTicks * TickSize); } //if (execution.Order.Name == ENTER_LONG) //{ //} //else if (execution.Order.Name == ENTER_SHORT) //{ // ExitShortStopMarket(1, stopLoss, EXIT, ENTER_SHORT); //} } }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) { ExitLongLimit(3, true, 1, execution.Order.AverageFillPrice + (ProfitTicks * TickSize), "EXIT", "SMA"); ExitLongStopMarket(3, true, 1, execution.Order.AverageFillPrice - (StopLossTicks * TickSize), "EXIT", "SMA"); } }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) { if (execution.Order.Name == ENTER_LONG) { enterTime = time; ExitLongLimit(2, true, 1, execution.Order.AverageFillPrice + (this.ProfitTicks * TickSize), EXIT, ENTER_LONG); ExitLongStopMarket(2, true, 1, execution.Order.AverageFillPrice - (this.StopLossTicks * TickSize), EXIT, ENTER_LONG); } else if (execution.Order.Name == ENTER_SHORT) { enterTime = time; ExitShortLimit(2, true, 1, execution.Order.AverageFillPrice - (this.ProfitTicks * TickSize), EXIT, ENTER_SHORT); ExitShortStopMarket(2, true, 1, execution.Order.AverageFillPrice + (this.StopLossTicks * TickSize), EXIT, ENTER_SHORT); } else if (TradeSecondTrade) { if (secondTrade) { secondTrade = false; } else if (execution.Order.Name == EXIT) { bool enterLong = (execution.Order.IsLimit && execution.Order.FromEntrySignal == ENTER_LONG); bool enterShort = (execution.Order.IsLimit && execution.Order.FromEntrySignal == ENTER_SHORT); // || (execution.Order.IsStopMarket && execution.Order.FromEntrySignal == ENTER_SHORT) // || (execution.Order.IsStopMarket && execution.Order.FromEntrySignal == ENTER_LONG) if (enterLong) { //secondTrade = true; currentStop = 0; EnterLong(2, 1, ENTER_LONG); } else if (enterShort) { //secondTrade = true; currentStop = 0; EnterShort(2, 1, ENTER_SHORT); } } } } }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) { if (execution.Order.Name == ENTER_LONG) { //ExitLongLimit(execution.Order.AverageFillPrice + (50 * TickSize), EXIT, ENTER_LONG); //ExitLongStopMarket(execution.Order.AverageFillPrice - (40 * TickSize), EXIT, ENTER_LONG); } else if (execution.Order.Name == ENTER_SHORT) { //ExitShortLimit(execution.Order.AverageFillPrice - (50 * TickSize), EXIT, ENTER_SHORT); //ExitShortStopMarket(execution.Order.AverageFillPrice + (40 * TickSize), EXIT, ENTER_LONG); } } }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (PrintDetails) { Print(string.Format("{0} | OEU | execution | {1} | {2}", Times[1][0], time, execution.ToString())); } if (execution.Order.OrderState != OrderState.Filled) { return; } // when the entry order fully fills, place the profit target and stop loss if (entryOrder != null && execution.Order == entryOrder) { ocoString = Guid.NewGuid().ToString(); if (UseProfitTarget) { if (PrintDetails) { Print(string.Format("{0} | OEU | placing profit target", execution.Time)); } // calculate a price for the profit target using the secondary series ticksize currentPtPrice = execution.Order.AverageFillPrice + ProfitTargetDistance * tickSizeSecondary; profitTarget = placeHolderOrder; SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.Limit, execution.Order.Filled, currentPtPrice, 0, ocoString, "profit target"); } if (UseStopLoss) { if (PrintDetails) { Print(string.Format("{0} | OEU | placing stop loss", execution.Time)); } currentSlPrice = execution.Order.AverageFillPrice - StopLossDistance * tickSizeSecondary; stopLoss = placeHolderOrder; SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, currentSlPrice, ocoString, "stop loss"); } } }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) { if (execution.Order.Name == ENTER_LONG) { profitTaker = execution.Order.AverageFillPrice + (this.ProfitTicks * TickSize); double tempStopLoss = execution.Order.AverageFillPrice - (this.StopLossTicks * TickSize); stopLoss = Math.Max(stopLoss, tempStopLoss); } else if (execution.Order.Name == ENTER_SHORT) { profitTaker = execution.Order.AverageFillPrice - (this.ProfitTicks * TickSize); double tempStopLoss = execution.Order.AverageFillPrice + (this.StopLossTicks * TickSize); stopLoss = Math.Min(stopLoss, tempStopLoss); } } }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) { if (execution.Order.Name == ENTER_LONG) { profitTaker = execution.Order.AverageFillPrice + (this.ProfitTicks * TickSize); stopLoss = execution.Order.AverageFillPrice - (this.StopLossTicks * TickSize); } else if (execution.Order.Name == ENTER_SHORT) { profitTaker = execution.Order.AverageFillPrice - (this.ProfitTicks * TickSize); stopLoss = execution.Order.AverageFillPrice + (this.StopLossTicks * TickSize); } else if (TradeSecondTrade) { if (secondTrade) { secondTrade = false; } else if (execution.Order.Name == PROFIT_TAKER) { bool enterLong = execution.Order.FromEntrySignal == ENTER_LONG; bool enterShort = execution.Order.FromEntrySignal == ENTER_SHORT; // || (execution.Order.IsStopMarket && execution.Order.FromEntrySignal == ENTER_SHORT) // || (execution.Order.IsStopMarket && execution.Order.FromEntrySignal == ENTER_LONG) if (enterLong) { //secondTrade = true; EnterLong(2, 1, ENTER_LONG); } else if (enterShort) { //secondTrade = true; EnterShort(2, 1, ENTER_SHORT); } } } } }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { RecordTradeProps(execution); }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (PrintDetails) { Print(string.Format("{0} | OEU | execution | {1} | {2}", Times[1][0], time, execution.ToString())); } if (execution.Order.OrderState != OrderState.Filled) { return; } // when the entry order fills, place the profit target and stop loss if (entryOrder != null && execution.Order == entryOrder) { if (UseProfitTarget) { if (PrintDetails) { Print(string.Format("{0} | OEU | placing profit target", execution.Time)); } // setting initial profit target if (isLongTrade) { // calculate a price for the profit target using the secondary series ticksize // currentPtPrice = execution.Order.AverageFillPrice + ProfitTargetDistance * tickSizeSecondary; currentPtPrice = execution.Order.AverageFillPrice + profiltsTaking * tickSizeSecondary; profitTarget = placeHolderOrder; ExitLongLimit(1, true, entryOrder.Quantity, currentPtPrice, "profit target", "entry"); } else { // calculate a price for the profit target using the secondary series ticksize // currentPtPrice = execution.Order.AverageFillPrice - ProfitTargetDistance * tickSizeSecondary; currentPtPrice = execution.Order.AverageFillPrice - profiltsTaking * tickSizeSecondary; profitTarget = placeHolderOrder; ExitShortLimit(1, true, entryOrder.Quantity, currentPtPrice, "profit target", "entry"); } } if (UseStopLoss) { if (PrintDetails) { Print(string.Format("{0} | OEU | placing stop loss", execution.Time)); } //setting initial stop loss if (isLongTrade) { // currentSlPrice = execution.Order.AverageFillPrice - StopLossDistance * tickSizeSecondary; currentSlPrice = execution.Order.AverageFillPrice - stopLossVal * tickSizeSecondary; stopLoss = placeHolderOrder; ExitLongStopMarket(1, true, entryOrder.Quantity, currentSlPrice, "stop loss", "entry"); } else { // currentSlPrice = execution.Order.AverageFillPrice + StopLossDistance * tickSizeSecondary; currentSlPrice = execution.Order.AverageFillPrice + stopLossVal * tickSizeSecondary; stopLoss = placeHolderOrder; ExitShortStopMarket(1, true, entryOrder.Quantity, currentSlPrice, "stop loss", "entry"); } } } }
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { //if (execution.Order.Name == "entryOrder" && execution.Order.OrderState == OrderState.Filled) // entryOrder = execution.Order; }