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

Average Price in ON ORDER UPDATE

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

    Average Price in ON ORDER UPDATE

    Hi,
    I have a question regarding the average price in the ON ORDER UPDATE - event.
    The online help defines the average price as follows:

    "A double value representing the average fill price of the order update"

    I have difficulties understanding that as I am not an English native speaker. Does this mean it is the average price of each fill or the whole order which is executed so far?

    Example:
    order is Buy 3 NQ at market

    Lets assume I get 2 fills and the resulting order updates in NT

    Bought 1 at 16300
    Bought 2 at 16310

    Is the 16310 the average price of the position (without commission)?

    Thanks,
    Klaus

    #2
    Hi Klaus, thanks for writing in.

    The average price would be 16305 without commission. The OnOrderUpdate method is able to differentiate between Filled and PartFilled orders, so you can capture the average price during the partial fills and full fills. See the OnOrderUpdate/OnExecutionUpdate reference as an example:



    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,
      thanks for your fast answer. I have the same understanding. But I just saw something different while testing a strategy.
      I am currently testing a strategy on my paper trading account with IB. I know that IB is sending quite unrealistic fills but I actually like that. This stresses my strategy and reveals most of the issues.

      I just had the following order upades in the log window:

      Time Category Message
      08/11/2021 16:00:46 Order Order='974570712/DU3766291' Name='S' New state='Accepted' Instrument='NQ 12-21' Action='Sell short' Limit price=0 Stop price=0 Quantity=2 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
      Time Category Message
      08/11/2021 16:00:46 Order Order='974570712/DU3766291' Name='S' New state='Partially filled' Instrument='NQ 12-21' Action='Sell short' Limit price=0 Stop price=0 Quantity=2 Type='Market' Time in force=GTC Oco='' Filled=1 Fill price=16329.5 Error='No error' Native error=''
      Time Category Message
      08/11/2021 16:00:46 Order Order='974570712/DU3766291' Name='S' New state='Filled' Instrument='NQ 12-21' Action='Sell short' Limit price=0 Stop price=0 Quantity=2 Type='Market' Time in force=GTC Oco='' Filled=2 Fill price=16321.375 Error='No error' Native error=''

      According to our understanding the avg Price for the position would be
      (16329,5 + 16321,375)/2 = 16325,4375

      Unfortunately NT came up with an average price of 16329,5
      08/11/2021 16:00:46 Position Instrument='NQ 12-21' Account='DU3766291' Average price=16329.5 Quantity=1 Market position=Short Operation=Operation_Add
      This price was also printed in the chart which I attached. Are we having an issue here?
      Thanks,
      Klaus
      PS: the target and stop order are placed with the correct price as I am maintaining my own position object
      Attached Files

      Comment


        #4
        Hi Chris,
        the Position update I had was the first, after the first fill. After the second fill, there was this message:
        08/11/2021 16:00:46 Position Instrument='NQ 12-21' Account='DU3766291' Average price=16321.3225 Quantity=2 Market position=Short Operation=Update
        This is the same price as shown in the chart. NT calculated an average of 16321,3225

        Sorry for the confusion.
        Klaus

        Comment


          #5
          Hi Klaus,

          Can you reproduce the same thing on the playback connection? Please let me know if you can, and I will test the same. If not, I we will need to try and reproduce with our test IB account. I just tested on the Sim101 account and got an expected result.

          Best regards,
          -ChrisL
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Hi Chris,
            I would like to skip the playback connection test. I am testing my strategy on the same server where my live strategies are running and I would like to avoid that playback test. But I can reproduce the behaviour as often as I get partial fills on my paper trading account.
            We could have a remote session if you like.
            Thanks,
            Klaus

            Comment


              #7
              Hi Klaus,

              I will assume the issue is reproducible on a paper Interactive brokers account so I will test on that and let you know if I can reproduce it. If not you can write to scriptingsupport at ninjatrader.com and I can take a look at your setup.

              Best regards,
              -ChrisL
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Hi Klaus,

                I have been testing this issue you reported but I am not able to reproduce with our test IB connection. Can you confirm you are running the correct version of either TWS or gateway? The supported versions are listed here with a download link if you are not running one of these:


                Best regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chris,
                  sorry for coming back so late. I missed the nofication of your answer.

                  Yes, I am running the recommended version of IBG and the latest version of NT. We can setup a Web-Session if you want.
                  Thanks,
                  Klaus

                  Comment


                    #10
                    Hi, thanks for the follow up. I will not be able to debug or test over teamviewer. I was not able to reproduce the issue you reported a month ago when I tested our IB connection. Are you able to reproduce on the SampleMACrossover strategy running on your paper IB account? If not, please reduce the strategy you are using and send me a video of this happening through google drive or wetransfer.

                    Best regards.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      I did a quick test with the managed approach and the SampleMACrossover. I could not reproduce the issue either. Then I tried to test it with the unmanaged approach. (the original strategy uses that) and I got the following message for the paper trading account:
                      14/12/2021 16:01:43 Default Strategy 'SampleMAXOver': Error on calling 'OnBarUpdate' method on bar 22: Strategy 'SampleMAXOver/250787235': 'SubmitOrderUnmanaged' method can't be called on managed strategies.
                      The same strategy works perfectly for the sim-account on my test machine. What am I missing here?
                      Attached Files

                      Comment


                        #12
                        Hi Klaus, Please try removing and re-adding the strategy in case you added the strategy to the chart before setting IsUnmanaged = true.

                        Best regards.
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chris,
                          that did do the trick. Thanks. I was testing the last days and I could not reproduce the issue with your strategy.
                          But I still have the issue in the other. So that would mean that there is an issue. I will investigate that further.

                          One question regarding the information in the LOG window:
                          - Where does NT get the information about the Order / Execution / Position - Information? Is it getting the information right from the connection handler?

                          Thanks,
                          Klaus

                          Comment


                            #14
                            Hi Klaus, that is correct. The updates for Orders/Executions/Positions are sent by the connection. In this case, the IB connection. Also, note that the order of these events is not guaranteed from IB or Rithmic connections. I attached a sample strategy that is able to properly calculate a position object based on the incoming executions rather than relying on the OnPositionUpdate event.

                            Best regards,
                            -ChrisL
                            Attached Files
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks Chris for the explanation.
                              I am aware of the drawbacks of the IB connection. I did develop filters and logic to deal with that and it is working good. I am only using the ON ORDER UPDATE event and did program my own execution logic and position object. That is doing what it should do. Only the log window bothers me because it is showing false information and therefore also the position on the chart window is false.
                              But I am going to live with it.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Jonafare, 12-06-2012, 03:48 PM
                              5 responses
                              3,986 views
                              0 likes
                              Last Post rene69851  
                              Started by Fitspressorest, Today, 01:38 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Fitspressorest  
                              Started by Jonker, Today, 01:19 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Jonker
                              by Jonker
                               
                              Started by futtrader, Today, 01:16 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post futtrader  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              14 responses
                              1,792 views
                              0 likes
                              Last Post aligator  
                              Working...
                              X