trader_ma

(PECL trader >= 0.2.0)

trader_maMoving average

Description

trader_ma(array $real, int $timePeriod = ?, int $mAType = ?): array

Parameters

real

Array of real values.

timePeriod

Number of period. Valid range from 2 to 100000.

mAType

Type of Moving Average. TRADER_MA_TYPE_* series of constants should be used.

Return Values

Returns an array with calculated data or false on failure.

add a note

User Contributed Notes 1 note

up
0
geekgirl dot joy at gmail dot com
3 years ago
<?php
$closes
= array(112.82, 117.32, 113.49, 112, 115.355, 115.54, 112.13, 110.34, 106.84, 110.08, 111.81, 107.12, 108.22, 112.28);

var_dump(trader_ma($closes, 3, TRADER_MA_TYPE_SMA));

/*
array(12) {
[2]=>
float(114.543) // (112.82 + 117.32 + 113.49) / 3 = 114.54333333333
[3]=>
float(114.27) // (117.32 + 113.49 + 112) / 3 = 114.27
[4]=>
float(113.615) // (113.49 + 112 + 115.355) / 3 = 113.615
[5]=>
float(114.298) // (112 + 115.355 + 115.54) / 3 = 114.29833333333
[6]=>
float(114.342) // (115.355 + 115.54 + 112.13) / 3 = 114.34166666667
[7]=>
float(112.67) // (115.54 + 112.13 + 110.34) / 3 = 112.67
[8]=>
float(109.77) // (112.13 + 110.34 + 106.84) / 3 = 109.77
[9]=>
float(109.087) // (110.34 + 106.84 + 110.08) / 3 = 109.08666666667
[10]=>
float(109.577) // (106.84 + 110.08 + 111.81) / 3 = 109.57666666667
[11]=>
float(109.67) // (110.08 + 111.81 + 107.12) / 3 = 109.67
[12]=>
float(109.05) // (111.81 + 107.12 + 108.22) / 3 = 109.05
[13]=>
float(109.207) // (107.12 + 108.22 + 112.28) /3 = 109.20666666667
}
*/
To Top