Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Reasons a stop/loss order does not get triggered?

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

    Reasons a stop/loss order does not get triggered?

    We're doing backtesting with our strategy. Using FDAX and Tick Replay. The strategy also use our own indicator which produces a value that's used by strategy to determine when to submit an entry order. Strategy uses Calculate.OnBarClose while indicator uses Calculate.OnEachTick.

    We send orders using SubmitOrderUnmanaged() and implemented trailing stop using chargeOrder().
    Noticed that some of the stop/loss orders don't get triggered.
    Are there rules about when a stop/loss order will get triggered or not?
    Thanks.

    Here's a sample log showing when stop order is changed (using TraceOrders and OnOrderTrace) and current price via OnMarketData.
    Dates below are in GMT+8.

    Stop price gets updated to 11509.5 near 27/05/2020 00:39:23.537000.
    Price goes down to 11509, 11508.5,11508 on 27/05/2020 00:42:30.139000.
    Stop/loss gets triggered later on 27/05/2020 00:47:59.991000.

    Code:
    27/05/2020 00:39:22.439000 marketDataUpdate.Price: 11514.5
    Market position is Long
    Auto Trail Frequency Threshold is 11514.5
    Threshold is reached? YES
    Current Trail Stop is 11509.5
    Changing stop order quantity from 11509 to 11509.5 with price at 11514.5
    27/05/2020 12:39:00 AM Strategy 'BackTesting Strategy/-1': Changed custom managed order: orderId='NT-00478-1224' account='Backtest' name='Stop1/Trade Strategy 6.2.1.3.1.8-a' orderState=Working instrument='FDAX 12-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=11509 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-05-27 00:23:00' gtd='2099-12-01' statementDate='2020-12-03' limitPriceChanged=0 quantityChanged=1 stopPriceChanged=11509.5
    The order name Stop1/Trade Strategy 6.2.1.3.1.8-a stop price is currently 11509.5
    The order name Stop1/Trade Strategy 6.2.1.3.1.8-a stop price is currently 11509.5
    The order name Stop1/Trade Strategy 6.2.1.3.1.8-a stop price is currently 11509.5
    The order name Stop1/Trade Strategy 6.2.1.3.1.8-a stop price is currently 11509.5
    27/05/2020 00:39:23.537000 marketDataUpdate.Price: 11514
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:39:23.552000 marketDataUpdate.Price: 11514.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:39:28.133000 marketDataUpdate.Price: 11514
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:39:30.204000 marketDataUpdate.Price: 11514
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:39:34.063000 marketDataUpdate.Price: 11513.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:39:37.824000 marketDataUpdate.Price: 11514
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:39:48.356000 marketDataUpdate.Price: 11513.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:39:51.523000 marketDataUpdate.Price: 11514.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    [SNIP]
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:16.973000 marketDataUpdate.Price: 11511
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:21.059000 marketDataUpdate.Price: 11512
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:26.531000 marketDataUpdate.Price: 11511.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:28.008000 marketDataUpdate.Price: 11511
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:29.720000 marketDataUpdate.Price: 11511
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.011000 marketDataUpdate.Price: 11510.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.110000 marketDataUpdate.Price: 11510
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.138000 marketDataUpdate.Price: 11509.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.138000 marketDataUpdate.Price: 11509.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.139000 marketDataUpdate.Price: 11509
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.139000 marketDataUpdate.Price: 11508.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.788000 marketDataUpdate.Price: 11508
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.789000 marketDataUpdate.Price: 11508
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.789000 marketDataUpdate.Price: 11508
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:30.791000 marketDataUpdate.Price: 11508.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:31.425000 marketDataUpdate.Price: 11508.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:31.426000 marketDataUpdate.Price: 11509
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:33.353000 marketDataUpdate.Price: 11510
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:42:33.353000 marketDataUpdate.Price: 11510
    Market position is Long
    [SNIP]
    27/05/2020 00:47:40.789000 marketDataUpdate.Price: 11510.5
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:47:50.199000 marketDataUpdate.Price: 11510
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:47:55.539000 marketDataUpdate.Price: 11510
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:47:55.540000 marketDataUpdate.Price: 11510
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:47:55.540000 marketDataUpdate.Price: 11510
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:47:55.540000 marketDataUpdate.Price: 11510
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    27/05/2020 00:47:59.991000 marketDataUpdate.Price: 11508
    Market position is Long
    Auto Trail Frequency Threshold is 11515
    Threshold is reached? NO
    Resetting entryOrder, _InitializingStopsAndTargets, _TotalStopsSubmitted, and _TotalTriggersSubmitted.
    Removing strategy Trade Strategy 6.2.1.3.1.8-a from collection.
    No. of active users of strategy Trade Strategy 6.2.1.3.1.8-a: -1
    Removing entries for Trade Strategy 6.2.1.3.1.8-a
    27/05/2020 00:48:00.001000 marketDataUpdate.Price: 11508
    27/05/2020 00:48:01.268000 marketDataUpdate.Price: 11508.5
    27/05/2020 00:48:02.739000 marketDataUpdate.Price: 11508
    27/05/2020 00:48:06.938000 marketDataUpdate.Price: 11508.5
    27/05/2020 00:48:14.142000 marketDataUpdate.Price: 11508

    Chart cropped shot.
    (1) is latest Stop/Loss order position.
    (2) is what should've triggered stop/loss.
    (3) is what ended up triggering stop/loss.

    Click image for larger version  Name:	2020-05-27-Cropped-Shot.JPG Views:	0 Size:	59.7 KB ID:	1130541
    Last edited by cmarkb; 12-03-2020, 04:45 AM.

    #2
    Unsnipped sample logs showing Price change

    Sample-logs-2020-05-27.txt
    Last edited by cmarkb; 12-03-2020, 02:25 AM.

    Comment


      #3
      Hello cmarkb,

      The first issue is that the Calculate needs to be the same between the host and hosted script.
      https://ninjatrader.com/de/support/f...ngs#post814614
      https://ninjatrader.com/support/foru...24#post1118724
      https://ninjatrader.com/it/support/f...62#post1127162

      Set the Strategy to Calculate.OnEachTick, and trigger all actions when IsFirstTickOfBar is true.


      Second, as a heads up, TickReplay does not provide fill prices for accurate order fills. Orders will still be filled without tick granularity within the larger bar.



      For a live order placed to your broker, contact your broker with the order ID and ask why this order did not fill while it was in a working state.

      In sim real-time or playback, I would recommend opening a 1 tick ask chart and a 1 tick bid chart. Mark the time when the order becomes working, when the price is changed, and when the order is cancelled. For a buy order check every ask tick to see that there is an ask tick that would have filled the order. For a sell order check every bid tick to see there is a bid price that would have filled the order.

      For historical orders, I would recommend enabling TraceOrders and directing this to file, writing the time and value of every bar high and low to file (if no intra-bar granularity is added for accurate order fills, print a 1 tick series values if intra-bar granularity for accurate order fills is added), and writing the order.ToString from OnOrderUpdate() to file.
      https://ninjatrader.com/support/help...ordertrace.htm
      Below is a link to an example.
      https://ninjatrader.com/support/foru...nce#post100192

      Basically, you want to analyze when the order actually becomes working, mark the time of every price change, and when it is cancelled, and check the fill bar price information to verify that a valid price was received to fill the order while the order was in a working state.
      Last edited by NinjaTrader_ChelseaB; 12-03-2020, 08:46 AM.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hi Chelsea,

        Thanks for the reply.
        Have been reading the other posts you've linked which helped big time.
        Will post additional questions here when I'm stuck. Thanks.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kulwinder73, Today, 10:31 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by RookieTrader, Today, 09:37 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by terofs, Yesterday, 04:18 PM
        1 response
        24 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by CommonWhale, Today, 09:55 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Gerik, Today, 09:40 AM
        2 responses
        8 views
        0 likes
        Last Post Gerik
        by Gerik
         
        Working...
        X