Tracking number of open position per algo

I am writing an automated trading script which I want to use in every algo that I have, which will use IBController.

Is there a way that I can know how many open positions are there for a specific algorithm? I may have 5 different algorithms running on the same account. The reason I need this is because I want to fire the algos from the explorer and I want to limit the number of open positions per algo according to my backtest results.

I think I need some persistent data because I assume that I need to get the data somehow from Interactive Brokers (Let's say for example that Amibroker or TWS exit for some reason, I want the data to be available when I open them again)

1 Like

You need to track it yourself from the formula using static variables and orderIDs returned by TWS.

Read about static variables in the Users Guide.

Also old Users' KB contains lots of example codes: AmiBroker Users' Knowledge Base

Thank you very much. i understand the solution. however something thet idid not see in the static Variable documentation is the mention of persistence.
In case Amibroker closes or my pc restarts, will the static variables stillremember their value?

It's mentioned in this doc: StaticVarSet.

Starting from version 5.80 there is a new parameter persist . If it is set to True then static variable will be stored in PersistVars.bin file when AmiBroker is closing and reloaded automatically on next startup, preserving the values of static variables between application runs).