• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel Pending

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

    Cancel Pending

    I am using "OnOrderUpdate() and OnExecution() methods" , as in the exemple in strategies samples, to submit protective orders but, sometimes , when conection is lost and take profit order is executed , the stop loss order is not canceled as you can see in the picture. It remain as Cancel Pending.
    How can I solve this ?

    Thanks

    #2
    Hello wagner4691,

    Thank you for the post.

    If you are physically not connected when the order event happens you would not receive it so the OnOrderUpdate/OnExecution would not be called to invoke your scripts logic.

    Are you cancelling the order yourself or was this tied by OCO?

    Was this cancelled on the account but did not reflect that in the platform after reconnecting or was the order still also active on the account?


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      The order should be canceled by strategy "OnOrderUpdate() and OnExecution() methods" , as in the exemple,
      The order still also active on the account
      Last edited by wagner4691; 05-22-2020, 12:30 PM.

      Comment


        #4
        It is only canceled in the account and in the platform when I turn off NT and turn on

        Comment


          #5
          Hello wagner4691,

          Thank you for the additional details.

          Yes in this situation the event would not have been observed for your logic to have cancelled the order when it was filled in realtime due to the disconnect. If the disconnect happened slightly after the fill you may see that the fill was observed to invoke the cancel however if the platform was unable to reach the broker nothing would have actually happened on the account.

          After restarting the platform and re enabling the script it should be able to reprocess this time using historical data and try to manage the position/account at that point which it sounds like that is what happened. If the script does not have a connection it won't be able to manage the orders or do other logic that is based on events as it would be waiting of the connection at that point. To avoid this type of situation would really require avoiding the connection loss, a private server could be used for that purpose to host the platform on a more stable connection if that were a ongoing problem.



          I loo forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Is it possible to change something in strategy to cancel the order ?

            Could I use this in some part of the strategy ?

            if (execution.Order.OrderState == OrderState.CancelPending)

            stopshortp = null;



            This is how I handle the protective orders.
            ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            Shortp
            if (entryshortp != null && entryshortp == execution.Order)
            {
            if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
            {
            sumFilled4 += execution.Quantity;

            if (execution.Order.OrderState == OrderState.PartFilled)
            {
            stopshortp = ExitShortStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + SLOS, "SLV2", @"ShortP");
            targetshort = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice - STP, "TPV2", @"ShortP");
            }

            else if (execution.Order.OrderState == OrderState.Filled && sumFilled4 == execution.Order.Filled)
            {
            stopshortp = ExitShortStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + SLOS, "SLV2", @"ShortP");
            targetshort = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice - STP, "TPV2", @"ShortP");
            }


            if (execution.Order.OrderState != OrderState.PartFilled && sumFilled4 == execution.Order.Filled)
            {
            entryshortp = null;
            sumFilled4 = 0;
            }
            }
            }


            if ((stopshortp != null && stopshortp == execution.Order) || (targetshort != null && targetshort == execution.Order))
            {
            if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
            {
            stopshortp = null;
            targetshort = null;
            }
            }

            Comment


              #7
              Hello wagner4691,

              If the strategy became disabled or if the connection is not present you won't be able to do anything besides manually manage your account at that point. You would need internet to have the platform perform actions based on order events.

              You can try to have the strategy recalculate in case of a reconnect, it sounds like disabling and re enabling the strategy was a potential solution here so recalculation may be an option. You can see the following page which details the connection loss settings, selecting to have the strategy recalculate could potentially work here if the start behavior allows for that. If the connection is physically unable to reconnect, exceeds the max restart attempts or the strategy becomes disabled you would still need to manually manage the account position at that point.
              https://ninjatrader.com/support/help...riptProperties

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                As you can see in the log below , the strategy was not disable . The conection was lost less than 1 minute.

                My question is, when I have a Cancel Pending, how can I cancel using some command in the strategy ?

                Can use something like this ?

                if (execution.Order.OrderState == OrderState.CancelPending)

                stopshortp = null;


                22/05/2020 13:23 Position Instrument='WIN 06-20' Account='52857' Average price=82410 Quantity=0 Market position=Flat Operation=Remove
                22/05/2020 13:23 Execution Execution='72212:13363895:1' Instrument='WIN 06-20' Account='52857' Exchange=Default Price=82745 Quantity=1 Market position=Short Operation=Operation_Add Order='727421650405' Time='5/22/2020 1:23 PM'
                22/05/2020 13:23 Order Order='727421650405/52857' Name='TPC2' New state='Filled' Instrument='WIN 06-20' Action='Sell' Limit price=82745 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=1 Fill price=82745 Error='No error' Native error=''
                22/05/2020 13:13 Position Instrument='WIN 06-20' Account='52857' Average price=82410 Quantity=1 Market position=Long Operation=Update
                22/05/2020 13:13 Default Email - Message sent successfully
                22/05/2020 13:13 Default Email - Message sent successfully
                22/05/2020 13:13 Default Email - Message sent successfully
                22/05/2020 13:13 Default Email - Message sent successfully
                22/05/2020 13:13 Order Order='727421650405/52857' Name='TPC2' New state='Working' Instrument='WIN 06-20' Action='Sell' Limit price=82745 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:13 Order Order='727421650405/52857' Name='TPC2' New state='Accepted' Instrument='WIN 06-20' Action='Sell' Limit price=82745 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:13 Order Order='727417963408/52857' Name='SLV2' New state='Filled' Instrument='WIN 06-20' Action='Buy to cover' Limit price=82880 Stop price=0 Quantity=1 Type='Stop Market' Time in force=DAY Oco='' Filled=1 Fill price=82510 Error='No error' Native error=''
                22/05/2020 13:13 Execution Execution='72212:13024015:2' Instrument='WIN 06-20' Account='52857' Exchange=Default Price=82510 Quantity=1 Market position=Long Operation=Update Order='727417963408' Time='5/22/2020 12:10 PM'
                22/05/2020 13:13 Connection My modalmais: Primary connection=Connected, Price feed=Connected
                22/05/2020 13:13 Order Order='727417963650/52857' Name='TPV2' New state='Cancelled' Instrument='WIN 06-20' Action='Buy to cover' Limit price=81660 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:13 Execution Execution='72212:13267347:2' Instrument='WIN 06-20' Account='52857' Exchange=Default Price=82410 Quantity=1 Market position=Long Operation=Update Order='727421649900' Time='5/22/2020 1:00 PM'
                22/05/2020 13:13 Position Instrument='WIN 06-20' Account='52857' Average price=81995 Quantity=1 Market position=Long Operation=Update
                22/05/2020 13:13 Order Order='727421649900/52857' Name='LongP' New state='Filled' Instrument='WIN 06-20' Action='Buy' Limit price=83015 Stop price=0 Quantity=1 Type='Market' Time in force=DAY Oco='' Filled=1 Fill price=82410 Error='No error' Native error=''
                22/05/2020 13:13 Execution Execution='72212:12563820:1' Instrument='WIN 06-20' Account='52857' Exchange=Default Price=81995 Quantity=1 Market position=Short Operation=Update Order='727417962269' Time='5/22/2020 11:00 AM'
                22/05/2020 13:13 Order Order='727417962269/52857' Name='ShortP' New state='Filled' Instrument='WIN 06-20' Action='Sell short' Limit price=81395 Stop price=0 Quantity=1 Type='Market' Time in force=DAY Oco='' Filled=1 Fill price=81995 Error='No error' Native error=''
                22/05/2020 13:13 Order Order='727421650309/52857' Name='SLC2' New state='Accepted' Instrument='WIN 06-20' Action='Sell' Limit price=81530 Stop price=81900 Quantity=1 Type='Stop Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:13 Order Order='727421650309/52857' Name='SLC2' New state='Working' Instrument='WIN 06-20' Action='Sell' Limit price=81530 Stop price=81900 Quantity=1 Type='Stop Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:12 Default Email - Message sent successfully
                22/05/2020 13:12 Connection My modalmais: Primary connection=Connection lost, Price feed=Connection lost
                22/05/2020 13:00 Default Email - Message sent successfully
                22/05/2020 13:00 Order Order='727421650405/52857' Name='TPC2' New state='Working' Instrument='WIN 06-20' Action='Sell' Limit price=82745 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 Order Order='727421650405/52857' Name='TPC2' New state='Accepted' Instrument='WIN 06-20' Action='Sell' Limit price=82745 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 Order Order='727421650405/52857' Name='TPC2' New state='Submitted' Instrument='WIN 06-20' Action='Sell' Limit price=82745 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 Order Order='727421650309/52857' Name='SLC2' New state='Working' Instrument='WIN 06-20' Action='Sell' Limit price=81530 Stop price=81900 Quantity=1 Type='Stop Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 Order Order='727421650309/52857' Name='SLC2' New state='Submitted' Instrument='WIN 06-20' Action='Sell' Limit price=0 Stop price=81900 Quantity=1 Type='Stop Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 Order Order='727421650309/52857' Name='SLC2' New state='Accepted' Instrument='WIN 06-20' Action='Sell' Limit price=0 Stop price=81900 Quantity=1 Type='Stop Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 Execution Execution='72212:13267347:2' Instrument='WIN 06-20' Account='52857' Exchange=Default Price=82410 Quantity=1 Market position=Long Operation=Operation_Add Order='727421649900' Time='5/22/2020 1:00 PM'
                22/05/2020 13:00 Position Instrument='WIN 06-20' Account='52857' Average price=82410 Quantity=1 Market position=Long Operation=Operation_Add
                22/05/2020 13:00 Order Order='727421649900/52857' Name='LongP' New state='Filled' Instrument='WIN 06-20' Action='Buy' Limit price=83015 Stop price=0 Quantity=1 Type='Market' Time in force=DAY Oco='' Filled=1 Fill price=82410 Error='No error' Native error=''
                22/05/2020 13:00 NinjaScript NinjaScript strategy 'SCALPER/201402763' submitting order
                22/05/2020 13:00 NinjaScript NinjaScript strategy 'SCALPER/201402763' submitting order
                22/05/2020 13:00 Order Order='727421649900/52857' Name='LongP' New state='Working' Instrument='WIN 06-20' Action='Buy' Limit price=83015 Stop price=0 Quantity=1 Type='Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 Order Order='727421649900/52857' Name='LongP' New state='Accepted' Instrument='WIN 06-20' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 Order Order='727421649900/52857' Name='LongP' New state='Submitted' Instrument='WIN 06-20' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                22/05/2020 13:00 NinjaScript NinjaScript strategy 'SCALPER/201402763' submitting order

                Comment


                  #9
                  I understand it will not be triggerd imediately but if I use it in OnBarupdate for exemple, the order will be cancel when I have a new bar?

                  Comment


                    #10
                    Hello wagner4691,

                    If you had a cancel pending order which did not resolve by its self when the connection was back there is nothing further your strategy could do at that point, you would need to disable the strategy and manually manage the account if necessary. At that point you would generally need to restart the platform or connection to clear the pending order and then re synchronize with that has happened on the account. If connection losses are common for your connection you could look into using a virtual private server to host the platform on a more stable connection instead.

                    Please let me know if I may be of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      I understand but , You should have some solution for that. I am using a VPS but sometimes it is a broker problem and NT should be able to handle with that. Sometimes I am not in front of my computer to turn NT off and turn it on to cancel pending orders. Is it possible to solve on the future?

                      Comment


                        #12
                        Sorry for so many questions. Is it possible to check the conecttion before cancel the exit order?
                        Last edited by wagner4691; 05-23-2020, 05:59 AM.

                        Comment


                          #13
                          Hello wagner4691,

                          Really all I could suggest here is not leave the platform completely unsupervised to make sure your PC is working correctly and that you are connected. If that VPS has disconnection problems you may want to try a different VPS. You can also try syncing the PC clock, if the clock is at all out of sync that can cause connection issues.

                          You can use the OnConnectionStatusUpdate override to monitor the connection status from your script however if you get frequent disconnects that is likely something you will need to troubleshoot directly rather that trying to make the script/platform accommodate for that. https://ninjatrader.com/support/help...nnectionstatus

                          Please let me know if I may be of further assistance.

                          JesseNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by atman, Today, 12:37 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post atman
                          by atman
                           
                          Started by random9570, Yesterday, 09:01 PM
                          1 response
                          13 views
                          0 likes
                          Last Post Fulcanelli  
                          Started by natngk, Yesterday, 08:28 PM
                          1 response
                          5 views
                          0 likes
                          Last Post NinjaTrader_Marco  
                          Started by Borsz, 05-27-2020, 10:37 AM
                          2 responses
                          24 views
                          0 likes
                          Last Post aligator  
                          Started by Tagliareni, Yesterday, 08:10 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post Tagliareni  
                          Working...
                          X