• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple strategy not working when using SetStopLoss

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Simple strategy not working when using SetStopLoss

    While debugging my automated strategy, I have stumbled upon a bug of some kind. For this reason, I have created an additional very simple strategy (attached Simplified.cs), with hard-coded test entries and exits, which attempts to identify where the problem might be located.

    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!
    Attached Files

    #2
    Hello MarianApalaghiei,

    The behavior occurs when using multiple exit orders for a single entry order in the Managed approach causing in-flight-executions.

    The managed approach

    If you are using the Strategy Builder, do not use Stops and Targets when using Exit methods. Use Exit methods only if you use them at all.

    Below is a link to an example.
    https://ninjatrader.com/support/foru...596#post806596

    If the strategy is unlocked, do not use Set methods. Instead use ExitLongLimit/ExitLongStopMarket/ExitShortLimit/ExitShortStopMarket as the protective orders, cancel the orders first, wait until they are cancelled in OnOrderUpdate.

    Below are links to a few examples.
    https://ninjatrader.com/support/help...and_onexec.htm
    https://ninjatrader.com/support/foru...269#post802269

    Alternatively, you could switch to the Unmanaged approach and completely control the orders how you would like.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Newtrader101, Today, 04:50 AM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by utilizator, Today, 06:31 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by digibob, Today, 01:13 AM
    3 responses
    13 views
    0 likes
    Last Post digibob
    by digibob
     
    Started by calebsandfort, Yesterday, 05:16 PM
    2 responses
    9 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by StevenNelson, Yesterday, 05:45 PM
    3 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jermaine  
    Working...
    X