if (State == State.SetDefaults)
{
EntriesPerDirection = 2;
EntryHandling = EntryHandling.UniqueEntries;
TraceOrders = true;
}
I have also assigned seperate Order variables (myEntryOrder and mySecondEntryOrder) to each of my positions and given them a different name (Order1 and Order2) as can be seen in the code below:
if (_AllParametersTrue == true && myEntryOrder == null)
{
EnterShortStopMarket(0, true, _Quantity, EntryPrice, "Order1");
SetStopLoss("Order1", CalculationMode.Price, (High[0] + 2 * ATR(14)[0]), false);
}
if (_AllParametersTrue == true && mySecondEntryOrder == null)
{
EnterShortStopMarket(0, true, _Quantity, EntryPrice, "Order2");
SetStopLoss("Order2", CalculationMode.Price, (High[0] + 2 * ATR(14)[0]), false);
SetProfitTarget("Order2", CalculationMode.Price, Target, false);
}
After countless hours spent trying to debug this issue I have had no success. I continue to get the message: Cancelled pending exit order, since associated position is closed
This message appears in the output when the stop loss of my first entry order is hit, NinjaTrader then automatically closes my other position.
I have a theory as to why this is happening but I am not certain that I am correct.
I included trace orders in the first method to identify what is going wrong. Everything works fine initially - Once the short stop market orders are filled the profit targets and initial stop losses are set correctly, a quantity of 1 is assigned to each of the stops/targets in the order menu of the control centre (which is the default quantity that the variable _Quantity in the methods above represent). BUT as soon as the candle in which I entered the trade closes, the quantity for each of the stops/targets changes to 2 (which is the total quantity of order 1 and order 2 combined). When this happens I get these messages in the output window:
8/02/2022 7:50:01 PM Strategy 'StrategyDebugging'/255187316': Amended stop order orderId='d879393074da4222b8716f2d97fe2091' account='Playback101' name='Stop loss' orderState=Accepted instrument='EURUSD' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=1.14354 quantity=1 tif=Gtc oco='7053db5918d44d0092a99165690c5ded' filled=0 averageFillPrice=0 onBehalfOf='' id=123 time='2022-02-08 19:42:35' gtd='2099-12-01' statementDate='2022-02-08' stopPriceChanged=1.14354
8/02/2022 7:50:01 PM Strategy 'StrategyDebugging'/255187316': Amended target order orderId='eb6e0561a9e2413e87d3c83c95554626' account='Playback101' name='Profit target' orderState=Working instrument='EURUSD' orderAction=BuyToCover orderType='Limit' limitPrice=1.14006 stopPrice=0 quantity=1 tif=Gtc oco='5b078cb127bd4793a5699aa327d79b9a' filled=0 averageFillPrice=0 onBehalfOf='' id=125 time='2022-02-08 19:42:35' gtd='2099-12-01' statementDate='2022-02-08' limitPriceChanged=1.14006
8/02/2022 7:50:01 PM Strategy 'StrategyDebugging'/255187316': Amended stop order orderId='504fdbfb1dfc489ca649a5cbf3c976cc' account='Playback101' name='Stop loss' orderState=Accepted instrument='EURUSD' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=1.14354 quantity=1 tif=Gtc oco='5b078cb127bd4793a5699aa327d79b9a' filled=0 averageFillPrice=0 onBehalfOf='' id=124 time='2022-02-08 19:42:35' gtd='2099-12-01' statementDate='2022-02-08' stopPriceChanged=1.14354
My theory is that because the order quantity change from 1 to 2, as soon as the first stop loss is hit, all of the positions are closed.
I am unsure why this happens and have gotten nowhere from my efforts in trying to debug this issue.
Comment