But something strange happens in realtime
slimit = (account_value + unrealized_profit)/800;
if ( some condition )
EnterLong(slimit);
if (some condition)
EnterShort(slimit)
(10 min chart)
Lets say I have $5000 is account it calculates and sold 6 contracts and then I take a loss of $1500 and my contracts (slimit) goes down to 4 , Condition switches from SHORT to LONG on the next bar.
On execution I show this realtime: ( got this from Onexecution() )
On execution of EnterLong(slimit) which is 4 now , and was short earlier with 6 contracts
6 CONTACTS CLOSE POSITON
6 CONTRACTS BUY TO COVER
4 CONTACTS BUY
in the end I have 10 contracts on buy side , which is wrong I should have 4 contracts on buy side.
but It shows correctly like this in simulation.
6 CONTRACTS BUY TO COVER
4 CONTACTS BUY
in the end 4 contracts buy side which is correct-----
so my question is why and how to avoid this , so while I switch I always get on the buy side with correct number of contracts .
I have dynamic script which keeps on adding and reducing contracts based on account value , all works well except this.
Comment