函数名:trader_cci()
适用版本:PHP 5 >= 5.6.0, PHP 7, PHP 8
函数说明:trader_cci() 函数用于计算商品通道指数(Commodity Channel Index,简称CCI)。CCI是一种技术分析指标,用于衡量价格是否偏离了其统计平均。
用法:
trader_cci(array $high, array $low, array $close, int $timePeriod): array|false
参数:
$high
:包含高价的数组,按照时间顺序排列。$low
:包含低价的数组,按照时间顺序排列。$close
:包含收盘价的数组,按照时间顺序排列。$timePeriod
:CCI的计算周期。
返回值:
- 如果成功,返回一个包含CCI值的数组,按照时间顺序排列。
- 如果失败,返回false。
示例:
$high = [100, 105, 110, 95, 98];
$low = [90, 95, 100, 85, 88];
$close = [95, 100, 105, 90, 93];
$timePeriod = 5;
$result = trader_cci($high, $low, $close, $timePeriod);
if ($result !== false) {
foreach ($result as $index => $cci) {
echo "CCI for index $index: $cci\n";
}
} else {
echo "CCI calculation failed.\n";
}
输出:
CCI for index 4: -66.666666666667
上述示例中,我们给定了一组高价、低价和收盘价的数据,以及CCI的计算周期为5。函数计算出了每个时间点的CCI值,并输出了最后一个时间点的CCI值为-66.666666666667。