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

detection account position for a given instrument

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

    detection account position for a given instrument

    Hey guys, I hope all is going well. Here is my situation: I need a strategy to be able to detect if any positions are open for a given account.. not JUST for the strategy. For example, if the account "Sim101" has a long trade open for the instrument "es 03-09", I would need to be able to detect that in the strategy.. even if that position was opened outside of the strategy being used. I would also need to be able to detect if the account is flat. Any advice? Thanks in advance.

    Also, is there any way to detect if there are any open positions in ninjatrader outside of ninjatrader itself? I am creating an external application to send trading signals to certain clients, but it needs to be able to detect if I have any open positions. If I could do the former efficiently, then the latter isn't a necessity.
    Last edited by naifwonder; 01-16-2009, 02:58 AM.

    #2
    naifwonder,

    This is currently not available, but is on our list of future considerations. NinjaTrader does not know of open positions you have outside of NinjaTrader.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      i should have been more specific, sorry about that..

      what I meant was that the position would be opened in ninjatrader. However, it might be done so through a different strategy, or maybe through the dom. So what I should say is, I need to be able to find out about any positions opened in ninjatrader for a given account for a given instrument.

      Comment


        #4
        Right, this is not possible and is on our list.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I am new to the forum and NT. Does NT 7 include this functionality now? THX

          Comment


            #6
            Welcome to our forums mydann - this is unfortunately not possible with NT7. A NinjaScript strategy would 'know' about it's own positions only.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Hi Bertrand,

              Thank you for your clarification. Do you work in NinjaTrader customer service dept? I have sent you a private message explaining my simple strategy.

              Basically my strategy needs to re-balance my position based on the market situation and current existing position. It may need to buy a little more, sell a little more or flat the position. In order to calculate the current market value of my existing position, my strategy needs to know the ACCOUNT position of instruments instead of STATEGY position.

              After searching, I found there is a similar one in FILE/DLL/COM inerface:
              int MarketPosition(string instrument, string account)
              Gets the market position for an instrument/account combination. Returns 0 for flat, negative value for short positive value for long

              Will it return the account position of the instrument? Or it returns the strategy position and which strategy?

              FYI, it is found in V6 help but not in V7 help. Is it deprecated?


              Thanks
              Daniel
              Last edited by mydann; 07-20-2011, 08:26 PM.

              Comment


                #8
                Hello,

                This is Brett responding for Bertrand. Anyone with NinjaTrader_ in there name works for NinjaTrader.

                This will get the account position for that instrument. It is also in the NT 7 help guide and is not depreciated.



                Let me know if I can be of further assistance.

                Comment


                  #9
                  NT 7 Market position

                  int MarketPosition(string instrument, string account)
                  Gets the market position for an instrument/account combination. Returns 0 for flat, negative value for short positive value for long.


                  Can you please give an example of the correct use of this function?

                  For example MarketPosition(ES 06-16, sim101)

                  I cannot get it working or get it to print to output. ... Regards
                  Last edited by elliot5; 06-02-2016, 07:38 AM.

                  Comment


                    #10
                    Hello everington_f,

                    Thanks for your post.

                    The DLL functions are for use with an external program such as Tradestation or esignal (http://ninjatrader.com/support/helpG...terface_at.htm.

                    You can find examples of use here: http://ninjatrader.com/support/helpGuides/nt7/?
                    esignal_sample_code.htm
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      NT 7 Market position

                      Ok I only use NT - then for an existing NT position - I can use

                      Positions[i].Account.Positions.Count >0

                      but it appears not to be instrument specific - if any position is open out of an array list the function counts it... how can I get account and instrument specific information for a position that is not a strategy position?

                      I have computer down time occasionally ... and need to be able to access the account position in code to manage them upon restart. (BTW I never understand why NT was not designed to be able to sync the strategy position to the account position.... Far more useful than the current situation. Regards

                      Comment


                        #12
                        Hello everington_f,

                        Thanks for your reply.

                        You can access the account information in this way:

                        Code:
                        foreach (Account acct in Cbi.Globals.Accounts)
                        {
                        if (acct.Positions != null)
                        {
                        PositionCollection positions = acct.Positions;
                        foreach (Position pos in positions)
                        {
                        Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
                        }
                        }
                        Please note that this is undocumented/unsupported code.
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          pos. in conditional statement

                          Thankyou Paul - that prints to output beautifully.... But are the pos. values available for a conditional statement? This one doesnt compile...... perhaps you have a better example..


                          foreach (Account acct in Cbi.Globals.Accounts)
                          {
                          if (acct.Positions != null)
                          {
                          PositionCollection positions = acct.Positions;
                          foreach (Position pos in positions)
                          {
                          if (BarsInProgress == i
                          && pos.Account.Name == sim101
                          && pos.instrument == PFE Default
                          && pos.MarketPosition == Short

                          && GetCurrentAsk(i) <= MIN(Closes[i],5)[1])

                          {
                          EnterLong(i,voladjust, "Exit Short"+i);
                          }

                          }
                          }
                          }



                          Or can I use something along these lines?


                          if (BarsInProgress == i
                          && Positions[i].Account.Positions.FindByAccountInstrument(sim101, PFE Default) == true)


                          perhaps (int MarketPosition(string instrument, string account) would work... but I need an example of instrument and account... cannot get the function to compile.

                          I simply need to be able to test in conditional setting for the presence of position in a specific instrument in an account. Regards and thx
                          Last edited by elliot5; 06-03-2016, 07:46 AM.

                          Comment


                            #14
                            Hello everington_f,

                            Thanks for your reply.

                            You would need to make some changes to test for the printed items, examples:

                            pos.Account.Name == "Sim101"

                            pos.Instrument.FullName == "YM 06-16"

                            pos.MarketPosition == MarketPosition.Short
                            Paul H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by jxs_xrj, 01-12-2020, 09:49 AM
                            6 responses
                            3,290 views
                            1 like
                            Last Post jgualdronc  
                            Started by Touch-Ups, Today, 10:36 AM
                            0 responses
                            7 views
                            0 likes
                            Last Post Touch-Ups  
                            Started by geddyisodin, 04-25-2024, 05:20 AM
                            8 responses
                            61 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by Option Whisperer, Today, 09:55 AM
                            0 responses
                            8 views
                            0 likes
                            Last Post Option Whisperer  
                            Started by halgo_boulder, 04-20-2024, 08:44 AM
                            2 responses
                            24 views
                            0 likes
                            Last Post halgo_boulder  
                            Working...
                            X