Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Orders Getting Cancelled after submitted

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

    Orders Getting Cancelled after submitted

    Hi,

    What could be the reason to my order getting cancelled a couple of seconds after being submitted (opened)?

    This is the whole code in the attached file.

    TIA!


    Attached Files

    #2
    Hello carlosgutierrez,

    Which specific orders are being cancelled?

    If you are referring to the profit target and stop loss that would be expected based on your conditions. The conditions need to remain true as long as you want the order to be active, if you dont call those order methods in OnBarUpdate for each event while not filled they would be expired. Your use of the shortpositionmover variable will prevent the orders from being called each OnBarUpdate so they would be expired. If you need to change the price you need to keep calling the order method and just adjust a price variable so on the next time the order is called it is moved.

    Comment


      #3
      Yes, the take profit and stop loss are getting canceled.

      The intention of both, longpositionmover and shortpositionmover, is to be able to move around the orders after the trade is open. What would I need to change to keep those orders?

      Comment


        #4
        Changing the order management did the trick.

        Used this:

        Code:
        if (StopLoss)
                        {
                            ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - (TickSize * Stoploss), "Stop1", "Entry1");
                            ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - (TickSize * Stoploss), "Stop2", "Entry2");
                            ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - (TickSize * Stoploss), "Stop3", "Entry3");
                        }
        
                        if (ProfitTarget)
                        {
                            ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * Target1),  "Target1", "Entry1");
                            ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * Target2),  "Target2", "Entry2");
                            ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * Target3),  "Target3", "Entry3");
                        }
        
                        longpositionmover = false;​

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello carlosgutierrez,

          Which specific orders are being cancelled?

          If you are referring to the profit target and stop loss that would be expected based on your conditions. The conditions need to remain true as long as you want the order to be active, if you dont call those order methods in OnBarUpdate for each event while not filled they would be expired. Your use of the shortpositionmover variable will prevent the orders from being called each OnBarUpdate so they would be expired. If you need to change the price you need to keep calling the order method and just adjust a price variable so on the next time the order is called it is moved.


          Still getting the order cancelation with the updated order management that I attached in the previous post.

          How can I fix the issue that my "shortpositionmover" is causing? That boolean is there so I can move around my orders after being submitted.

          Another alternative could be the ability to use a specific ATM strategy. How can I code the ATM use into my script?

          Comment


            #6
            Hello carlosgutierrez,

            Are you cancelling orders anywhere in your logic? Did you miss one of the orders and have it not set to live until cancelled? Live until cancelled orders do not automatically cancel, they are live until you cancel them or they are filled.

            You can see the SampleATMStrategy that comes with the platform that shows what logic is required to submit atms. That cannot be used in combination with an unmanaged or managed script, the ATM runs outside the strategy and requires special methods to be used.

            Comment


              #7
              Hi, I am revisiting this issue. I had solved it worh the ATM strategy addition. But I cannot use it on Strategy Optimization (if you have a way to test a strategy using an ATM please let le know).
              But I have some other codes getting this same issue and I found that is because the order logic in under UnBarUpdate. Where should I locate the logic for the orders not get a reload every time a new candle forms?


              TIA!

              Comment


                #8
                Hello carlosgutierrez,

                ATM strategies cannot be backtested because those are part of the manual trading framework. A NinjaScript strategy can launch an ATM in realtime but has limited ways of interacting with that outside atm strategy.

                If you are using live until cancelled orders you would generally have your entry logic in OnBarUpdate and then the targets would be submitted from OnExecutionUpdate. You can see a sample of that here: https://ninjatrader.com/support/help...and_onexec.htm

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                54 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                130 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                72 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                44 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X