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

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 kujista, Today, 05:44 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post kujista
                    by kujista
                     
                    Started by ZenCortexCLICK, Today, 04:58 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post ZenCortexCLICK  
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    172 responses
                    2,281 views
                    0 likes
                    Last Post sidlercom80  
                    Started by Irukandji, Yesterday, 02:53 AM
                    2 responses
                    18 views
                    0 likes
                    Last Post Irukandji  
                    Started by adeelshahzad, Today, 03:54 AM
                    0 responses
                    8 views
                    0 likes
                    Last Post adeelshahzad  
                    Working...
                    X