Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why Position.AvgPrice gives not exact price

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

    Why Position.AvgPrice gives not exact price

    If in my strategy i only place 1 contract orders at a time, why the value of Position.AvgPrice sometimes is not the exact buy/sell value ?

    Look at the picture for more detail ( in this example there are 2 separated longs of ES at 1237.75 Each bar shows at the top the value of Position.AvgPrice ) with :
    DrawText("tx2"+CurrentBar, "B="+Position.AvgPrice , 0, High[0] + 0.50, Color.Blue);


    Look that at the second long ( the first one was closed by a trailing Stop Loss ) the AvgPrice is 1237.72302996171 instead of 1237.75
    Attached Files
    pmaglio
    NinjaTrader Ecosystem Vendor - The Indicator Store

    #2
    What is your code for your positions? It seems to me you are printing that value even before you acquired your second long position.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      The blue dots are the entries ( EMA(100) + 0.25 ) end the exits are just moving the stop 3 ticks into the profit when the high of the current bar is at 4 ticks into the profit. ( there is a target at 4 ticks also, but not taken too frequently )
      pmaglio
      NinjaTrader Ecosystem Vendor - The Indicator Store

      Comment


        #4
        I think Josh would like to see all of the code if possible.
        RayNinjaTrader Customer Service

        Comment


          #5
          Ok, this is not the same code but i get the same error.
          The code is SampleMAcrossover_tmp and the image is from 16th July 1,000VB on the ES

          Note : The only difference with the original sample is in the entry ; the EnterLongLimit has an input value of EMA(fast)+0.25 ; ( which can be a a number non multiple of 0.25 ; but this should not be a problem....)
          Attached Files
          pmaglio
          NinjaTrader Ecosystem Vendor - The Indicator Store

          Comment


            #6
            When you want to add a value to say EMA() you don't want to just do + 0.25. You want to do + 25 * TickSIze.

            The reason you are seeing these values is simply because you are using a Limit order. You are using a double value of EMA(Fast)[0]. This EMA value is already priced out to funky decimals and so your limit order is placed at that funky decimal value. It is simply returning the value you told it to fill at so it is actually correct in its return.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              That explains a lot of problems I was having.... I thought that the filled price was automatic rounded to correct price for each instrument...
              How can I round the value EMA(fast)[0]+25*TickSize to the most near valid value ?

              Thanks !
              pmaglio
              NinjaTrader Ecosystem Vendor - The Indicator Store

              Comment


                #8
                Try the Round2TickSize() method - http://www.ninjatrader-support.com/H...2TickSize.html
                RayNinjaTrader Customer Service

                Comment


                  #9
                  I changed : EMA(fast)[0]+0.25
                  by : Instrument.MasterInstrument.Round2TickSize(EMA(Fas t)[0]+0.25)
                  And it works Perfect !

                  Thanks Ray !
                  pmaglio
                  NinjaTrader Ecosystem Vendor - The Indicator Store

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  605 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  351 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  560 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  561 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X