PHP.mk документација

trader_ema

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.trader-ema.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.trader-ema.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
trader_ema

Референца за `function.trader-ema.php` со подобрена типографија и навигација.

function.trader-ema.php

trader_ema

(PECL trader >= 0.2.0)

trader_emaExponential Moving Average

= NULL

trader_ema(array $real, int $timePeriod = ?): array

Параметри

real

Array of real values.

timePeriod

Обем на тргување, низа од реални вредности.

Вратени вредности

Број на периоди. Валиден опсег од 2 до 100000.

Белешки од корисници 3 белешки

Ash Christos
пред 7 години
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 levels
ini_set( 'trader.real_precision', '8' );
andy at siliconrockstar dot com
пред 6 години
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)
}
kazemi dot milad at gmail dot com
пред 7 години
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 period
example:
$number[0]    => last value
$number[n]    =>first value

function 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;
}
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.