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

Is this a bug? Stoploss and Profit target cancelled right after trade?

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

    Is this a bug? Stoploss and Profit target cancelled right after trade?

    Working on a strategy and backtesting this week and noticed something strange happening at 5.15.2023 at 2:59 when I place a trade.

    Trade should be opened and a 4 pip stop loss entered. The stop loss order looks fine, but for some reason it gets cancelled right after it's created, if you look at the 'time' value, it's almost like it happens before the trade as the trade happes at 14:59:46, but the order gets placed and cancelled at 14:59:45.

    I tried changing order type from Day to Gtc and also tried disabling the Break at EOD all without success. I think cleared all the cache/db for NinjaTrader thinking it was some bad data, but same thing happens each time.

    Code:
    orderId='NT-00073-184' account='Backtest' name='long' orderState=Submitted instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:46' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00073-184' account='Backtest' name='long' orderState=Accepted instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:46' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00073-184' account='Backtest' name='long' orderState=Working instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:46' gtd='2099-12-01' statementDate='2023-05-20'
    
    Trade: orderId='NT-00073-184' account='Backtest' name='long' orderState=Working instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:46' gtd='2099-12-01' statementDate='2023-05-20'
    
    orderId='NT-00074-184' account='Backtest' name='Stop loss' orderState=Submitted instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4148 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00074-184' account='Backtest' name='Stop loss' orderState=Accepted instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4148 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00074-184' account='Backtest' name='Stop loss' orderState=Working instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4148 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00075-184' account='Backtest' name='Profit target' orderState=Submitted instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169 stopPrice=0 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00075-184' account='Backtest' name='Profit target' orderState=Accepted instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169 stopPrice=0 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00075-184' account='Backtest' name='Profit target' orderState=Working instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169 stopPrice=0 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00073-184' account='Backtest' name='long' orderState=Filled instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=1 averageFillPrice=4149 onBehalfOf='' id=-1 time='2023-05-15 14:59:46' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00074-184' account='Backtest' name='Stop loss' orderState=CancelPending instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4148 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00074-184' account='Backtest' name='Stop loss' orderState=CancelSubmitted instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4148 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00074-184' account='Backtest' name='Stop loss' orderState=Cancelled instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4148 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00075-184' account='Backtest' name='Profit target' orderState=CancelPending instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169 stopPrice=0 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00075-184' account='Backtest' name='Profit target' orderState=CancelSubmitted instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169 stopPrice=0 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00075-184' account='Backtest' name='Profit target' orderState=Cancelled instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169 stopPrice=0 quantity=1 tif=Day oco='NT-00044-184' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 14:59:45' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00076-184' account='Backtest' name='Exit on session close' orderState=Submitted instrument='ES 06-23' orderAction=Sell orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-16 15:59:59' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00076-184' account='Backtest' name='Exit on session close' orderState=Accepted instrument='ES 06-23' orderAction=Sell orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-16 15:59:59' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00076-184' account='Backtest' name='Exit on session close' orderState=Working instrument='ES 06-23' orderAction=Sell orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-16 15:59:59' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00076-184' account='Backtest' name='Exit on session close' orderState=Filled instrument='ES 06-23' orderAction=Sell orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=4127.5 onBehalfOf='' id=-1 time='2023-05-16 15:59:59' gtd='2099-12-01' statementDate='2023-05-20'
    
    
    ​

    #2
    Nope, still not working correctly... Now it's simply doing it at a different time of the day. Realized the oco value on these was just a group id and if it referenced a previous trade it wasn't really a link to that trade.

    The script base time series is 1500 ticks, but a do have a single tick additional series added as well (to help backtesting) and the others do get triggered on that series, maybe that's causing the problem?

    I also trade disabling SetProfitTarget entirely, and right after the trade is enter, the Stop Loss order is cancelled.

    Code:
    orderId='NT-00000-1995' account='Backtest' name='long' orderState=Submitted instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:36:48' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00000-1995' account='Backtest' name='long' orderState=Accepted instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:36:48' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00000-1995' account='Backtest' name='long' orderState=Working instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:36:48' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00001-1995' account='Backtest' name='Stop loss' orderState=Submitted instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4152.25 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00001-1995' account='Backtest' name='Stop loss' orderState=Accepted instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4152.25 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00001-1995' account='Backtest' name='Stop loss' orderState=Working instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4152.25 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00002-1995' account='Backtest' name='Profit target' orderState=Submitted instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169.75 stopPrice=0 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00002-1995' account='Backtest' name='Profit target' orderState=Accepted instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169.75 stopPrice=0 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00002-1995' account='Backtest' name='Profit target' orderState=Working instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169.75 stopPrice=0 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00000-1995' account='Backtest' name='long' orderState=Filled instrument='ES 06-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=1 averageFillPrice=4154.75 onBehalfOf='' id=-1 time='2023-05-15 06:36:48' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00002-1995' account='Backtest' name='Profit target' orderState=CancelPending instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169.75 stopPrice=0 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00002-1995' account='Backtest' name='Profit target' orderState=CancelSubmitted instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169.75 stopPrice=0 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00002-1995' account='Backtest' name='Profit target' orderState=Cancelled instrument='ES 06-23' orderAction=Sell orderType='Limit' limitPrice=4169.75 stopPrice=0 quantity=1 tif=Day oco='NT-00000-1995' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'
    orderId='NT-00001-1995' account='Backtest' name='Stop loss' orderState=Filled instrument='ES 06-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4152.25 quantity=1 tif=Day oco='NT-00000-1995' filled=1 averageFillPrice=4151.75 onBehalfOf='' id=-1 time='2023-05-15 06:35:16' gtd='2099-12-01' statementDate='2023-05-20'​

    Comment


      #3
      Is your strategy using "exit on close"? Not sure what time zone you are in but with a 1500 tick bar it might span the session boundary at some point in the afternoon.

      https://ninjatrader.com/support/help...sestrategy.htm
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Or, is this the moment it transitions from historical to realtime? If it is, depending on your settings, it might be abandoning the historical position and orders to wait for a new realtime one.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          If you are using a 1-tick series as you say to help with backtesting, what happens if instead of SetProfitTarget and SetStopLoss you use ExitLongLimit and ExitLongStop and use the overload that lets you specify the 1-tick series as the bar series to trade? Remember to repeat these orders each time or they will be canceled.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            Hi Bruce, I played with the GTC and exit on end of session indicators and neither of them changed anything. I'm in CST and it's currently doing the same thing on a trade on 5.15 from 1:50pm and it's going all the way until 5.17. It's also not on the transition from historical to real-time.

            I'm trying to place my own stop loss order now, will let you know if it changes things, but that doesn't change the fact I've uncovered something that does not make sense.

            Comment


              #7
              Hello brad79,

              Thanks for your notes.

              Backtesting in the Strategy Analyzer uses only historical data and processes logic OnBarClose. No realtime data is used when backtesting in the Strategy Analyzer so you will not see the script transition from historical to real-time.

              I understand that you have added a 1-tick data series to the script. Are you submitting orders to that added data series?

              What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 7.0.?.? or 8.0.?.?)​

              Please attach a reduced exported copy of the strategy that reproduces the behavior you are reporting and the exact steps and settings you are using to reproduce the behavior so I may test it on my end.

              Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed.

              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Haiasi, 04-25-2024, 06:53 PM
              2 responses
              17 views
              0 likes
              Last Post Massinisa  
              Started by Creamers, Today, 05:32 AM
              0 responses
              5 views
              0 likes
              Last Post Creamers  
              Started by Segwin, 05-07-2018, 02:15 PM
              12 responses
              1,786 views
              0 likes
              Last Post Leafcutter  
              Started by poplagelu, Today, 05:00 AM
              0 responses
              3 views
              0 likes
              Last Post poplagelu  
              Started by fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,408 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Working...
              X