The trader_ema() function works correctly if you understand what the second argument is. The second argument is used to group the values into overlapping periods. Within the periods, the numbers undergo a simple average calculation.
So if you call trader_ema($array, 6), and your array only has six values, you're going to get back a simple average, because there is no previous data to weight the value.
If you call trader_ema($array, 3), then your six array values will be grouped into four overlapping groups of three, and you'll get back four values, each representing the EMA for that period.
Below is the output of trader_ema(array(1,2,2,1,3,4), 3) and trader_sma(array(1,2,2,1,3,4), 3). You can see the first value is the same for both the EMA and SMA calculations.
trader_ema(array(1,2,2,1,3,4), 3)
array(4) {
[2]=>
float(1.6666666667)
[3]=>
float(1.3333333333)
[4]=>
float(2.1666666667)
[5]=>
float(3.0833333333)
}
trader_sma(array(1,2,2,1,3,4), 3)
array(4) {
[2]=>
float(1.6666666667)
[3]=>
float(1.6666666667)
[4]=>
float(2)
[5]=>
float(2.6666666667)
}