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

SetProfitTarget() - isMIT not working

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

    SetProfitTarget() - isMIT not working

    Hi,

    I have a SetProfitTarget() with isMIT = false when first set it in OnStateChange(). In OnBarUpdate(), I later have SetProfitTarget() with isMIT=true. But it does not get me out with a market order. I use playback data with this. You can reproduce the issue on /ES 03-24 on December 20th, 2023 . Have long entry limit order at 2pm, with the limit price at 4821.75. After entered the long position, at 2:10pm, i decided to SetProfitTarget to breakeven at 4821.75 with isMIT=true to get me out at breakeven. 5minute later the high touch 4821.75, but the order never execute as market order. It just sit there. So does isMIT work? Can you please confirm?
    Code:
    SetProfitTarget(entrySignalName, CalculationMode.Price, Position.AveragePrice, true);
    Last edited by affilife; 01-31-2024, 12:55 PM.

    #2
    Hello affilife,

    Thank you for your post.

    Please enable TraceOrders to monitor when orders are submitted, changed, canceled, ignored, or rejected. What I suspect might be happening is your profit target is initially being submitted with isMIT set to false, and then when you call it again later the order type is not able to be changed. For more details on TraceOrders and other debugging tips, please see the following links:



    What are the results if you change isMIT to true when you first call SetProfitTarget() in OnStateChange()? Does this submit the Profit Target order as an MIT and allow for the execution as a market order? I would be glad to take a look at a reduced copy of your strategy. Please export the source code via Control Center > Tools > Export > NinjaScript AddOn. Next, attach the exported strategy in your reply here.

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Here is the trace. It never updated to MIT order type although I explicitly call this code.
      Code:
      SetProfitTarget(entrySignalName, CalculationMode.Price, Position.AveragePrice, true);
      1/31/2024 14:24:58 Order Order='165a6097976d4bc1a5e58dbb2592cb83/Playback101' Name='Profit target' New state='Accepted' Instrument='ES 03-24' Action='Sell' Limit price=4821.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='a5d329739dc8456d9af4f4aa7b618f0e' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:24:58 Order Order='165a6097976d4bc1a5e58dbb2592cb83/Playback101' Name='Profit target' New state='Working' Instrument='ES 03-24' Action='Sell' Limit price=4821.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='a5d329739dc8456d9af4f4aa7b618f0e' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:24:58 Order Order='165a6097976d4bc1a5e58dbb2592cb83/Playback101' Name='Profit target' New state='Change submitted' Instrument='ES 03-24' Action='Sell' Limit price=4821.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='a5d329739dc8456d9af4f4aa7b618f0e' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:10:47 Order Order='165a6097976d4bc1a5e58dbb2592cb83/Playback101' Name='Profit target' New state='Working' Instrument='ES 03-24' Action='Sell' Limit price=4827.5 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='a5d329739dc8456d9af4f4aa7b618f0e' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:10:47 Position Instrument='ES 03-24' Account='Playback101' Average price=4821.75 Quantity=1 Market position=Long Operation=Operation_Add
      1/31/2024 14:10:47 Order Order='165a6097976d4bc1a5e58dbb2592cb83/Playback101' Name='Profit target' New state='Accepted' Instrument='ES 03-24' Action='Sell' Limit price=4827.5 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='a5d329739dc8456d9af4f4aa7b618f0e' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:10:47 Order Order='165a6097976d4bc1a5e58dbb2592cb83/Playback101' Name='Profit target' New state='Submitted' Instrument='ES 03-24' Action='Sell' Limit price=4827.5 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='a5d329739dc8456d9af4f4aa7b618f0e' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:10:47 Order Order='9db684cc6f0a44c6b524291e5fa8e2fa/Playback101' Name='Stop loss' New state='Trigger pending' Instrument='ES 03-24' Action='Sell' Limit price=0 Stop price=4801.75 Quantity=1 Type='Stop Market' Time in force=GTC Oco='a5d329739dc8456d9af4f4aa7b618f0e' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:10:47 Execution Execution='a5d329739dc8456d9af4f4aa7b618f0e' Instrument='ES 03-24' Account='Playback101' Exchange=Default Price=4821.75 Quantity=1 Market position=Long Operation=Operation_Add Order='6f91a4a37b11498b8e2d83ca561e10bd' Time='12/20/2023 13:55'
      1/31/2024 14:10:47 Order Order='6f91a4a37b11498b8e2d83ca561e10bd/Playback101' Name='long_pos_R1' New state='Filled' Instrument='ES 03-24' Action='Buy' Limit price=4821.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=1 Fill price=4821.75 Error='No error' Native error=''
      1/31/2024 14:10:40 Order Order='6f91a4a37b11498b8e2d83ca561e10bd/Playback101' Name='long_pos_R1' New state='Working' Instrument='ES 03-24' Action='Buy' Limit price=4821.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:10:40 Order Order='6f91a4a37b11498b8e2d83ca561e10bd/Playback101' Name='long_pos_R1' New state='Accepted' Instrument='ES 03-24' Action='Buy' Limit price=4821.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
      1/31/2024 14:10:40 Order Order='6f91a4a37b11498b8e2d83ca561e10bd/Playback101' Name='long_pos_R1' New state='Submitted' Instrument='ES 03-24' Action='Buy' Limit price=4821.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''








      Comment


        #4
        If i have isMIT set to true at the beginning, then set it back to false later once the position is opened. That wont work either, it will stay as MIT as I set in the first place. It seems there is a bug in NT8 that never update order type after it sets after the position is opened.
        Last edited by affilife; 01-31-2024, 01:42 PM.

        Comment


          #5
          Originally posted by affilife View Post
          If i have isMIT set to true at the beginning, then set it back to false later once the position is opened. That wont work either, it will stay as MIT as I set in the first place. It seems there is a bug in NT8 that never update order type after it sets after the position is opened.
          It is not expected to be able to modify the order type. I created a simple test script, and it seems that any price changes do go through but changing the order type is not supported. Your original questions were, "So does isMIT work? Can you please confirm?" The answer is that yes, isMIT does work on the initial submission of the Profit Target order, but it does not work and is not supported to modify isMIT on any subsequent calls of SetProfitTarget() in an attempt to change the order type to/from MIT. Calling SetProfitTarget() again after the initial submission of the profit target only modifies the price of the order.

          This is not a bug and is instead an expected behavior; NinjaTrader does not support changing the order type of an active order. This is even noted in the TD Ameritrade connection guide here:Please let us know if we may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment


            #6
            Thanks for letting me know. Is there a workaround for this to work? Do you have any suggestions to make it work? The whole point is to exit at breakeven as quickly as possible while minimizing the loss. And that's a market order in this case

            Comment


              #7
              Originally posted by affilife View Post
              Thanks for letting me know. Is there a workaround for this to work? Do you have any suggestions to make it work? The whole point is to exit at breakeven as quickly as possible while minimizing the loss. And that's a market order in this case
              Hello affilife,

              Thank you for your reply.

              Where do you have your Profit Target set initially, and at what point do you move it to breakeven? In other words, what is the trigger condition to exit at breakeven? Is there a reason you do not start with isMIT set to true when you initially set the profit target so that the order would be a market-if-touched order once you change its price to breakeven? Please provide more details of what you are looking to achieve so I may better understand and assist you.

              I look forward to your reply.
              Emily C.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by burtoninlondon, Today, 12:38 AM
              0 responses
              5 views
              0 likes
              Last Post burtoninlondon  
              Started by AaronKoRn, Yesterday, 09:49 PM
              0 responses
              12 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Yesterday, 08:42 PM
              0 responses
              11 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Yesterday, 07:51 PM
              0 responses
              13 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,982 views
              3 likes
              Last Post jhudas88  
              Working...
              X