If a trade closed with positive PNL, add the PNL $ amount to account value variable and then use updated account value to calculate new quantity of shares for the next trade.
If a trade closed with negative PNL, do not update account value.
The problem is that my strategy is always long or short. For example, lets lets say we trade price and 200ma crossover. Suppose the price is below 200ma and I have been short, now the price crosses above and I have two trades instantaneously: 1) close the short 2) initiate the long.
However, before the long order is sent out, I want to add the PNL from my short trade, get updated account value, and then recalculate the number of shares to trade (so its always the same % of the account valule), and only then, initiate the long.
I tried onorderupdate() and onexecutionupdate() and went thru a dozen of code variations but cant achieve the recalculation to happen between trades (so the part in italics). I think its because the trades are basically sent instantaneously and the system doesnt have time to do calculations in between
Does anyone have any advice on how to solve it?
Ideally, if someone could edit the template sma crossever startegy that NT provides, to achieve proper order execution like described above, that would be truly amazing! I imagine for someone who knows how to do it it will take 1-2 minutes..

Comment