note 123902 added to function.trader-ema
| From: | andy at siliconrockstar dot com | Date: | Sat, 01 Jun 2019 20:00:47 +0000 |
| Subject: | note 123902 added to function.trader-ema | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211161@lists.php.net to get a copy of this message | ||
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)
}
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.34 (proxied: 47.184.86.141)
----
Manual Page -- http://php.net/manual/en/function.trader-ema.php
Edit -- https://master.php.net/note/edit/123902
Del: integrated -- https://master.php.net/note/delete/123902/integrated
Del: useless -- https://master.php.net/note/delete/123902/useless
Del: bad code -- https://master.php.net/note/delete/123902/bad+code
Del: spam -- https://master.php.net/note/delete/123902/spam
Del: non-english -- https://master.php.net/note/delete/123902/non-english
Del: in docs -- https://master.php.net/note/delete/123902/in+docs
Del: other reasons-- https://master.php.net/note/delete/123902
Reject -- https://master.php.net/note/reject/123902
Search -- https://master.php.net/manage/user-notes.php