In the opening post, you said "CapitalClosed". I don't think this is a real variable.

Capital is an input.

And here's a really good code snippet:
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);



Source: http://www.zorro-trader.com/manual/en/optimalf.htm