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

When to use Position or PositionAccount?

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

    When to use Position or PositionAccount?

    I've developed an indicator (not a strategy) for trading.
    In the indicator I'm checking for an open position with the account.Positions collection.
    The manual mentions a Positions as well as a PositionsAccount collection, and makes some confusing remarks about the difference.


    Holds an array of Position objects that represent positions managed by the strategy.
    This property should only be used when your strategy is executing orders against multiple instruments.


    This property should only be used when your strategy is executing orders against multiple instruments.

    And in the Position help it says:

    Represents position related information that pertains to an instance of a strategy.
    Tips:
    •For multi-instrument scripts, please see Positions object which holds an array of all instrument positions managed by the strategy's account
    •For a real-world Account Position, please see PositionAccount.
    And the PositionAccount help says:

    Represents position related information that pertains to real-world account (live or simulation).
    Tips:
    •For multi-instrument scripts, please see PositionsAccount object which holds an array of all instrument positions managed by the strategy's account
    •For a Strategy Position, please see Position
    My indicator is not a strategy and is working with one instrument.
    Which of these collections should I use for live trading?

    #2
    Hello wjadevries,

    If you are creating an indicator that trades you can essentially ignore the Strategy related content. The two items you linked are for use with Strategies.

    You would not have an equivalent object in an indicator, you would reference the account and then the Positions collection from the account. In that collection you may have multiple position objects. https://ninjatrader.com/support/help...ns_account.htm

    You are still working with Position objects not to be confused with a strategies inherited property "Position" which represents its virtual position. The Position object is a class which has the positions properties.

    The Addon section of the help guide is what you want to reference when doing trading/account related tasks from an indicator: https://ninjatrader.com/support/help...nt8/add_on.htm



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks.
      one more question:
      the addon section also contains the ChangeOrder method, but I can't use it since it gives unknown method compilation errors in my indicator.
      So I use the addon account.Change method instead.
      Why is the ChangeOrder method not available and what would be the difference?

      Comment


        #4
        Hello wjadevries,

        The ChangeOrder method is under the Strategy section in the help guide and is for managed/unmanaged strategies, you would need to refer to the Addon section and its Account sub category. If you are looking at the left bar in the help guide, expand the NinjaScript > Language Reference > Addon > Account. Under the Account category you will see Change, Submit, Cancel etc..

        When you use an account directly you will always be using the instance of the account. All account related help pages will require that you first find the account like shown in the main example here: https://ninjatrader.com/support/help...ount_class.htm

        Once you have the instance of the account you can issue commands to that account like submitting or changing orders.

        If you run into something which is not being found where you tried to use it, try searching for that in the help guide and go to the page for it. For example going to ChangeOrder's page you can see at the top of the page NinjaScript > Language Reference > Strategy > Order Methods > Managed Approach so that won't apply in this use case based on where it was in the help guide.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Totally clear, thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          19 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          21 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X