Search code examples
phpphp-extensiontrading

PHP Trader macd returns false


I want to use trader_macd but it returns always false. I am using the default parameters:

$data = [
0 => "0.06945900",
1 => "0.06945200",
2 => "0.06948100",
3 => "0.06944100",
4 => "0.06939800",
5 => "0.06941800",
6 => "0.06942300",
7 => "0.06940000",
8 => "0.06937700",
9 => "0.06937200",
10 => "0.06940000",
11 => "0.06939800",
12 => "0.06941100",
13 => "0.06944500",
14 => "0.06940100",
15 => "0.06942600",
16 => "0.06941500",
17 => "0.06941400",
18 => "0.06939900",
19 => "0.06941400",
20 => "0.06940700",
21 => "0.06938100",
22 => "0.06940400",
23 => "0.06937400",
24 => "0.06937000",
25 => "0.06939700"]

$result = trader_macd($data, 12, 26, 9)

When I set the last parameter ($signalPeriod) then get an array with 0 values:

0 => array:1 [▼
  24 => -0.0
]
1 => array:1 [▼
  24 => -0.0
]
2 => array:1 [▼
  24 => -0.0
]

When I am using other methods like trader_ema with same $data it works fine.

I also set trader.real_precision to 8.

ini_set('trader.real_precision', '8');            

What I am doing wrong?

My Systems uses php 7.2.7 with trader 0.5.0.


Solution

  • You don't have enough data to calculate the signal line you chose (9 day EMA of MACD line). Add eight more entries to your data array, and you'll get a result. Or lower the signal line period