• 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.


No announcement yet.

Partner 728x90


The exact price of the order I just bought.

  • Filter
  • Time
  • Show
Clear All
new posts

    The exact price of the order I just bought.

    Could anybody tell me how do I get the exact price of the order I just entered, PLEASE!?
    Like... after I EnterLong();, is there any function I could call to get the exact price of my order!? Such as,

    int p = GetExactPrice();

    Something like that!?
    Thank you very VERY much!!!

    Try Position.AveragePrice. Use a check to see if Position.MarketPosition == MarketPosition.Long


      I tried, but it's 0!


        Hello YoutingChu,

        Thanks for your inquiry.

        chnh1 is right that you could check Position.AveragePrice when you are in a position to see the fill price, however, this will be an average price of your strategy's position should you have received partial fills for an order with multiple contracts.

        I have attached a sample printing Position.Average price when in position along with using OnExecutionUpdate to print the fill price of a long entry order.

        Publicly available documentation on the items in this sample can be referenced below.

        OnExecutionUpdate() - https://ninjatrader.com/support/help...tionupdate.htm

        Position.AveragePrice - https://ninjatrader.com/support/help...erageprice.htm

        Please let us know if you have any questions.
        Attached Files
        JimNinjaTrader Customer Service


          Dear Jim,
          Thanks for your help.

          I tried your example, but it was never executed! Which means the if(Position.MarketPosition == MarketPosition.Long) condition was never met! And if I take that condition away, the result of Position.AvereragePrice become 0s again!
          And I tried OnExecuteionUpdate and get its price, but the price are all wrong!!! I have no idea what's going on!? And I don't understand why it needs to go through so much troubles JUST TO get the exact buying price!? WHY!?!?!?
          Thank you very VERY much for your help again!


            It would help if we understood more about your strategy.

            If you are manually entering a position and trying to use a strategy to track this kind of data, it will not work because your strategy did not enter the position. You did. The strategy position is zero.


              Hello YoutingChu,

              The execution will have to be seen before we can get the fill price. That can be in OnExecutionUpdate() as soon as the execution occurs or in OnBarUpdate() with the Position object after the order gets filled.

              I have attached a demonstration video showing the example in action. I added a return statement for State.Historical so we could focus on realtime executions.

              Demo: https://www.screencast.com/t/poeIzOzW8GC

              If the condition for MarketPosition.Long is commented out, then we will see the following prints:
              Position.AveragePrice: 0 CurrentBar: 26637
              OnExecutionUpdate: 2672.75 CurrentBar: 26637
              Position.AveragePrice: 2672.75 CurrentBar: 26638
              1. EnterLong() is submitted in OBU
              2. Position.AveragePrice gets printed from the same OBU iteration. The position is not yet opened.
              3. OnExecutionUpdate shows the fill price upon the order's execution
              4. On a new OBU iteration, we see Position.AveragePrice report the same price.

              Also, to touch more on liquid150's post, please make sure you are not mistaking manual order submissions with those owned by the strategy. The documentation page below can be referenced for more details.

              Strategy Position vs. Account Position - https://ninjatrader.com/support/help..._account_p.htm

              Please let me know if you have any additional questions.
              Last edited by NinjaTrader_Jim; 04-27-2018, 07:31 AM.
              JimNinjaTrader Customer Service


                Dear Jim,
                Thank you very much for your GREAT help!!!

                I was able to get the exact price, I hope that's what it is, through the OnExecutionUpdate. But there is still one question I would like to ask:

                What's the difference between execution.Price and price (the parameter which OnExecutionUpdate is taken)!?

                Thank you very VERY much for you help!!!

                Also thanks chnh1 and liquid150 greatly!!!


                  Hello YoutingChu,

                  "execution" is an execution object passed by reference and "price" represents the execution's price for convenience. "execution.Price" and "price" would represent the same thing.

                  This can be referenced in the OnExecutionUpdate() documentation page linked in post 4.

                  If there is anything else we can do to assist, please let us know.
                  JimNinjaTrader Customer Service


                    Please ignore... Deleted original post - made mistake in coding/corrected... Execution.Price works as expected for both entry and exit orders.

                    Last edited by music_p13; 06-05-2018, 03:35 PM.


                    Latest Posts


                    Topics Statistics Last Post
                    Started by mtamaku, Today, 09:19 AM
                    0 responses
                    Last Post mtamaku
                    by mtamaku
                    Started by traderMNQ, Today, 09:00 AM
                    3 responses
                    Last Post NinjaTrader_ChrisL  
                    Started by jransom, Today, 09:08 AM
                    1 response
                    Last Post NinjaTrader_Kate  
                    Started by Irukandji, Today, 08:27 AM
                    1 response
                    Last Post NinjaTrader_Manfred  
                    Started by brunoviveiros, Today, 08:18 AM
                    0 responses
                    Last Post brunoviveiros