Contents
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.
In summary:
-
MiddleBand: Moving Average (simple or exponential)
-
UpperBand: Moving Average + (2 * Standard Deviation)
-
LowerBand: Moving Average - (2 * Standard Deviation)
-
LastValue: lastval(price)
-
Bandwidth = (UpperBand - LowerBand)/MiddleBand
-
PercentB = (LastValue - LowerBand) / (UpperBand - LowerBand)
The application also includes an Excel spreadsheet that displays the bands, plotting them automatically.
The Bollinger Band sample application has the following files:
-
The application,
BollingerBand.sbapp
-
An
sbfeedsim
configuration file,BollingerBand.sbfs
-
An feed simulation data file,
BollingerBand.csv
-
In the Package Explorer, double-click to open the
BollingerBand.sbapp
application. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
Open the Feed Simulations tab.
-
Select the
BollingerBand.sbfs
feed simulation file and click . -
When done, press F9 or click the
Stop Running Application button.
-
Open three terminal windows. In each window, navigate to the directory in your Studio workspace that contains your copy of this sample.
-
In window 1, launch StreamBase Server on
BollingerBand.sbapp
:sbd BollingerBand.sbapp
-
In window 2, enter the following command to dequeue tuples from the server's output streams:
sbc dequeue OutputBollingerSMA OutputBollingerEMA
-
In window 3, run sbfeedsim on the provided configuration file, suppressing the printout of tuples.
sbfeedsim -q BollingerBand.sbfs
-
In window 2, press Ctrl+C to close the enqueuer. Then run
sbadmin shutdown
to close the server.
-
Open three StreamBase Command Prompts. In each window, navigate to the directory in your Studio workspace that contains your copy of this sample.
-
In window 1, launch StreamBase Server on
BollingerBand.sbapp
:sbd.exe BollingerBand.sbapp
-
In window 2, enter the following command to dequeue tuples from the server's output streams:
sbc.exe dequeue OutputBollingerSMA OutputBollingerEMA
-
Start Microsoft Excel 2003 and open the following Excel file
BollingerBand.xls
provided in the sample folder. -
In window 3, run sbfeedsim on the provided configuration file, suppressing the printout of tuples:
sbfeedsim -q BollingerBand.sbfs
-
In window 2, press Ctrl+C to close the enqueuer. Then run
sbadmin shutdown
to close the server.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click
→ . -
Select this application from the Applications list.
-
Click OK.
StreamBase Studio creates a project for each sample.
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.
Important
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 the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:
studio-workspace
/sample_bollingerband
See Default Installation Directories for the location of studio-workspace
on your system.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
streambase-install-dir
/sample/bollingerband
See Default Installation Directories for the default location of studio-workspace
on your system.