I am trying to cancel an unfilled entry order after 1 bar. Here is how I am trying to accomplish this (I'll spare you the if() conditions):
if()
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Limit, Close[0] + -.1, 0, TimeInForce.Day, orderId, "133t Trail", atmStrategyId);
DrawArrowUp("ZLR Long", 0, Low[0] - TickSize, Color.Lime);
Print("The order triggered atmStrategyId# is: " + (atmStrategyId));
Print("The order triggered orderId# is: " + (orderId));
}
// Cancel if order is not filled after close of entry bar
if (atmStrategyId.Length > 0
&& GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
{
AtmStrategyCancelEntryOrder("atmStrategyId");
Print("Cancelling Unfilled ATM Entry #"+(atmStrategyId));
}
Here what the output window gives when an order didn't get filled:
The order triggered atmStrategyId# is: d9e0f3914a974925974d28122e98f3a2
The order triggered orderId# is: f23e4f7d1db64725989917b63131ff74
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: Initialized
Cancelling Unfilled ATM Entry #d9e0f3914a974925974d28122e98f3a2
The current ATM Strategy market position is: Flat
The current ATM Strategy position quantity is: 0
The current ATM Strategy average price is: 0
The current ATM Strategy Unrealized PnL is: 0
The current ATM Strategy ID# is: d9e0f3914a974925974d28122e98f3a2
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: Working
Cancelling Unfilled ATM Entry #d9e0f3914a974925974d28122e98f3a2
The current ATM Strategy market position is: Flat
The current ATM Strategy position quantity is: 0
The current ATM Strategy average price is: 0
The current ATM Strategy Unrealized PnL is: 0
The current ATM Strategy ID# is: d9e0f3914a974925974d28122e98f3a2
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: Working
..and on and on as the entry order never gets cancelled and sits there trying to fill. What am I missing? Can someone point me in the right direction?
Thanks.
Comment