Struggling with Account.Flatten in unmanaged mode

Hi

I’m having problems with Account.Flatten in my ‘unmanaged’ strategy in that it is terminating the strategy. Is there anything I can do that will keep my code alive?

I’m executing this:

Account.Flatten(new { Instrument });

Thanks for any help you can give.

PS. I’m unsure why [ and ] are being converted to a box!

1 Like

I could be wrong but my view is that Flatten mimicks the pressing of the Close button in ChartTrader which is why your strategy unloads.

Instead detect position side and Sell/Buy Position.Quantity accordingly

Yeah, that’s what I’ve ended up doing. Not my preferred solution as I have to cater for partial fills, rather than just issue an instruction.

I don’t understand how would Account.Position not take into consideration partial fills?

In my experience the quantity for Buy/Sell doesn’t always get filled as a whole when i do SubmitOrderUnmanaged so I have code that keeps checking and sweeps up and quantity not filled the first time round.

Saw your post about Account.Flatten killing the strategy in unmanaged mode, the engine does that because it tries to clean up the UI state and ends up dropping the whole script thread. Doing manual loops to sweep up partial fills works, but it’s slow and prone to race conditions when the data feed spikes

The clean way to handle this is to build a raw C# state machine that drops the OCO tokens first, then kills the pending orders directly via exchange IDs without hitting NT’s internal validation loops. If you want to skip the trial and error on that wrapper, let me know, I have the unmanaged template ready to plug into your strategy

Thank you, Eduardo

I’ve all but moved away from NT so need has really disappeared.
Good to know that you’ve got a solution, in case I come back to NT.

Thanks again.