函数名: trader_bbands()
适用版本: PHP 5 >= 5.6.0, PHP 7, PECL trader >= 0.4.0
用法: trader_bbands($real, $timePeriod = 5, $nbDevUp = 2, $nbDevDn = 2, $mAType = MAType::SMA)
参数:
返回值:返回一个包含上轨、中轨和下轨价格数据的数组。
示例:
$real = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55];
$result = trader_bbands($real, 5, 2, 2, MAType::SMA);
var_dump($result);
输出:
array(3) {
["upperband"]=>
array(5) {
[4]=>
float(35)
[5]=>
float(39.99999999999999)
[6]=>
float(44.999999999999986)
[7]=>
float(49.999999999999986)
[8]=>
float(54.999999999999986)
}
["middleband"]=>
array(5) {
[4]=>
float(25)
[5]=>
float(29.999999999999993)
[6]=>
float(34.999999999999986)
[7]=>
float(39.999999999999986)
[8]=>
float(44.999999999999986)
}
["lowerband"]=>
array(5) {
[4]=>
float(15)
[5]=>
float(19.999999999999993)
[6]=>
float(24.999999999999986)
[7]=>
float(29.999999999999986)
[8]=>
float(34.999999999999986)
}
}
以上示例中,我们使用了一个包含10个价格数据的数组,并调用了trader_bbands()函数来计算布林带。函数的第二个参数设置为5,表示计算5个时间周期的布林带。默认情况下,上轨和下轨的标准差倍数都为2,中轨的移动平均类型为SMA。函数返回一个包含上轨、中轨和下轨价格数据的数组。