我刚刚在我的php安装中安装了TA-Lib / trader,这很不错。我的PHP并不好,甚至在交易者文档中我只需要一点指导。我想从我的数据库中加载一组值并将它们发送到" trader_sma"得到小的移动平均线。我的伪代码看起来像:
<?php
$finance = $dbrequest("SELECT close_price FROM market_table WHERE stock='$symbol');
//So now $finance is an array with all of the stocks closing prices
//how do I place it into this function? I also need to 'count' the rows in
//the array to send them into $timePeriod?
//array trader_sma ( array $real [, integer $timePeriod ] )
?>
任何帮助表示赞赏。谢谢。
答案 0 :(得分:2)
$real
将是您输入的值,$timePeriod
是一个整数,用于指定移动平均线的长度。
因此你可以使用这样的函数:
$real = array(12,15,17,19,21,25,28,12,15,16);
$timePeriod = 3;
$data = trader_sma($real,$timePeriod);
var_dump($data);
输出将是三个增量移动平均线的数组......
12 + 15 + 17 = 34 34/3 = 11.333
array(float 11.333,
float 17, etc...