Try the following (based on Method 2 found here:
http://www.easycalculation.com/statistics/learn-standard-deviation.php
<http://www.easycalculation.com/statistics/learn-standard-deviation.php>
).
Note that if you're trying to compare to Van Tharp, he uses the minimum
of 100 and number of trades. Otherwise, use the number of trades as in
your original post:
for (trade = bo.getFirstTrade(); trade; trade = bo.getNextTrade()) {
R = ...;
trades++;
sumR += R;
sumR2 += R^2;
}
if (trades > 0) {
expectancyR = sumR / trades;
stdDevR = sqrt((sumR2 - (sumR^2 / trades)) / (trades - 1));
SQN = ((expectancyR / stdDevR) * sqrt(min(100, trades)));
}
Mike
--- In [email protected], "jeffarcherjr" <jeffarche...@...>
wrote:
>
> Can anyone tell me how to calculate system quality number in a custom
backtest proc?
>
> I understand the math and the formula
>
> SQN = (Expectancy/Standard Deviation R) - SqRoot(Number of trades)
>
> Where I'm stuck is how to calculate the Standard Deviation of R within
a CustomBacktestProc?
>
> If this has been discussed before perhaps someone could point me to
the post, but I've not found anything with searches of the message
boards.
>
> Many Thanks
>
> Jeff
>