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

Manage positions from several strategies

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

    Manage positions from several strategies

    Hi My Friends,

    You guys probably wrote about this before but I couldn't find the right keyword. This is the situation:
    I have 2 strategies (Unmanaged = true running at the same time over the same instrument, same account. Strategy A found a buy opportunity and executed 1 Buy Market, generating 2 other orders (Target and Stop). After 1 minute, Strategy B found a SELL opportunity and executed 1 Sell Market, generating 2 other orders (Target and Stop). Now my account position is flat and I have 4 unnecessary orders pending in my chart. I have all OCO setup in my OnExecution and OnPositionUpdate but since the SELL order came from Strategy B, Strategy A was not able to cancel Target and Stop (as programmed).
    I tried to use Account.Position but it does not show me direction, only count.

    Any help appreciated,

    mcosta72
    NinjaTrader Ecosystem Vendor - Quant-Wise

    #2
    Originally posted by mcosta72 View Post
    I have 2 strategies (Unmanaged = true running at the same time over the same instrument, same account.
    Well, there's your problem.

    Don't do that.

    If you want to do what you are doing, use 2 different accounts.


    Comment


      #3
      Hello mcosta72,

      Your broker will have one position for each account and instrument. bltdavid is correct. You would need separate accounts.

      Below is a link to a forum post where this is discussed.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Technically, same strategy (on same instrument same account) can be done -- if you code your strategy to such that you setup a trade lock mechanism. What I have done is that if Strat A wants to enter a trade (long or short, doesn't matter) it must first acquire the TradeLock -- if successful, it enters the trade. Along comes Strat B who wants to enter a trade, it tries to acquire the TradeLock but fails because Strat A has the lock, thus Strat B is denied trade entry.

        The strategy code is designed so that the single TradeLock is a shared resource. Only 1 strategy at a time can trade, and that is whoever has acquired the TradeLock. The other strategy is simply denied entry and waits for its next setup.

        I've used this with great success -- for ex, setup strat A to take longs only, and strat B to take shorts only -- and trading same instrument in same acct using two different instances of same strategy worked like a charm -- the TradeLock solution is what made this possible.
        Last edited by bltdavid; 01-28-2019, 01:15 PM.

        Comment


          #5
          Thank you bltdavid and Chelsea,

          @btldavid, The TradeLock idea is something that I would like to avoid, but I think it is impossible with the systems we have right now. I am going to allow the same direction orders be placed but I will definitely block opposite orders.

          The next question is: Where in Account instance is stored the Long or Short Information? Account.Positions shows only quantity.

          mcosta72
          NinjaTrader Ecosystem Vendor - Quant-Wise

          Comment


            #6
            Does Anyone know anything about "Account" object?
            Thanks
            mcosta72
            NinjaTrader Ecosystem Vendor - Quant-Wise

            Comment


              #7
              Hello mcosta72,

              The Account class is not documented in NinjaTrader 7 so we cannot offer any support for its usage. I may suggest using Intellisense and using prints to see how you can use the Account object and Account.Positions collection. Prints similar to the following can help provide further direction.

              Code:
              foreach (Position pos in Account.Positions)
              {
                  Print(String.Format("Instrument: {0} MarketPosition: {1} Quantity: {2}", pos.Instrument.FullName, pos.MarketPosition, pos.Quantity));
              }
              If you have any additional questions involving documented NinjaScript, we will be happy to assist you further.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              238 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              383 views
              1 like
              Last Post Gavini
              by Gavini
               
              Started by oviejo, Today, 12:28 AM
              0 responses
              1 view
              0 likes
              Last Post oviejo
              by oviejo
               
              Started by pechtri, 06-22-2023, 02:31 AM
              10 responses
              125 views
              0 likes
              Last Post Leeroy_Jenkins  
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              59 views
              0 likes
              Last Post DynamicTest  
              Working...
              X