Thanks Matthew, your last suggestion really helped. I adjusted my exit signals as you suggested and it is working better now. But I do now have a new problem. It appears the section of my code which enters stops and targets after a fill execution isn't working. I had to add a test to see if I had an open position without stops and targets, then I had to add them in. That fixed my immediate problem but now, I have positions open for a bar or two with no stops or targets. I used the code right out of the sample, for onExecution, but I'm wondering if I somehow messed it up by adding my test for whether the execution was a long position or a short position. Here's the code I am using:
protected override void OnExecution(IExecution execution) { /* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate() which ensures your strategy has received the execution which is used for internal signal tracking. */ [COLOR="Red"] if (entryOrder != null && entryOrder == execution.Order && entryOrder.OrderAction == OrderAction.Buy)[/COLOR] { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { // Stop-Loss order 4 ticks below our entry price stopOrder = ExitLongStop(1, true, DefaultQuantity, Position.AvgPrice - ATRTicks(14).Max_ATR[0] * TickSize, "LAbv_Stop", "LAbv_Band"); // Target order 8 ticks above our entry price targetOrder = ExitLongLimit(1, true, DefaultQuantity, Position.AvgPrice + (ATRTicks(14).ATRinTicks[0] - P_Offset) * TickSize, "LAbv_Trgt", "LAbv_Band"); // Resets the entryOrder object to null after the order has been filled or partially filled if (execution.Order.OrderState != OrderState.PartFilled) { entryOrder = null; } } } if(entryOrder != null && entryOrder == execution.Order && entryOrder.OrderAction == OrderAction.SellShort) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0) ) { // Stop-Loss order max ATR above entry price stopOrder = ExitShortStop(1, true, DefaultQuantity, Position.AvgPrice + ATRTicks(14).Max_ATR[0] * TickSize, "SBlo_Stop", "SBlo_Band"); // Target order one ATR below entry price targetOrder = ExitShortLimit(1, true, DefaultQuantity, Position.AvgPrice - (ATRTicks(14).ATRinTicks[0] - P_Offset) * TickSize, "SBlo_Trgt", "SBlo_Band"); // Resets the entryOrder object to null after the order has been filled or partially filled if (execution.Order.OrderState != OrderState.PartFilled) { entryOrder = null; } } } // Reset our stop order and target orders' IOrder objects after our position is closed. if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order)) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled) { stopOrder = null; targetOrder = null; } } }
entryOrder.OrderAction == OrderAction.Buy)
I am using to determine if the executed action was a buy, (later I have the same test for a sell) so I can determine what the stop and target need to be. Is it possible that I have that incorrectly formatted so I'm not getting my stop and target placed on execution? Is there an easy way I can test for that to see if it is working as I expect?
Thanks
DaveN
Comment