after a couple of months I'm running the strategy today happened that, I think due to several platform disconnections, the strategy continued to send to market closing orders like if it didn't recognize they already were sent before.
So at the end instead of find myself long 1 contract I was long 3 contracts with only 1 contract to close the position at target. (yes I was not there, it happened during the nigh and I was sleeping)
It's the first time it happens but platform disconected several times and I never had this kind of problem before...maybe is due to the fact I'm using the 9.5...
anyway in order to prevent such thing again I was thinking to use some kind of protection but I need help to code the variable...and even if figure out something I still have some doubt if can work...can you help?
vars : cont(0) ;
cont = currentcontract ....I should assign a value to this var consider I have no overnight positions.
if currentcontracts > 1 then begin
sell (currentcontract - cont) contract this bar at close ;
you might want to look at the GetPositionQuantity reserved word. This will provide you with the position for a symbol and side (long/short) for the account of choice.
As TS says it might have some issues and is processor intensive, you might want to check the GetPosProvQty function. You can obtain it from the official forums.