MACD Sample

Moving Average Convergence Divergence (MACD) is a momentum indicator that follows trends and shows the relationship between two moving averages of prices. This sample calculates the MACD by subtracting the 26-day Exponential Moving Average (EMA) from a 12-day EMA. A 9-day EMA of MACD, called the signal, is then computed.

The aggregate function exp_moving_avg emits Null until the aggregate operator receives enough tuples to compute the first moving average. The filter operators filter out tuples that contains Null.

The application also includes an Excel spreadsheet that displays the MACD and signal values. The MACD and signal lines are plotted automatically.

This Sample's Files

The MACD sample application consists of:

  • An EventFlow application, MACD.sbapp.

  • A feed simulation file, MACD.sbfs.

  • A feed simulation data file, MACD.csv.

  • A Microsoft Excel file, MACD.xls, that you can use in conjunction with the StreamBase Adapter for Microsoft Excel. See the Adapters Guide for more information on this external adapter.

Running MACD.sbapp in StreamBase Studio

  1. In the Package Explorer, double-click to open the MACD.sbapp application. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. Select the Feed Simulations view. In that view, select the feed simulation file MACD.sbfs, and click Run.

  4. When done, press F9 or click the Stop Running Application button.

Running MACD.sbapp in Terminal Windows

This section describes how to run the sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.

  2. In window 1, launch StreamBase Server on MACD.sbapp:

    sbd MACD.sbapp
  3. In window 2, enter the following command to dequeue tuples from the sbd output streams:

    sbc dequeue OutputAll
  4. In window 3, run sbfeedsim on the provided configuration file, suppressing the printout of tuples.

    sbfeedsim -q MACD.sbfs
  5. In window 3, type the following command to terminate the server and dequeuer:

    sbadmin shutdown

Importing This Sample into StreamBase Studio

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

  • From the top menu, click FileLoad StreamBase Sample.

  • Select this application from the Applications list.

  • Click OK.

StreamBase Studio creates a project for each sample.

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 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_MACD

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/MACD

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