• 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

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 Oliver81594, Today, 04:09 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post Oliver81594  
                  Started by Nate G, Yesterday, 05:27 PM
                  1 response
                  14 views
                  0 likes
                  Last Post MojoJojo  
                  Started by Mindset, Yesterday, 10:35 PM
                  1 response
                  6 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by habibalex, Yesterday, 08:19 PM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_Marco  
                  Started by lakersfan, Yesterday, 07:53 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post lakersfan  
                  Working...
                  X