0

I just installed TA-Lib / trader into my php installation and it's good to go. My PHP isn't great and even with the trader documentation I just need a bit of guidance. I want to load an array of values from my database and send them into "trader_sma" to get the small moving average. My pseudo code will look something like:

<?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 ] )


?>

Any help appreciated. Thanks.

user3515232
  • 133
  • 2
  • 12

1 Answers1

3

$real will be the values you are inputting and $timePeriod is an integer that specifies the length of the moving average.

Therefore you would use the function like this:

$real = array(12,15,17,19,21,25,28,12,15,16);
$timePeriod = 3;
$data = trader_sma($real,$timePeriod);
var_dump($data);

The output will be array of a three increment moving average...

12 + 15 + 17 = 34 34 / 3 = 11.333

array(float 11.333,
      float 17, etc...
M H
  • 2,179
  • 25
  • 50
Jed Lynch
  • 1,998
  • 18
  • 14