Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Brandon H.NinjaTrader Customer Service

    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
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kempotrader, Today, 08:56 AM
        0 responses
        6 views
        0 likes
        Last Post kempotrader  
        Started by kempotrader, Today, 08:54 AM
        0 responses
        4 views
        0 likes
        Last Post kempotrader  
        Started by mmenigma, Today, 08:54 AM
        0 responses
        2 views
        0 likes
        Last Post mmenigma  
        Started by halgo_boulder, Today, 08:44 AM
        0 responses
        1 view
        0 likes
        Last Post halgo_boulder  
        Started by drewski1980, Today, 08:24 AM
        0 responses
        3 views
        0 likes
        Last Post drewski1980  
        Working...
        X