trader_bbands

(PECL trader >= 0.2.0)

trader_bbandsBollinger Bands

说明

trader_bbands(
    array $real,
    int $timePeriod = ?,
    float $nbDevUp = ?,
    float $nbDevDn = ?,
    int $mAType = ?
): array

参数

real

浮点数数组。

timePeriod

Number of period. Valid range from 2 to 100000.

nbDevUp

Deviation multiplier for upper band. Valid range from TRADER_REAL_MIN to TRADER_REAL_MAX.

nbDevDn

Deviation multiplier for lower band. Valid range from TRADER_REAL_MIN to TRADER_REAL_MAX.

mAType

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

返回值

Returns an array with calculated data or false on failure.

添加备注

用户贡献的备注 1 note

up
8
geekgirl dot joy at gmail dot com
3 years ago
<?php

// According to Wikipedia and the internet:
// Bollinger Bands chart the price and volatility of a financial instrument over time
// and yield an "envelope" minimum and maximum and middle "bands" of moving averages
// which provide a relative definition of high and low market prices
// Prices are "high" at or near the upper band and "low" at or near the lower band.
// Bollinger Bands are considered useful for pattern recognition

$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);
$time_period = 5;
$upper_deviation_multiplier = 2.0;
$lower_deviation_multiplier = 2.0;

$ma_type = TRADER_MA_TYPE_SMA; // Simple Moving Average
//TRADER_MA_TYPE_EMA - Exponential Moving Average
//TRADER_MA_TYPE_WMA - Weighted Moving Average
//TRADER_MA_TYPE_DEMA - Double Exponential Moving Average
//TRADER_MA_TYPE_TEMA - Triple Exponential Moving Average
//TRADER_MA_TYPE_TRIMA - Triangular Moving Average
//TRADER_MA_TYPE_KAMA - Kaufman's Adaptive Moving Average
//TRADER_MA_TYPE_MAMA - MESA Adaptive Moving Average
//TRADER_MA_TYPE_T3) - T3 Moving Average


var_dump(trader_bbands($closes, $time_period, $upper_deviation_multiplier, $lower_deviation_multiplier, $ma_type));

// Index 0 is "upper" band.
// Index 1 is "middle" band.
// Index 2 is "lower" band.

/*
array(3) {
[0]=>
array(10) {
[4]=>
float(118.025)
[5]=>
float(118.401)
[6]=>
float(116.739)
[7]=>
float(117.153)
[8]=>
float(118.563)
[9]=>
float(116.676)
[10]=>
float(113.996)
[11]=>
float(113.114)
[12]=>
float(112.577)
[13]=>
float(113.892)
}
[1]=>
array(10) {
[4]=>
float(114.197)
[5]=>
float(114.741)
[6]=>
float(113.703)
[7]=>
float(113.073)
[8]=>
float(112.041)
[9]=>
float(110.986)
[10]=>
float(110.24)
[11]=>
float(109.238)
[12]=>
float(108.814)
[13]=>
float(109.902)
}
[2]=>
array(10) {
[4]=>
float(110.369)
[5]=>
float(111.081)
[6]=>
float(110.667)
[7]=>
float(108.993)
[8]=>
float(105.519)
[9]=>
float(105.296)
[10]=>
float(106.484)
[11]=>
float(105.362)
[12]=>
float(105.051)
[13]=>
float(105.912)
}
}
*/
To Top