PDA

View Full Version : Position.AvgPrice Real Value


daven
10-30-2008, 09:02 AM
I have always assumed that when calling "Position.AvgPrice" for position one gets the average ENTRY price for a position, but judging by how my strategy is behaving it appears that I am actually getting the average Price of my combined positions based on what they were at the last bar close. My problem is I am using the above price as a limit order for the remaining runner after I take off two contracts at a first profit target. Here is the code I am using.

if (Position.MarketPosition == MarketPosition.Short
&& Position.Quantity == 1)
{
ExitShortLimit(Position.AvgPrice , "SBreakEven Exit", "SRunner");
}

The problem is, this order is executing on the next bar after I close out the first two contracts and the price it is closing at, is generally the same as my first profit exit. If, as I suspect, the Position.AvgPrice gives us the avg price of the position at the time it is called, then is there a way to get the average entry price of a position? Perhaps store a variable and refer to it later? Or better yet, there is an actual command that provides the average entry price of a position. It seems that would be a very useful command if you don't already have it.
Thanks
DaveN

NinjaTrader_Josh
10-30-2008, 09:31 AM
Hi daven,

Position.AvgPrice returns you the average entry price of your complete position at the very moment you call it. If your position is already closed then this will likely not yield a value you want.

Instead you will want to access the historical Trades objects to get their entry prices. http://www.ninjatrader-support.com/HelpGuideV6/TradeClass.html

You can access the IExecution object of the entry and from there get the entry price for that trade.