Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position Data Access within a Script or Indicator

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

    Position Data Access within a Script or Indicator

    Hello everybody,

    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();
    }

    #2
    Hi bhawk,

    Positon.AvgPrice and Position.Quantity will only return values for open positions executed from the strategy they are within.

    Unfortunately, there is no method of accessing orders/trades that are placed manually.
    TimNinjaTrader Customer Service

    Comment


      #3
      Running My Strategy Script with Chart Trader or Superdom

      Thank you, Tim for your statement. To overcome the problem I see another scenario, that looks possible:

      1. I create a Script that opens a position when I run it.
      In such a case I have access to the Position info.

      How can I call this script with Chart Trader or Super Dom with a button
      or cell click. Is there any way to connect the Script to Chart Trader or Super DOM?

      All my attempts to do such a connection fail. ( I am new in Ninja Trader Environment ).

      Can you advise something, please?

      Thank you again.
      Last edited by bhawk; 05-17-2010, 08:05 AM.

      Comment


        #4
        Hi bhawk,

        In most cases, trades that are placed from a strategy should not be manually manipulated.

        A few options, however...
        1. You can cal an ATM Strategy from within a strategy, please see the sample at "Tools>Edit NS>Strategy>SampleAmStrategy"
        2. If you just need to monitor the values, you can do so from your script using Print() statements.
        TimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        670 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        379 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        111 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        582 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X