Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Maximum position errors for multiple accounts

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

    Maximum position errors for multiple accounts

    I'm having issues with "Exceed account's maximum position" errors when trading multiple accounts.

    I have attempted using an off the shelf copy trader as well as building my own in ninja script. I have no issues when trading a single account up to my max contracts, but the second I trade 2+ accounts where each account places a market order above 50% of my contract limit with a OCO TP and SL I get this error.

    Even odder is that this happens both when opening orders as well as closing orders, and it does not happen 100% of the time but say 80% of the time.

    Lets take a concrete example:

    I have 2 accounts Sim1 and Sim2 and each has a 10 contract limit. I can trade either of these accounts 1 at a time at 10 contracts with a OCO TP and SL with no issues. I can do this via my ninjascript or the NinjaTrader UI.

    Next scenario: In my ninja script I want both accounts to take the same entry. When I click BUY on my indicator it loops over the two accounts and submits a market order of 10 contracts and a OCO TP and SL. It submits these 3 orders together for each account milliseconds apart. More often than not this causes the "Exceed account's maximum position" error to pop up for both accounts. (I also waited for the market order to be filled and then place the TP and SL but that did not help)

    Additionally I have a "Flatten All" button that loops over each account calls account.CancelAllOrders and then places a market order in the opposite direction to close out the existing market position. This also causes the same "Exceed account's maximum position" most of the time.

    This seems like a bug in NijnaTrader, or maybe there is some nuance to placing bracket orders across multiple accounts. Since this process works flawlessly when using a single account I'm stumped.


    Side Note: If I trade 5 contracts and have a 10 contract limit per account I can copy orders over to as many accounts as I want. This leads me to thinking that the active contracts on the market are being calculated incorrectly when many accounts place orders in quick succession...


    #2
    Hello Blaze212,

    Do you see this problem if you do not use a trade copier? While I wouldn't be able to directly assist with a trade copier we can explore this if you have a situation where you are manually trading or have two strategies running as a few examples.

    Regarding the flatten, you would need to wait for the orders to be closed before submitting other orders, some actions do take time to complete so you won't be able to for example flatten an account and also submit orders in the opposite direction at once, that would require waiting for confirmation that the account is flat.

    Comment


      #3
      I am manually trading with my indicator. I built a NinjaScript indicator that attaches to the current chart and has configuration on the UI to trade multiple accounts at the same time.

      When I click the buy button on my UI it kicks off an account.Submit(Order(s)), for each account so I'm not copying trades, but rather submitting two identical orders on 2 different accounts at almost the same time.


      On the Flatten All side. I'm not trying to re-enter at any point. I call account.CancelAllOrders(Instrument); and then submit a reverse market order to close out my open position and then loop over this logic for each account configured.

      I attempted to find a way in the built in Ninja UI to try and execute two orders on different accounts at the same time like this but I didn't see an easy way. Maybe I could hook up multiple simple NinjaScript strategies to try and get the same result?


      Attached Files

      Comment


        #4
        Hello Blaze212,

        I would suggest making a simplified example that produces a problem when using Account.Submit from an indicator. It could simply submit two orders on the first realtime bar.

        On the flatten question calling CancelAllOrders would also require that you wait for confirmation, if you are not doing that before submitting reverse orders that may cause a problem.

        Comment


          #5
          Ok talking it out and then stripping down a simplified solution led me to what I believe is the root cause. Which I started investigating based on your comment about the cancel and close needing to be sequenced.

          When submitting orders on an account the bracket order must be placed after the market order is filled. If the market order is still in some sort of pending state and both end up pending the system rejects it thinking there are too many contracts in flight. Similar to the cancel and flatten I need to cancel pending orders, wait, and then close my position, I cannot do both at the same time.

          I would think I should be able to place the market order and the bracket orders or the cancel orders at the same time, but maybe there's a reason those order effectively get double counted?

          I'm unblocked, so thank you! I'm just curious as to why those cannot be placed at the same time.

          Comment


            #6
            Hello Blaze212,

            When working with live accounts or even the sim account you need to account for delay between you and the other party, events need to finish before you try doing other actions. If you have a market order that has not filled when you try and do another action you are doing too much at once which will show up differently than if the market order filled and then you did another action.

            The general flow of scripts would be to use the order events to dictate what happens in logic instead of doing things all at once, for example you submit an entry and wait for its execution event to know it filled. Once that fills you submit targets. Once a target is cancelled or filled you look for that execution or OnOrderUpdate event to do the next task and so on. There aren't any cases where you do multiple actions from within a single condition because that will not be the same process to the broker.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            55 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            37 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            17 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            19 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            49 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X