Announcement

Collapse
No announcement yet.

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.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              566 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              330 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              547 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              548 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X