The strategy has been tested on ES 09-19, on a few 5-minute candles from January 25, 2006, as it can be seen in the chart screenshots.
The code is very simple:
- Sets a stop loss value of 200, once, at the beginning, when the data is loaded.
- Enter long with a LIMIT order, at 1194.25, at the close of the 10:10:00 candle;
- Exit the long position at MARKET, at the close of the 10:20:00 candle, which happens to be 1194.25 (I used a Slippage value of 1 tick, for market orders);
- Enter long with a LIMIT order, at 1190.50, at the close of the 10:25:00 candle;
- Exit the long position at MARKET, at the close of the 10:50:00 candle.
The first EnterLongLimit and ExitLong ("Fixed bar exit") pair works correctly.
When the long exit ("Fixed bar exit") order is filled, the associated "Stop loss" order is cancelled. Apparently, this creates problems, as the "Output - NOT Working - with SetStopLoss.txt" file shows. The second EnterLongLimit submits the long entry order, but it does not reach the Filled state, even though the candle closing at 10:30:00 clearly punches through the 1190.50 limit price. Also, no associated "Stop loss" order is submitted for it. The position remains Flat. It looks like an internal deadlock. No "Ignored order..." message appears in the output window.
My guess is that the problem is generated when the "Stop loss" order associated to the prior position is cancelled (10:20:00) immediately before we attempt to EnterLongLimit (10:25:00).
The strategy fills orders correctly when the SetStopLoss call is removed. Please see the attached output files and screenshots.
Also, the strategy fills orders correctly when the Order Fill Resolution is set to High (1 minute, for example), even when SetStopLoss is used.
I did not find my specific situation in any of the cases mentioned here: https://ninjatrader.com/support/help...antedPositions
Could someone help with an explanation?
Thanks in advance!
Comment