{Function _ProSizerQty by Alex Matulich, Unicorn Research Corporation rev 6/2003 This function duplicates the position sizing calculations of the ProSizer Excel tool available at http://unicorn.us.com/trading/prosizer.html Once you have used ProSizer to determine the position sizing model best for your trading, you may call this function in your strategy to determine the number of lots you should trade. If you wish to trade a combination of models such as the maximum of %risk and %volatility, simply call this function for each model and combine the results in your strategy. } Inputs: PSmodel(NumericSimple), {Position sizing model: 1 = fixed lot 2 = fixed fraction 3 = fixed ratio 4 = percent risk 5 = percent volatility see http://unicorn.us.com/trading/prosizerdoc.html for a description of each model} startEquity(NumericSimple), {starting equity in dollars} param1(NumericSimple), {parameter 1 for position sizing model model1 (fixed lot): number of lots model2 (fixed fraction): % of equity (0-100) model3 (fixed ratio): 10000/delta model4 (%risk): risk % of equity (0-100) model5 (%volatility): volatility % of equity (0-100)} param2(NumericSimple); {parameter 2 for position sizing model model1 (fixed lot): 0 model2 (fixed fraction): 0 model3 (fixed ratio): initial number of lots model4 (%risk): mkt units risked (initial stop size) model5 (%volatility): market volatility at entry in mkt units} vars: qty(0), equity(0); equity = startEquity + NetProfit; if marketposition <> 0 then equity = equity + PositionProfit; if PSmodel = 1 then {fixed lot size} qty = param1 else if PSmodel = 2 then {fixed fraction of equity} qty = IntPortion(equity * 0.01*param1 / margin + 0.5) else if PSmodel = 3 then begin {fixed ratio} qty = 2 * NetProfit * 0.0001*param1 + 0.25 + param2 * param2 - 1; if qty < 0 then qty = 0; qty = MaxList(1, IntPortion(SquareRoot(qty) + 0.5)); end else if PSmodel = 4 then {percent risk} qty = IntPortion(equity * 0.01*param1 / (param2*BigPointValue) + 0.5) else if PSmodel = 5 then {percent volatility} qty = IntPortion(equity * 0.01*param1 / (param2*BigPointValue) + 0.5); _ProSizerQty = qty;