Code:
// reinvest the square root of your portfolio component profits, separately for long and short trades
if(GoLong)
Margin = OptimalFLong * Capital * sqrt(1 + (WinLong-LossLong)/Capital);
else
Margin = OptimalFShort * Capital * sqrt(1 + (WinShort-LossShort)/Capital);
// reinvest the square root of your portfolio component profits
Margin = OptimalFLong * Capital * sqrt(1 + ProfitClosed/Capital);
// reinvest the square root of your total profits
Margin = OptimalFLong * Capital * sqrt(1 + (WinTotal-LossTotal)/Capital);