I tried adding some code which saves the value of CurrentBar when the order is place, then checks to see if the order is still working and compares it to a value for how many bars I'd like the order to last. The problem is, it doesn't work. When the offending code is live, every order is cancelled as soon as it is placed. My preference is to have two checks: bars past order placement, and if price moves too far away from my entry price, (past the two profit targets in the ATM for instance). Here is the code, any idea why it should execute immediately instead of waiting for the current bar value to exceed the order current bar value plus my offset? Also, how can I add that price check as an alternative test.
Thanks for your help.
DaveN
The code below shows the order entry where I set the barcode value, then the order status test where I compare and cancel if there are too many bars past entry.
&& orderId.Length == 0 && atmStrategyId.Length == 0) { Print(counter + " " + " Executing RC_ATM_Sell"); atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(OrderAction.Sell, OrderType.Limit, Close[0] + Offset * TickSize, 0, TimeInForce.Day, orderId, "RC_ATM", atmStrategyId); barcount.Set(CurrentBars[0]); } #endregion #region Order Fill Status and Adjustment if (orderId.Length > 0) { string[] status = GetAtmStrategyEntryOrderStatus(orderId); if (status[2] == "Working" && (CurrentBars[0] > Bars_Past_OE + barcount[0])) { Print(counter + " cancelling order because CurrentBars > Bars_Past_OE + Barcount"); Print(counter + CurrentBars[0] + " " + barcount[0]); AtmStrategyCancelEntryOrder(orderId); } } #endregion
Comment