Standard Deviation function used in original Bollinger Bands function of TA-Lib is not correct.
You can see it in this image for BB(Close, 3, 2.4).
I have implemented my own bbands function in PHP while using TA-Lib trading library.
function trader_bbands2($_data, $_period, $_dev)
{
$sma = trader_sma($_data, $_period);
$counter = count($_data);
for ($i = $_period; $i < $counter; $i++)
{
$stddev = standard_deviation(array_slice($_data, $i - $_period, $_period), $_period);
$bb[0][$i - 1] = $sma[$i - 1] + ($stddev * $_dev);
$bb[1][$i - 1] = $sma[$i - 1];
$bb[2][$i - 1] = $sma[$i - 1] - ($stddev * $_dev);
}
return $bb;
}
Last edited by ZorroHispano; 09/01/20 15:59.