### Description

array trader_ema ( array `\$real` [, int `\$timePeriod` ] )

### Parameters

`real`

Array of real values.

`timePeriod`

Number of period. Valid range from 2 to 100000.

### Return Values

Returns an array with calculated data or false on failure.

### User Contributed Notes 4 notes

abovesense at hotmail dot com
3 years ago
``` Hello there,Is someone have tried the function and can tell what is the return size digits after the decimal point, meaning what is the precision of the returned  answer ?Best,laye ```
kazemi dot milad at gmail dot com
1 month ago
``` trader_ema in wrong calculate value this return just simple moving avrage for get ema correct use this code\$number is data array and \$n is number of periodexample:\$number[0]    => last value\$number[n]    =>first valuefunction exponentialMovingAverage(array \$numbers, int \$n): array{    \$numbers=array_reverse(\$numbers);    \$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]);    }    \$EMA=array_reverse(\$EMA);    return \$EMA;} ```
Ash Christos
1 month ago
``` This method works fine. If you're finding that the EMA and SMA results are the same, the precision setting might still be the default or not tuned to your use case. (For example floats with more than 3 levels, sathoshi's, etc) # this is needed for 0.00XXXXZ levelsini_set( 'trader.real_precision', '8' ); ```
-7
manoj dot monu23 at gmail dot com
4 years ago
``` the trader_ema() function does'nt work correctly , it calculate just average of last period entries. Follow the following code for trader_ema: function EMACalculator(\$limit,\$array){    \$EMA_previous_day = \$array[0];    //print_r(\$array);    \$multiplier1 = (2/\$limit+1);    \$EMA[]=array();    \$EMA = \$array[0];    \$Close= \$array[1];        while(\$limit){        //echo"EMA is \$EMA\n";    \$EMA = (\$Close - \$EMA_previous_day) * \$multiplier1 + \$EMA_previous_day;    \$EMA_previous_day= \$EMA;        \$limit--;}return \$EMA;}where \$limit accept the period of ema  and \$array : accept array of data for ema calculation. ```