Here is the clarification;
1. Downloaded 2016.12.01 - 2016.12.31 CL 03-17 market replay data.
2. Connect market replay connection, put the strategy on chart CL 10 tick renko chart.
3. After 2016.12.12 02:05:00 suddenly, i see strategy going long and there is no any stoploss and takeprofit order.
4. Because of that without TP and SL order, position can not be close until the end of the test.
Before talk about strategy, i want to say, i do tests for other instruments and time frames never see any problem. For example ES between 2016.12.01-2017.02.28. After see the problem i put print lines to code. Below there is an order life cycle for long position that close with loss according to output window;
LONG ORDER SENT WITH ID : 216
LONG ORDER FILLED WITH ID : 216
STOP LOSS ORDER SENT WITH ID : 217
TAKE PROFIT ORDER SENT WITH ID : 218
STOP LOSS ORDER FILLED WITH ID : 217
But for problematic order only printing LONG ORDER SENT WITH ID : 244 and even order filled there is no any print neither for order nor SL&TP orders. Also either data or market replay in a bad shape at the day. And suddenly take shape many bars at 1x replay...
Here is some code parts for clarification the strategy;
private Order entryOrder; private Order stopLossOrder; private Order takeProfitOrder; protected override void OnBarUpdate() { if (Position.MarketPosition == MarketPosition.Flat) { if (entryOrder == null) { if (Check Long Condition) { entryOrder = EnterLongLimit(0, true, ?, ?, "Long Entry"); Print("LONG ORDER SENT WITH ID : " + entryOrder.Id); } else if (Check Short Condition) { entryOrder = EnterShortLimit(0, true, ?, ?, "Short Entry"); Print("SHORT ORDER SENT WITH ID : " + entryOrder.Id); } } else { if (Check Cancel Condition) { CancelOrder(entryOrder); } } } } protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment) { if (entryOrder != null && entryOrder == order) { if (entryOrder.OrderState == OrderState.Cancelled || entryOrder.OrderState == OrderState.Rejected) { entryOrder = null; } } } protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if (entryOrder != null && entryOrder == execution.Order) { if (entryOrder.OrderState == OrderState.Filled || entryOrder.OrderState == OrderState.PartFilled || (entryOrder.OrderState == OrderState.Cancelled && entryOrder.Filled > 0)) { if (Position.MarketPosition == MarketPosition.Long) { stopLossOrder = ExitLongStopMarket(0, true, entryOrder.Filled, ?, "Stop Loss", "Long Entry"); takeProfitOrder = ExitLongLimit(0, true, entryOrder.Filled, ?, "Take Profit", "Long Entry"); Print("LONG ORDER FILLED WITH ID : " + entryOrder.Id); Print("STOP LOSS ORDER SENT WITH ID : " + stopLossOrder.Id); Print("TAKE PROFIT ORDER SENT WITH ID : " + takeProfitOrder.Id); } else if (Position.MarketPosition == MarketPosition.Short) { stopLossOrder = ExitShortStopMarket(0, true, entryOrder.Filled, ?, "Stop Loss", "Short Entry"); takeProfitOrder = ExitShortLimit(0, true, entryOrder.Filled, ?, "Take Profit", "Short Entry"); Print("SHORT ORDER FILLED WITH ID : " + entryOrder.Id); Print("STOP LOSS ORDER SENT WITH ID : " + stopLossOrder.Id); Print("TAKE PROFIT ORDER SENT WITH ID : " + takeProfitOrder.Id); } if (entryOrder.OrderState != OrderState.PartFilled) { entryOrder = null; } } } else if (stopLossOrder != null && stopLossOrder == execution.Order) { Print("STOP LOSS ORDER EXECUTED WITH ID : " + stopLossOrder.Id); if (stopLossOrder.OrderState == OrderState.Filled || stopLossOrder.OrderState == OrderState.PartFilled) { Print("STOP LOSS ORDER FILLED WITH ID : " + stopLossOrder.Id); if (stopLossOrder.OrderState != OrderState.PartFilled) { stopLossOrder = null; } } } else if (takeProfitOrder != null && takeProfitOrder == execution.Order) { Print("TAKE PROFIT ORDER EXECUTED WITH ID : " + takeProfitOrder.Id); if (takeProfitOrder.OrderState == OrderState.Filled || takeProfitOrder.OrderState == OrderState.PartFilled) { Print("TAKE PROFIT ORDER FILLED WITH ID : " + takeProfitOrder.Id); if (takeProfitOrder.OrderState != OrderState.PartFilled) { takeProfitOrder = null; } } } }
Thanks,
Aytac
Comment