Function Prototype
/* Bollinger Bands */
/* Type: overlay */
/* Input arrays: 1 Options: 2 Output arrays: 3 */
/* Inputs: real */
/* Options: period, stddev */
/* Outputs: bbands_lower, bbands_middle, bbands_upper */
int ti_bbands_start(TI_REAL const *options);
int ti_bbands(int size,
TI_REAL const *const *inputs,
TI_REAL const *options,
TI_REAL *const *outputs);
Description
This documentation is still a work in progress. It has omissions, and it probably has errors too. If you see any issues, or have any general feedback, please get in touch.
The Bollinger Bands indicator calculates three results. A middle band, which is a Simple Moving Average, as well as upper and lower bands which are spaced off the middle band.
It takes two parameters: the period n
, as well as a scaling value a
. The upper and lower
bands are spaced off of the middle band by a
standard deviations of the input.
$$bbands^{middle}_{t} = \frac{1}{n} \sum_{i=0}^{n-1} in_{t-i}$$
$$bbands^{lower}_{t} = bbands^{middle}_{t} - a \sqrt {\frac{1}{n} \sum_{i=0}^{n-1} (in_{t-i}-bbands^{middle}_{t})^{2}}$$
$$bbands^{upper}_{t} = bbands^{middle}_{t} + a \sqrt {\frac{1}{n} \sum_{i=0}^{n-1} (in_{t-i}-bbands^{middle}_{t})^{2}}$$
See Also
References
- Bollinger, John A. (2001) Bollinger on Bollinger Bands
- Murphy, J. (1999) Technical Analysis of the Financial Markets
- Achelis, S. (2000) Technical Analysis from A to Z, 2nd Edition
Example Usage
Calling From C
/* Example usage of Bollinger Bands */
/* Assuming that 'input' is a pre-loaded array of size 'in_size'. */
TI_REAL *inputs[] = {input};
TI_REAL options[] = {5, 2}; /* period, stddev */
TI_REAL *outputs[3]; /* bbands_lower, bbands_middle, bbands_upper */
/* Determine how large the output size is for our options. */
const int out_size = in_size - ti_bbands_start(options);
/* Allocate memory for each output. */
outputs[0] = malloc(sizeof(TI_REAL) * out_size); assert(outputs[0] != 0); /* bbands_lower */
outputs[1] = malloc(sizeof(TI_REAL) * out_size); assert(outputs[1] != 0); /* bbands_middle */
outputs[2] = malloc(sizeof(TI_REAL) * out_size); assert(outputs[2] != 0); /* bbands_upper */
/* Run the actual calculation. */
const int ret = ti_bbands(in_size, inputs, options, outputs);
assert(ret == TI_OKAY);
Calling From Lua (with Tulip Chart bindings)
-- Example usage of Bollinger Bands
bbands_lower, bbands_middle, bbands_upper = ti.bbands(input, 5, 2)
Example Calculation
period = 5, stddev = 2
date | input | bbands_lower | bbands_middle | bbands_upper |
---|---|---|---|---|
2005-11-01 | 81.59 | |||
2005-11-02 | 81.06 | |||
2005-11-03 | 82.87 | |||
2005-11-04 | 83.00 | |||
2005-11-07 | 83.61 | 80.53 | 82.43 | 84.32 |
2005-11-08 | 83.15 | 80.99 | 82.74 | 84.49 |
2005-11-09 | 82.84 | 82.53 | 83.09 | 83.66 |
2005-11-10 | 83.99 | 82.47 | 83.32 | 84.16 |
2005-11-11 | 84.55 | 82.42 | 83.63 | 84.84 |
2005-11-14 | 84.36 | 82.44 | 83.78 | 85.12 |
2005-11-15 | 85.53 | 82.51 | 84.25 | 86.00 |
2005-11-16 | 86.54 | 83.14 | 84.99 | 86.85 |
2005-11-17 | 86.89 | 83.54 | 85.57 | 87.61 |
2005-11-18 | 87.77 | 83.87 | 86.22 | 88.57 |
2005-11-21 | 87.29 | 85.29 | 86.80 | 88.32 |
Chart
Other Indicators
Previous indicator: Average Price
Next indicator: Balance of Power
Random indicator: Detrended Price Oscillator
Copyright © 2016-2024 Tulip Charts LLC. All Rights Reserved.