Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trying to retrieve entry price - need help

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

    trying to retrieve entry price - need help

    In the strategy analyzer, when I enter long and then display what I think is the entry price...as follows:

    EnterLong();
    Print(spaces12+"Position.AvgPrice="+Position.AvgPr ice.ToString("0.0000"));

    The value displayed in the output window is 0.0000?






    #2
    Hello joemiller,

    The issue is most likely that the position is not filled when this print is made. (It takes a few moments for an order to fill even with the simulator).

    I recommend that you move the print statement to OnPositionUpdate().

    This will print the position after the order is filled.

    Below is a link to the help guide on OnPositionUpdate().
    http://www.ninjatrader.com/support/h...tionupdate.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      I did the following and the average price still displays as zero?
      I am using hourly bars.
      The analyzer execution and trade tables display many entries, all at non-zero, reasonable prices.

      protected override void OnPositionUpdate(IPosition position)
      {
      if (position.MarketPosition == MarketPosition.Flat)
      {
      Print(spaces12+"***Position.AvgPrice="+Position.Av gPrice.
      ToString("0.0000"));//PPPPPPPPPPPPPPP
      }
      }

      Comment


        #4
        Hi joemiller,

        The check for position being flat is causing your script to only print when there is not a position.

        This means that your code will only ever print 0.

        Try removing the position check.

        For example:
        Code:
        protected override void OnPositionUpdate(IPosition position)
        {
        Print(spaces12+"***Position.AvgPrice="+Position.Av gPrice.
        ToString("0.0000"));//PPPPPPPPPPPPPPP
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          That did it.
          Many Thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          102 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          144 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          71 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          125 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          79 views
          0 likes
          Last Post PaulMohn  
          Working...
          X