• 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

The exact price of the order I just bought.

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

    The exact price of the order I just bought.

    Greetings,
    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!!!

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

    Comment


      #3
      I tried, but it's 0!

      Comment


        #4
        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

        Comment


          #5
          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!

          Comment


            #6
            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.

            Comment


              #7
              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

              Comment


                #8
                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!!!

                Comment


                  #9
                  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

                  Comment


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

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

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NinjaCustomer, Today, 12:14 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Started by U0000999, Yesterday, 11:49 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post U0000999  
                    Started by ahadari28, Yesterday, 04:01 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post ahadari28  
                    Started by TazoTodua, Yesterday, 06:00 AM
                    2 responses
                    19 views
                    0 likes
                    Last Post TazoTodua  
                    Started by TazoTodua, Yesterday, 09:06 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X