I am trying to use PHPs trader functions (available as a PECL extension) to calculate the moving average convergence/divergence (MACD) of various securities. However, the va
I don't know PHP, but I can explain ta-lib behavior from C/C++ perspective. I've debugged its MACD with your dataset. If you call ta-lib's C function ta_macd()
for your data you'll get following.
macd signal hist
-3.08486 0.869685 -3.95455
-3.4801 -0.000272319 -3.47983
-3.05529 -0.611275 -2.44401
-2.79613 -1.04825 -1.74788
-2.92258 -1.42311 -1.49947
-3.78208 -1.89491 -1.88718
-3.90264 -2.29645 -1.60619
-5.82247 -3.00166 -2.82082
-8.11782 -4.02489 -4.09293
-9.9449 -5.20889 -4.73601
-10.6137 -6.28985 -4.32385
-10.4216 -7.11621 -3.30543
-10.2058 -7.73414 -2.47171
-9.68753 -8.12482 -1.56272
-8.46746 -8.19335 -0.274115
-6.38441 -7.83156 1.44715
-3.66972 -6.99919 3.32947
-1.77941 -5.95524 4.17582
0.218855 -4.72042 4.93927
2.13774 -3.34879 5.48653
4.47273 -1.78448 6.25722
6.08764 -0.210058 6.2977
7.69672 1.3713 6.32543
8.3057 2.75818 5.54752
8.38504 3.88355 4.50149
8.49283 4.80541 3.68743
7.61258 5.36684 2.24574
5.6388 5.42123 0.217565
4.48522 5.23403 -0.748811
3.42501 4.87223 -1.44722
3.32672 4.56312 -1.23641
2.95095 4.24069 -1.28974
2.75772 3.9441 -1.18637
It doesn't match your excel file bcs of following:
=AVERAGE(B19:B30)
in cell C30
and the excel results will match with C function results.E38-G70
.Well, that's how TA-Lib works as far as I can see. But if you compare my results with your PHP function results you'll find that they doesn't match too. But you can notice that my MACDs are equal to values in your 1st array starting from
[33]=>
float(-3.085)
And if you compare PHP results with Excel (updated) you'll find that first elements of 1st array are equal to E30-E37
. These are first 8 MACDs that TA-Libs omits as they don't have corresponding signal\hist values bcs signal is calculated with 9-days EMA. It also means following:
I would recommend looking inside PHP function source code. I couldn't find it. If you want to doublecheck vanilla C implementation of MACD in ta-lib, you shall refer to following pages: macd, ema.