I have the following Defaults:
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 3;
EntryHandling = EntryHandling.AllEntries;
In `OnBarUpdate` I have something like:
EnterLong(NumberOfContracts, entrySignal);
if (NumberOfRunners > 0)
{
EnterLong(NumberOfRunners, runnerSignal);
}
In `OnOrderUpdate` I have:
if (order.Name.StartsWith(pioneerPrefix))
{
entryOrder = order;
}
else if (order.Name.StartsWith(runnerPrefix))
{
runnerOrder = order;
}
In `OnExecutionUpdate`:
// Update our exit order quantities once orderstate turns to filled and we have seen execution quantities match order quantities
else if (order.OrderState == OrderState.Filled && sumFilled == order.Filled)
{
// Stop-Loss order for OrderState.Filled
stoploss = order.IsLong ? Low[LowestBar(Lows[0], 5)] : High[HighestBar(Highs[0], 5)];
stopOrder = exitOrderStopMarket(order.Filled, stoploss, stopLossSignalName + order.Name, order.Name);
if (order == entryOrder) // this is the pioneer order
{
targetOrder = exitOrderLimit(Math.Min(order.Filled, NumberOfContracts), (upperSeries[0] + lowerSeries[0]) / 2, targetSignalName + order.Name, order.Name);
}
}
Scenario
Here is the behavior (assume 5-min bars):
1. both orders are filled successfully, let's say, 2 contracts for pioneer, and 1 contract for the runner.
2. pioneer target is filled, the 2 stop loss orders for pioneer are canceled successfully.
3. the runner order and runner stop loss order is still open.
4. on the next bar, after about 5-mins, the runner stop loss is canceled and the runner order is left open (without the stop loss).
It seems after the pioneer target is filled and the pioneer stop loss orders are canceled, on the next bar the runner stop loss is also canceled, it's not canceled immediately, but, for some reason, it mysteriously cancels on the next bar open, in this case, around 5-mins.
Here is the stack trace, see the call to `DoCancel` from `OnBarUpdate`.
NinjaTrader.Core.dll!NinjaTrader.NinjaScript.Strat egyBase.Process(object sender, NinjaTrader.Cbi.OrderEventArgs orderUpdate)
NinjaTrader.Core.dll!NinjaTrader.Cbi.Account.Raise OrderUpdate(NinjaTrader.Cbi.OrderEventArgs e)
NinjaTrader.Core.dll!NinjaTrader.Cbi.Account.Order UpdateCallback(NinjaTrader.Cbi.Order order, string orderId, double limitPrice, double stopPrice, int quantity, double averageFillPrice, int filled, NinjaTrader.Cbi.OrderState orderState, System.DateTime time, NinjaTrader.Cbi.ErrorCode error, string comment, System.DateTime statementDate)
NinjaTrader.Core.dll!NinjaTrader.Cbi.Account.Cance l(System.Collections.Generic.IEnumerable<NinjaT rad er.Cbi.Order> orders)
NinjaTrader.Core.dll!NinjaTrader.NinjaScript.Strat egyBase.DoOrder(NinjaTrader.Cbi.Order order, NinjaTrader.Cbi.OrderState[] orderStates)
NinjaTrader.Core.dll!NinjaTrader.NinjaScript.Strat egyBase.DoCancel(NinjaTrader.Cbi.Order order)
NinjaTrader.Core.dll!NinjaTrader.NinjaScript.Strat egyBase.OnOnBarUpdate(bool[] toProcess)
NinjaTrader.Core.dll!NinjaTrader.NinjaScript.Ninja ScriptBase.Update(int idx, int bip)
NinjaTrader.Core.dll!NinjaTrader.NinjaScript.Ninja ScriptBase.SubscribeBarsUpdate.__BarsUpdate|1(obje ct _, NinjaTrader.Data.BarsUpdateEventArgs o)
NinjaTrader.Core.dll!NinjaTrader.Data.BarsSeries.A dd(NinjaTrader.Data.Bars bars, double open, double high, double low, double close, System.DateTime time, long volume, double tickSize, bool isBar, double bid, double ask)
NinjaTrader.Core.dll!NinjaTrader.Data.BarsSeries.A ddMarketData(NinjaTrader.Data.Bars bars, double open, double high, double low, double close, System.DateTime time, long volume, double bid, double ask, long tickId, bool isDailyFakeBar)
NinjaTrader.Core.dll!NinjaTrader.Data.BarsSeries.O nMarketData(NinjaTrader.Data.MarketDataEventArgs obj)
NinjaTrader.Core.dll!NinjaTrader.Data.MarketDataEv entWrapper.OnMarketData(object sender, NinjaTrader.Data.MarketDataEventArgs e)
NinjaTrader.Core.dll!NinjaTrader.Cbi.Instrument.On RealtimeDataTimerElapsed.__Action|1(NinjaTrader.Cb i.Instrument.SubscribedThread[] threads, int i, NinjaTrader.Cbi.Instrument.RealtimeEvents evts)
See attached Log of the above Scenario.
Question:
Why is the stop loss being canceled on the next bar after the target is filled and no action is happening in the strategy and how can I keep the stop loss around?
Thanks so much for any help with this.

Comment