Source for StandardDev function

Questions about MultiCharts .NET and user contributed studies.
robbob
Posts: 46
Joined: 26 Jan 2013
Has thanked: 2 times
Been thanked: 3 times

Source for StandardDev function

Postby robbob » 17 Feb 2013

Hi,

I'm attempting to determine why a script I had coded in Wealth-lab is producing different results in Multicharts. I've been able to track the difference to the value of the BollingerBands between the two platforms, and specifically to the StandardDev function in MC that the BollingerBand indicator is using. The function is producing output that is different from both wealth-lab and Microsoft Excel for the price series that I am testing. Is the code for Functions such as StandardDev available? I see a "Functions" folder in the PowerLanguage editor, but it contains no files.

Below is an example calculating std dev of the last 3 closes.

Close prices: $95.23, $95.95, $95.88
Expected standard deviation: 0.397 (reported by Wealth-lab and Excel)
Actual standard deviation: 0.324 (reported by Multi-charts).

Thanks,
-Rob

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Source for StandardDev function

Postby Henry MultiСharts » 20 Feb 2013

Hello Rob,

The source code of the functions has been opened in MultiCharts 8.5 beta. You can download it from this page.

Here is how the Standard Deviation is calculated:
Image
Attachments
StandardDev.PNG
(11.33 KiB) Downloaded 969 times

robbob
Posts: 46
Joined: 26 Jan 2013
Has thanked: 2 times
Been thanked: 3 times

Re: Source for StandardDev function

Postby robbob » 21 Feb 2013

So there are actually 2 different ways to calculate variance and subsequently standard deviation, for a sample and for a population. It looks like MC is using the population based calculation even though the indicators are only calculating their values based on a small subset of the price history, ie the last 5 closes for a 5 period bollinger band.

My guess is that the only way around this problem is to create my own b band indicators that use the Sample variance and standard deviation calculations rather than Population based, unless there's a simpler method.

thanks,
-Rob

User avatar
Analyst
Posts: 19
Joined: 09 Jul 2013
Has thanked: 3 times
Been thanked: 2 times

Re: Source for StandardDev function

Postby Analyst » 10 Sep 2013

Rob, the difference between sample and population standard deviation is whether you divide by N or N-1. So, you can reconcile the MC figure with the Excel figure by squaring it, multiplying by N/(N-1), and taking the square root. Using the figures from your example:

0.324^2 * (3/2) = 0.397^2


Return to “MultiCharts .NET”