upperBB(), middleBB(), lowerBB() Built-in Study Functions
The Bollinger Band studies (created by John Bollinger) are similar to moving average envelopes. The difference between Bollinger Bands and envelopes is that envelopes are plotted at a fixed percentage above and below a moving average, whereas Bollinger Bands are plotted at standard deviation levels above and below a moving average. Since standard deviation is a measure of volatility, the bands are self-adjusting, widening during volatile markets and contracting during calmer periods.
Syntax
upperBB( nLength , nStdev [, Series | sym() | inv() ][, nBarIndex ] )
middleBB( nLength , nStdev [, Series | sym() | inv() ][, nBarIndex ] )
lowerBB ( nLength , nStdev [, Series | sym() | inv() ][, nBarIndex ] )
Parameters
Parameter: | Description: | Default: |
nLength | Required. Number of periods to use for calculation. | n/a |
nStdev | Required. Number of standard deviations to use for calculation. | n/a |
Series or sym() or inv() |
[Optional] Series Object or function of sym() or inv() to determine symbol/interval source for the study. | Chart's sym/inv |
nBarIndex | [Optional] Bar index of series to retrieve . | n/a |
Return Value(s)
Returns a Series Object when nBarIndex is not specified.
Returns a single value when nBarIndex is specified.
Notes
Only available in versions 7.9 or later.
Code Examples
function main() { return new Array(upperBB(20, 2), middleBB(20, 2), lowerBB(20, 2)); }
function main() { return new Array( upperBB(20, 2, hl2()), middleBB(20, 2, hl2()), lowerBB(20, 2, hl2()) ); }
Retrieve single values:
function main() { var nValue_0 = middleBB(20, 2, 0); // Current Bar Index var nValue_1 = middleBB(20, 2, -1); // Prior Bar Index return new Array(nValue_0, nValue_1); }
//global Series Object variables var xStudy1 = null; var xStudy2 = null; var xStudy3 = null; function main() { if (xStudy1 == null) xStudy1 = upperBB(20, 2); if (xStudy2 == null) xStudy2 = middleBB(20, 2); if (xStudy3 == null) xStudy3 = lowerBB(20, 2); // retrieve single values for conditional statements var nValue1_0 = xStudy1.getValue(0); // Current Bar Index value var nValue2_0 = xStudy2.getValue(0); // Current Bar Index value var nValue3_0 = xStudy3.getValue(0); // Current Bar Index value var nValue1_1 = xStudy1.getValue(-1); // Prior Bar Index value // Plot Current Bar Index Value return new Array(nValue1_0, nValue2_0, nValue3_0); }
// global Series Object variables var xStudy1 = null; var xStudy2 = null; var xStudy3 = null; var bInit = false; // Initialization flag function main() { if (bInit == false) { xStudy1 = upperBB(20, 2, inv(20)); // 20-min interval xStudy2 = middleBB(20, 2, inv(20)); // 20-min interval xStudy3 = lowerBB(20, 2, inv(20)); // 20-min interval bInit = true; } // retrieve single values for conditional statements var nValue1_0 = xStudy1.getValue(0); // Current Bar Index value var nValue1_1 = xStudy1.getValue(-1); // Prior Bar Index value // Synchronized Series plot return new Array(getSeries(xStudy1), getSeries(xStudy2), getSeries(xStudy3)); }
// global Series Object variables var xStudy1 = null; var xStudy2 = null; var xStudy3 = null; var bInit = false; // Initialization flag function main() { if (bInit == false) { xStudy1 = upperBB(20, 2, sym("IBM,20")); // IBM 20-min interval xStudy2 = middleBB(20, 2, sym("IBM,20")); // IBM 20-min interval xStudy3 = lowerBB(20, 2, sym("IBM,20")); // IBM 20-min interval bInit = true; } // retrieve single values for conditional statements var nValue1_0 = xStudy1.getValue(0); // Current Bar Index value var nValue1_1 = xStudy1.getValue(-1); // Prior Bar Index value // Synchronized Series plot return new Array(getSeries(xStudy1), getSeries(xStudy2), getSeries(xStudy3)); }
See Also
Series Object
getSeries()
Built-in Study Functions
eSignal Forum Search Engine
Help Guides and Tutorials