Custom Market Breadth Module

Author: Optuma Team Last updated: Oct 22, 2022 01:55


The custom Market Breadth module gives the client the ability to create a measure based on any technical criteria that can be defined with a script formula. The only requirement is that the script must return a true/false response (e.g. is the RSI(10) greater than 75?), or a calculation that can be measured (e.g. how far is the close above the 12-period exponential moving average?) Each of these will return result for the selected universe (eg S&P500 companies, or your portfolio) and will show the result as either a percentage, a count, a sum or an average.

The example below shows the percentage of SPX members with a positive 3 bar Gann Swing. It can be displayed as its own chart as per the example on the left, or below the price chart using the Breadth Data tool.


As well as calculating the percentage of true/false conditions, the Breadth module also has the ability to create the following measures on a universe of stocks (see the Other Settings section below for a description of each):

  • Count
  • Sum
  • Average
  • Cumulative
  • Spread
  • Ratio
  • Geometric Average (used to create equal-weighted custom indices)

The following can be used for Advance/Decline studies:

  • Advance Decline
  • Advance Decline Cumulative Line
  • Advance Decline Ratio
  • Advance Decline Spread
  • Advance Decline Percent

Blog posts:

Using Optuma’s Market Breadth Engine - Part 1

Using Optuma’s Market Breadth Engine - Part 2

What is Market Breadth?

The concept of Market Breadth requires an enormous amount of computational power basing calculations on objective data.

The best place to start is with the Advance Decline Oscillator. The value is simply achieved by taking all the members of the Index and comparing the members that are advancing versus the members that are declining. The reason this so important is that it has been found that at market tops, it is the heavyweights of the stock market that are getting the “late money” and due to their size they continue to take the Index higher. What is not so evident is that all the small caps are usually the first to change trend at a turning point in the market. Market Breadth aims to alert the analyst of these changes before it is evident in the trend of the Index.

As an example, in the Dow Jones Industrial 30, if 15 stocks are advancing and 15 stocks are declining our result for that day would be 0 (15-15). Below is a small table with some examples of how the numbers could work:

Technical Market Breadth Charts 2

Both the Net Advance and the A/D Line can be used as Breadth indicators. With the Net Advance, the result is more like an oscillator and it gives a chart like the following:

Breadth ADDSPX

The final column in the table is the A/D Line. This is sometimes more correctly called the Cumulative Advance Decline line where today’s value is based on yesterday’s value and the result of the net advances.

Technical Market Breadth Charts 4

With the A/D Line, the actual value has little reflection to the number of securities as the value can grow to be a very large positive or negative number. Rather, the analyst is looking at the plot and determining if there are divergences between the Index and the AD Line.

How to build a custom breadth measure

Market Breadth is accessed from the Data Menu in Optuma.

Breadth Data

When the Market Breath form opens for the first time, double click on the New Breadth label on the left and give it a name. When creating data you are in effect creating a data series like a price chart, so in the Symbol field type a new symbol (please use letters and numbers only) which will be added to your system for use in other areas of the software.

The script editor is ready for setting the criteria used in the breadth, which could be selected from your saved scripts under My Criteria, or click the New button to open the script editor window and create a new formula.

Breadth New

In the script editor, we are going to make our condition that each equity is positive when its close is above the 200-day Weighted Moving Average.

Once you have entered the script, select Apply.

Breadth Close 200WMA

The next step is to choose the data set that we are going to test this on by going to the Breadth Properties and clicking on Codes to Include. What you use exactly is dependent on the data source you have. You can also use the Lists tab to select Symbol Lists which may be lists of codes from CSV files or the constituents of a Bloomberg Index. In this example, we are going to use the current members of the S&P 500 Index.

Breadth Codes to Include

Next, we need to give the result a code and a name. The reason for this is that once the calculation is complete, the result is stored in a data file just like any other security. This means that you can overlay it on charts and even set alerts on it. A good suggestion is to use a combination of the data being used and the condition so that you can easily identify the various measures created. When the name is updated, the Breadth measure in the list is also renamed.

Breadth Name

Other Settings

Breadth Settings
We’ve dealt with the 1st three breadth properties however we need to deal with the last as they are also very important.

Membership: Allows your breadth to use data that is free of Survivorship Bias. For more information on this, please click here (not available for all Symbol Lists).

Date Range: This defines how far back you want Optuma to create the calculations. Optuma will load all the data files for that range and then calculate how many passed the criteria. We must put a warning here: if you are using an index without survivorship bias available (eg Russell 2000), then you are selecting the current equities that “survived” ie they are companies that did not go bust as the ones that did are no longer in the index. Worse from a bias point of view is that some of those equities may have been a penny stock. For this reason, we do not recommend going back further than 5 years.

Data Time Frame: This allows you to build a breadth code based on Daily / Weekly / Monthly or Yearly data. This can be used when the underlying data building the breadth is only updated in weekly, monthly or quarterly intervals.

Breadth Action: This defines the type of result displayed. The following are the possibilities:

  • Percent - What is the percentage of the members that have passed the test? We count the passes and divide by the total number of universe members.
  • Count - Simply the number of members that passed the test.
  • Sum - This one is a bit of a departure from traditional Breadth. With Sum, you can have a script that returns a value like RSI() or percent that the close is above a moving average and this function will sum together all those values. It is best that your script result is normalised else high-value stocks may overweight the result.
  • Average - Based on the Sum above, this one divides the result by the total number of members to get an average each day.

The following take into consideration the members that passed and the members that failed.

  • Spread - This will take the difference between the codes that passed and those that failed, so if 375 passed and 125 failed, the result will be 250.
  • Cumulative - the number that passed the true/false test is added to the result of the previous day. To use the example above, today’s value would be 375 higher than yesterday. If none passed then the line would be flat.
  • Ratio - In this case, the number that passed is divided by the number that failed (ie 375 / 125 would give a ratio of 3).
  • Geometric Average: This option is used to calculate an equal-weighted custom index, by taking the product of the numbers generated by the script and raising it to the inverse of the number in the series. See here for a video.

These are the advance/decline calculations that require two formulas: eg CLOSE() IsUp for the Advance Script and CLOSE() IsDown for the Decline Script:

  • Advance Decline - similar to the Spread calculation but ignores those unchanged.
  • Advance Decline Cumulative Line - takes the Advance-Decline spread and added to the previous value. If 150 advanced and 250 declined then the line would be 100 lower than yesterday.
  • Advance Decline Ratio - similar to the Ratio calculation but ignores those unchanged.
  • Advance Decline Percent - calculates (Advances - Declines) / (Advances + Declines). Ranges between -100/+100

Auto Update: Selecting this option means that when Optuma is started in the morning, or when new data is received by the end of day data feed, Optuma will automatically run the calculations for the latest day and add that value to the file to keep it up to date. This can be slow if the calculations are intense or data needs to be sourced from a 3rd party that is slow.

The Data menu contains an option called “Update All Breadth Indicators”. When Auto-Update is unticked, you can use this action to rebuild all of your breadth codes at once, rather than one at a time.

Breadth Update Indicators

Also, rather than update all your breadth measures at once (which can take a long time if you have a lot of calculations) you can group your calculations and then right-click on the heading and select Update Breadth Group:


Decimal Type: Sets the decimal place setting to be used, e.g. 0.00, 0.0000, halves, 32nds.

Generating the Breadth Chart

Finally, we need to run the Breadth Calculations by pressing the Build Breadth button. If all the data is present, this will build five years of data in a few seconds and the time will be listed as well as a chart showing you the result.

Breadth Build

From here you can double-click on the chart to open it as a new chart in Optuma, or you can press F3 and look in the Market Breadth folder.

Breadth Selector

Once the chart is open you can see the performance.

Breadth Large 2

From here you can overlay the index and set some rules based on what should have been a good indication of a Bull market and what was a good indication of a Bear market. Below is the chart with the overlay (right-click and select Overlay Left Scale):

Breadth Large 3

Looking at the chart, it seems that a good measure is when our breadth value is over 75% to say that is a Bull market and less than 30% would indicate a Bear market. We can show this on the chart by adding a Show View tool in conjunction with a Switch script. The script is SWITCH(CLOSE() > 75, CLOSE()<30)

Breadth Switch

You can drag and drop the Show View over the chart and reduce its transparency so that you can easily see how the zones correlate to the market movements.

Breadth Switch 2

You can see the above example that a 200-day WMA is a good measure although it is very late in the moves, as you would expect with any technique constructed from a 200-day moving average. In Optuma there are many different Breath measures that can be explored.

From Optuma 2.0 and onward, you can now build Custom Breadth measures with over 10 years of history.