Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy and existing positions

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

    strategy and existing positions

    when first loading a strategy onto a chart, can I determine if there are any existing long/short open positions or do I need to tell the strategy about these using e.g. parameters?

    #2
    Hello delTik,

    Thank you for writing in.

    From a NinjaTrader 8 strategy, you will be able to determine the position of your account by using PositionAccount (or PositionsAccount if your strategy will execute orders against multiple instruments.

    PositionAccount
    PositionsAccount

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      great thank you.

      do you know where I can look at a few more detailed samples than the default ninjascript installed strategies?

      I really just want to just check if an account is long or short on the first tick of the bar?

      Comment


        #4
        Hello delTik,

        While we do not have a sample for this particular question, I would suggest taking a look at our reference sample section here on the support forum for some very helpful samples: http://ninjatrader.com/support/forum...splay.php?f=30

        If you want to check if the current account position is long or short on the first tick of bar, for example:
        Code:
        if (IsFirstTickOfBar)
        {
             if (PositionAccount.MarketPosition == MarketPosition.Long)
                  // do something
             else if (PositionAccount.MarketPosition == MarketPosition.Short)
                  // do something
        }
        For more information about IsFirstTickOfBar, please take a look at this help guide link: https://ninjatrader.com/support/help...ttickofbar.htm

        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          thanks Zachary

          I've created

          myAccount = Account.Accounts.FirstOrDefault(a => a.Name == "Sim101");

          but which account does

          PositionAccount

          refer to?

          I'd really like to understand how this is organised e.g.
          which account is a strategy assigned to?
          which account or strategy is EnterLong assigned to?
          if an instrument has multiple positions which one does PositionAccount refer to?
          Last edited by delTik; 05-12-2016, 04:01 AM.

          Comment


            #6
            Hello delTik,

            PositionAccount refers to the account the strategy is running on.

            When adding the strategy to a chart or through the Strategies tab on the Control Center, the account that the strategy will be running on is selected within the Account drop down menu under Set up.

            PositionAccount refers to the entire account position for the instrument your strategy is running on; if your strategy utilizes multiple instruments, each different account position for each different instrument can be accessed with PositionsAccount: https://ninjatrader.com/support/help...onsaccount.htm
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              ok thanks. does this assume that an instrument can only have one position? what if say EURUSD has 3 positions?

              PositionsAccount "should only be used when your strategy is executing orders against multiple instruments."

              what about executing multiple orders against a single instrument? which one do I use PositionAccount or PositionsAccount?

              I'm probably misunderstanding, sorry.
              Last edited by delTik; 05-13-2016, 05:00 AM.

              Comment


                #8
                Hello delTik,

                If you wish to see your position size, then you would use PositionAccount.Quantity.

                You would use PositionAccount if your strategy is only running over one instrument.

                If your strategy is running over multiple instruments (added additional Series with AddDataSeries()), you will use PositionsAccount to be able to access the position of the other instruments you have added.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks but if my current account has 3 (real) EURUSD positions which one is PositionAccount referring to?
                  Last edited by delTik; 05-13-2016, 09:14 AM.

                  Comment


                    #10
                    Hello delTik,

                    You will only have one position for each instrument. However, you may have a quantity higher than 1.

                    PositionAccount will refer to the entire position of the account and instrument your strategy is running on.

                    If you are running your strategy on an ES chart on Sim101, for example, but do not have an open position on your account, Sim101, for the ES, PositionAccount will be flat.
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      ok thanks Zachary, getting clearer now. have only 1 instrument.

                      I think where I'm getting confused is that I may have several positions on one instrument and each position has a different entry & quanitity. Possibly a mixture of long & short positions.

                      I can see how PositionAccount can be used to find e.g. 3 Long EURUSD with the same entry price but not the above? Same question applies to the strategy "Position"?
                      Last edited by delTik; 05-13-2016, 10:02 AM.

                      Comment


                        #12
                        Hello delTik,

                        Additional orders placed on your account at a different entry price will still be added to the total position quantity for that specific instrument.

                        The same applies to the strategy position.

                        The average position price will change, however.
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          ok thanks Zachary I think I have it ... PositionAccount & Position is the aggregate, would not be able to get the actual details.

                          So let's say I initially find 3 real long EURUSD how do I initialize the strategy with the same (again using script)?

                          Also can I find any existing (real) limit/stop orders?

                          Comment


                            #14
                            Hello delTik,

                            Can you please clarify what you mean by "how do I initialize the strategy with the same (again using script)?"

                            Are you wishing to submit an entry order with the quantity of PositionAccount.Quantity?

                            If you wish to find stop/stop limit orders on your real account, you'll need to utilize the Account class and access the Orders collection: https://ninjatrader.com/support/help...ount_class.htm
                            Zachary G.NinjaTrader Customer Service

                            Comment


                              #15
                              when I load the strategy on to the chart I want the script to:

                              1. Determine what the existing real positions are.
                              2. Set the positions in the strategy to be the same so it can make the correct decisions.

                              account position would typically not be flat when loading the strategy and this is what I call "initialization" so the strategy can take control of the real position.

                              If the strategy is unaware of the real position then it can't take control.

                              starting to feel a bit worried? (back tomorrow)
                              Last edited by delTik; 05-13-2016, 11:15 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              939 views
                              0 likes
                              Last Post spwizard  
                              Started by Max238, Today, 01:28 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by rocketman7, Today, 01:00 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post rocketman7  
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              28 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              33 views
                              0 likes
                              Last Post wzgy0920  
                              Working...
                              X