1

I get similar MACD and Signal values, using the following class in Binance:

I got this code from:

https://github.com/hurdad/doo-forex/blob/master/protected/class/Technical%20Indicators/MACD.php

How can I modify the class to arrive at the exact value?

halfer
  • 19,824
  • 17
  • 99
  • 186
yancha
  • 27
  • 3
  • Hi, can you provide information on the inputs you're sending to this library? – Noah Solomon Jan 22 '19 at 20:24
  • They do not look like good classes. Static methods, clumsy file and folder naming, poor commit messages, not under active maintenance, no tests. However, you can use them if you must - have you tried creating your own class to extend from this one? – halfer Jan 22 '19 at 22:05

2 Answers2

1

You can use the php-trader lib, note that it works as CLI only.

But this is fairly simple math:

MACD = EMA26 - EMA12

enter image description here

enter image description here

NVRM
  • 11,480
  • 1
  • 88
  • 87
-4

/* * Exponential moving average (EMA) * * The start of the EPA is seeded with the first data point. * Then each day after that: * EMAtoday = α⋅xtoday + (1-α)EMAyesterday * * where * α: coefficient that represents the degree of weighting decrease, a constant smoothing factor between 0 and 1. * * @param array $numbers * @param int $n Length of the EPA * @return array of exponential moving averages */

function exponentialMovingAverage( $numbers, $n)
{
$m   = count($numbers);
$α   = 2 / ($n + 1);
$EMA = [];

// Start off by seeding with the first data point
$EMA[] = $numbers[0];

// Each day after: EMAtoday = α⋅xtoday + (1-α)EMAyesterday
for ($i = 1; $i < $m; $i++) {
$EMA[] = ($α * $numbers[$i]) + ((1 - $α) * $EMA[$i - 1]);
}

return $EMA;}
  • 1
    this is EMA formula and looks like copied from here https://stackoverflow.com/questions/39444699/exponential-moving-average-in-php – aiternal Jun 23 '20 at 19:36