Bollinger Band Sample

About This Sample

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.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, click File>Import Samples and Community Content.

  • Enter boll to narrow the list of options

  • Select How to calculate Bollinger Band from the Applications category.

  • Click Import Now.

StreamBase Studio creates a project for the sample.

Running This Sample in StreamBase Studio

To run this sample:

  1. 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 Maven>Update Project from the context menu.

  2. Open the src/main/eventflow/packageName folder.

  3. Open the BollingerBand.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the module.

  4. Open the Feed Simulations tab.

  5. Select the BollingerBand feed simulation file and click Run.

  6. When done, press F9 or click the Terminate EventFlow Fragment button.

This Sample's Files

The Bollinger Band sample application contains the following files:

BollingerBand.sbapp

The sample application file.

BollingerBand.sbfs

An sbfeedsim configuration file.

BollingerBand.csv

A feed simulation data file.

Sample Location

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 permission problems. The default workspace location for this sample is:

studio-workspace/sample_bollingerband

See Default Installation Directories for the default location of studio-workspace on your system.