Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access position information in multi time frame.

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

    Access position information in multi time frame.

    Hi,
    I developed a multi time frame strategy:
    Code:
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1); // BarsInProgress 1
    }
    I use BarsinProgress == 1 for 1 Tick timeframe and BarsinProgress == 0 for default data series selected in the Strategy settings.

    Well, at this point I have a problem handling the Position.MarketPosition. When I want to take an enter I use in this way:

    Code:
    if(BarsinProgress == 1) {
    if(EnterLongCondition) 
        EnterLong(1, quantity_1, "Long #1");
    }
    The trade is taken but when I try to see what the market position is, I always see Flat.

    I have tried these ways:
    Code:
    Print(PositionsAccount[0].MarketPosition);
    Print(PositionsAccount[1].MarketPosition);
    Print(Position.MarketPosition);
    How can I access the information of the position, as well as the average value of the position?

    PS: I have tried also with EnterLong(quantity_1, "Long #1");

    Thank you

    #2
    Hello lju45,

    Thank you for your post.

    If you would like to print out the account positions for the orders that are submitted to the added series, you would need to check if BarsInProgress == 1 followed by adding your print statement. For example, the code may look like this.

    Code:
    if (BarsInProgress == 1)
    {
        Print("BarsInProgress: " + BarsInProgress + " MarketPosition: " + PositionAccount.MarketPosition + " Average Price: " + PositionAccount.AveragePrice);
    }
    See the help guide documentation below for more information.
    BarsInProgress - https://ninjatrader.com/support/help...BarsInProgress
    PositionAccount - https://ninjatrader.com/support/help...ionaccount.htm

    If you see that the print is only outputting that the market position is flat, debugging steps would need to be taken to determine how the strategy is behaving.

    Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
    https://ninjatrader.com/support/foru...121#post791121

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you Brandon,

      I have test it and the result is Flat and 0 all the time although there are trades (image 1)
      I have also tried this and have not obtained results either, so I am unable to enter the position information when I'm doing backtest.
      Code:
      if (PositionAccount.AveragePrice != 0)
      {
      Print("BarsInProgress: " + BarsInProgress + " MarketPosition: " + PositionAccount.MarketPosition + " Average Price: " + PositionAccount.AveragePrice);
      }

      Comment


        #4
        Hello lju45,

        Thank you for your note.

        Please see the attached example script which demonstrates printing the quantity, market position, and average price for the Strategy position and the Account position.

        To print the Account position and Strategy position, we print the following within the OnPositionUpdate() method. OnPositionUpdate() is an event-driven method that is called each time the position of a strategy changes state.

        Code:
        protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
        {
            Print(String.Format("Account Positions - Quantity: {0}, {1} at {2}", PositionAccount.Quantity, PositionAccount.MarketPosition, PositionAccount.AveragePrice));
            Print(String.Format("Strategy Positions - Quantity: {0}, {1} at {2}", Position.Quantity, Position.MarketPosition, Position.AveragePrice));
        }
        See the help guide documentation for more information.
        OnPositionUpdate - https://ninjatrader.com/support/help...tionupdate.htm
        PositionAccount - https://ninjatrader.com/support/help...ionaccount.htm
        Position - https://ninjatrader.com/support/help...8/position.htm

        Let us know if we may assist further.
        Attached Files
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        51 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        127 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X