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

OnOrderUpdate and OnExecutionUpdate

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

    OnOrderUpdate and OnExecutionUpdate

    I was wondering for the OnOrderUpdate() and the OnExecutionUpdate, when does it run?

    " The OnOrderUpdate() method is updated whenever the state of an order changes which allows you to submit and control your stop-loss and profit target orders the instant your entry order is filled. The OnExecutionUpdate() method is updated whenever you receive an execution or a fill on your orders. This method provides you the fastest possible submission of protective orders. Utilizing the increased granularity provided in these advanced methods can be advantageous to you by providing you with maximum control of how your stop-loss and profit target orders behave."

    - For the OnOrderUpdate, it runs whenever an order changes, does it mean like for example when the ticks increase or decrease, or in terms of change as if the order has been filled and canceled?
    - For the OnExecutionUpdate, it said execution or fill on your orders, so does it run whenever a contract has been submitted and whenever the contract hits a profit target and stop loss, if so, how do I implement it in a way where there is a specific stop loss or profit target.

    The definition is very unclear and I want to have a more defined definition. Thanks

    #2
    They are not mutually exclusive.

    OnOrderUpdate (usually) runs first, this callback lets you inspect all OrderState changes.

    OnExecutionUpdate runs second (if necessary) and only when the OrderState is Filled or PartFilled.

    You may well see both of these fire in quick succession.

    Comment


      #3
      So can you explain when does OnOrderUpdate and OnExecutionUpdate runs? which runs when the tick increase or decrease and which would run when the order is submitted

      Comment


        #4
        Originally posted by horace chow View Post
        So can you explain when does OnOrderUpdate and OnExecutionUpdate runs? which runs when the tick increase or decrease and which would run when the order is submitted
        What does when tick increase or decrease mean?

        After an entry order is submitted you would soon see OnOrderUpdate called for the
        StateChange events of that order as it eventually goes to Working -- or to Accepted.

        When the order is executed at the exchange, OnOrderUpdate is called again to reflect
        the StateChange to Filled (or PartFilled). Right after this, you will see OnExecutionUpdate
        is called.

        If by tick increase or decrease you mean manually adjusting an open order up or
        down by 1 tick using +/- buttons in Control Center -- yes, you will receive an OnOrderUpdate
        event in your strategy each time you adjust the StopPrice or LimitPrice of a standing
        order -- even when this is done manually via +/- buttons in the Control Center Orders tab.
        Last edited by bltdavid; 05-27-2020, 06:24 PM.

        Comment


          #5
          Hello horace chow,

          OnOrderUpdate will iterate when an order is submitted, accepted, working and filled.

          OnExecutionUpdate will iterate when an order is executed (filled or partial filled.)

          These are separate events than market data events which will update OnBarUpdate/OnMarketData.

          You can check the SampleOnOrderUpdate strategy for further direction on using these methods. I may also suggest testing with if (State == State.Historical) return; added to the script's OnBarUpdate method, and with prints added in OnOrderUpdate and OnExecutionUpdate to print out the Order and Execution when these updates occur. This will help to visualize when these events occur and how they can be used.

          SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

          We look forward to assisting.
          JimNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Jim View Post
            ... I may also suggest testing with if (State == State.Historical) return; added to the script's OnBarUpdate method, and with prints added in OnOrderUpdate and OnExecutionUpdate to print out the Order and Execution when these updates occur. This will help to visualize when these events occur and how they can be used.
            please could you elaborate further on this ... for ex show a sample or a screencast. I do not understand how to use if (State == State.Historical) return; where exactly to insert it and what info it is going to tell.
            thx

            Comment


              #7
              Hello guidoisot,

              When we enable a script, it first processes historical data and then it processes realtime data.

              If you want to skip historical processing, you can check if the current state is State.Historical, and then call return. This will effectively have the script always start flat and can be used to quickly test your logic from a flat position.

              I have attached a screenshot showing this code added in OnBarUpdate.
              Attached Files
              JimNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Jim View Post
                ... can be used to quickly test your logic from a flat position.
                you mean either in real time or better in simulated feed since the latter can be run faster than real time.
                So does this imply that OnOrderUpdate and OnExecutionUpdatecannot be used in backtesting?
                and neither in market replay?
                thx

                Comment


                  #9
                  Hello guidoisot,

                  No, you can test the strategy as is in the Strategy Analyzer to observe that it can be backtested and OnOrderUpdate and OnExecutionUpdate can be used when backtesting.

                  The suggestion to skip historical processing is simply for testing so you can enable the strategy and know that it has started flat.
                  JimNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ghoul, Today, 06:02 PM
                  3 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  44 views
                  0 likes
                  Last Post jeronymite  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  7 responses
                  20 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  180 views
                  0 likes
                  Last Post jeronymite  
                  Started by DanielSanMartin, Yesterday, 02:37 PM
                  2 responses
                  13 views
                  0 likes
                  Last Post DanielSanMartin  
                  Working...
                  X