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...

Comment