Bollinger Bands are a technical trading tool that provide a relative definition of high and low bands.
This sample application calculates a Bollinger Band from securities prices. The Bollinger Band consists of a set of three curves drawn in relation to the securities prices. The middle band is a measure of the intermediate-term moving trend, usually the simple moving average (or exponential moving average), which serves as the base for the upper and lower bands.
The difference between the upper and lower bands and the middle band is determined by the volatility of the securities. The volatility is typically the standard deviation of the same data that is used to calculate moving average. This application uses 20-day periods for the moving average and standard deviation calculations. Two standard deviations are used to compute the upper and lower bands. You can adjust the number of periods and standard deviations in the Aggregate operator and Map operator, respectively, to suit your purposes.
The sample computes the Bollinger Band from a 20-day simple moving average. It also computes the Bollinger Band from 20-day exponential moving average. Simple moving average and exponential moving average are calculated by calling the StreamBase aggregate functions avg() and exp_moving_avg(), respectively. It also calculates values for LastValue, Bandwidth, and PercentB.
MiddleBand: Moving Average (simple or exponential)
UpperBand: Moving Average + (2 * Standard Deviation)
LowerBand: Moving Average - (2 * Standard Deviation)
Bandwidth = (UpperBand - LowerBand)/MiddleBand
PercentB = (LastValue - LowerBand) / (UpperBand - LowerBand)
The application also includes an Excel spreadsheet that displays the bands, plotting them automatically.
In StreamBase Studio, import this sample with the following steps:
From the top-level menu, click> .
bollto narrow the list of options
Select How to calculate Bollinger Band from the Applications category.
StreamBase Studio creates a project for the sample.
To run this sample:
In the Project Explorer view, open the sample you just loaded.
If you see red marks on a project folder, wait a moment for the project to load its features.
If the red marks do not resolve themselves after a minute, select the project, right-click, and select> from the context menu.
BollingerBand.sbappfile and click the Run button. This opens the SB Test/Debug perspective and starts the module.
Open the Feed Simulations tab.
BollingerBandfeed simulation file and click .
When done, press F9 or click the Terminate EventFlow Fragment button.
The Bollinger Band sample application contains the following files:
The sample application file.
A feed simulation data file.
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.
Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.
Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:
See Default Installation Directories for the default location of
studio-workspace on your system.