Bollinger Bands |
Top Previous Next |
upperBB( length, stdDev [, source | sym() | inv()] [, barIndex] ) middleBB( length, stdDev [, source | sym() | inv()] [, barIndex] ) lowerBB( length, stdDev [, source | sym() | inv()] [, barIndex] )
Bollinger Bands (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.
Parameters
To Create a Series
var myStudy1 = null; var myStudy2 = null; var myStudy3 = null; var bInit = false;
function main() { var myVar1; var myVar2; var myVar3;
if ( bInit == false ) {
myStudy1 = upperBB( 20, 2 ); myStudy2 = middleBB( 20, 2 ); myStudy3 = lowerBB( 20, 2 );
bInit = true;
}
//retrieve the current values myVar1 = myStudy1.getValue(0); myVar2 = myStudy2.getValue(0); myVar3 = myStudy3.getValue(0);
return new Array( myVar1, myVar2, myVar3 );
}
To Retrieve a Single Value
function main() {
... ... myVar = middleBB( 10, 1.5 );
//do something with the value in myVar
}
Calling Examples
//create a study that uses IBM as the symbol along with whatever bar //interval you are using in the chart where the script is loaded myStudy = middleBB( 20, 2, sym( "IBM") );
//create a study that uses the 15-min bar interval, regardless of the bar //interval of the chart in which the script is loaded myStudy = upperBB( 20, 2, inv(15) );
//create a study that uses the Daily bar interval, regardless of the bar //interval of the chart in which the script is loaded myStudy = lowerBB( 10, 1.5, inv("D") );
//create a study that will be based on MSFT 30-min bars, regardless of //the symbol/bar interval of the chart in which the script is loaded myStudy = middleBB( 20, 1, sym( "MSFT,30" ) );
//create a study that will be based on the high. myStudy = middleBB( 10, 2, high() );
//create a study that will be based on the close, using 15-min bars, regardless of //the bar interval of the chart in which the script is loaded myStudy = upperBB( 12, 2, close( inv(15) ) );
|