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

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.

    JesseNinjaTrader Customer Service

    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.

            JesseNinjaTrader Customer Service

            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
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Graci117, Today, 09:02 PM
                0 responses
                2 views
                0 likes
                Last Post Graci117  
                Started by ETFVoyageur, Today, 07:55 PM
                0 responses
                6 views
                0 likes
                Last Post ETFVoyageur  
                Started by janio973, Today, 07:24 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by aligator, 01-06-2022, 12:14 PM
                4 responses
                242 views
                0 likes
                Last Post john_44573  
                Started by reynoldsn, Today, 05:56 PM
                0 responses
                14 views
                0 likes
                Last Post reynoldsn  
                Working...
                X