I need to access Positon.AvgPrice, Position.Quantity, etc. in such a scenario:
1. I open a position using ChartTrader or Super DOM.
2. Then I start my Ninja Script.
3. My Script obtains Positon.AvgPrice, and Position.Quantity
and Prints them.
The problem is that such a scenario provides only zeros as Position values.
At the same time an instance of Position class do contains proper values
ONLY if the position was created by the script itself!!!
My script below confirmed this.
Is there any way to access the opened position info within a script, that has been started AFTER the position was opened manually?
Which Class or Method has access there?
Thank you in advance.
public class ShowPosition : Strategy
{
protected override void Initialize()
{
ClearOutputWindow();
CalculateOnBarClose = true; //false;
Add("MSFT", PeriodType.Minute, 5);
}
private void PrintPositionInfo( int PosNumber )
{
Print(" ");
Print("CurrentBar = " + CurrentBar);
Print( "Position# " + PosNumber );
Print("Position.AvgPrice=" + Position.AvgPrice);
Print("Position.Quantity=" + Position.Quantity);
Print("Position.MarketPosition=" + Position.MarketPosition);
double PL = Position.GetProfitLoss(Close[0],0);
// If not flat print our unrealized PnL
if (Position.MarketPosition != MarketPosition.Flat)
Print("Open PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Points));
}
private void GoLong()
{
Print("CurrentBar=" + CurrentBar);
if (CurrentBar == 30)
{
Print("");
Print("Inside EnterLong(100)");
EnterLong(100);
PrintPositionInfo(0);
}
// Exits position
if (CurrentBar == 35)
{
Print("");
Print("Inside ExitLong(50)");
ExitLong(50);
PrintPositionInfo(0);
}
}
protected override void OnBarUpdate()
{
GoLong();
}

Comment