Click here to Login




How to create the advance/decline market breadth indicator

Updated on 2012-02-29





The advance/decline line is a market technical indicator that compares the daily number of increasing stocks with the daily number of decreasing stocks (negative return).

It is one of the most used market breadth indicators and commonly called A-D line. This indicator can be calculated for any group of stocks. You can for example compute the A-D line of NYSE stocks, A-D line of S&P 500 or A-D line of all stocks listed on U.S. Exchanges.

Here is the formula for the advance/decline line:
AD line = (# of advancing stocks – # of declining stocks) + yesterday's A/D line value

Before we start, read the following post to learn how to create a market composite:
How to create a composite index/indicator


Creating the advance/decline line

We could have built this line by creating two composites (one for advancing stocks and another one for declining stocks) then creating a custom indicator to calculate the AD line.

However, we will show you here how to create this market breadth indicator using a single composite item.

Steps:

- Open the composites form, click on "Add", select a list of stocks then click on "Next"
- In the formula panel (Step 2), we must perform two composite calculations.

This can be done using the "AddComposite" function.

AddComposite("Adv", close > close[1], _CompSum);
AddComposite("Dec", close <= close[1], _CompSum);
composite = 1; // Not used here


Usually, a basic market indicator is calculated by taking the sum, average, min or max of the values returned by the "composite" variable (for each stock) for the same bar/date.

The "AddComposite" function allows you to create additional composites that can then be used in a C# script to perform additional calculations and return a single composite.

This is what we are going to do with this advance/decline market breadth indicator.


Creating the C# Script

Click on "Script" button located just below the "Formula" panel of the "Create Composite" form.

The composite script is executed once after the composite formula calculation is completed.

In order to create the advance/decline line, we must implement the AD line formula (shown above) inside the composite script.

How to get a reference to composites created using the "AddComposite" function (QuantShare Language):

double[] adv = Functions.GetVariable("Adv");
double[] dec = Functions.GetVariable("Dec");


The "adv" array now gets the number of advancing stocks for each trading bar, while the "dec" array gets the number of declining stocks.

Note that "adv" and "dec" arrays are synchronized, which means that for each array, the value at index 25 (for example) references the same date/time.


How to compute the AD line:

double[] comp = new double[adv.Length];
comp[0] = adv[0] - dec[0];
for(int i=1;i < adv.Length;i++)
{
comp[i] = (adv[i] - dec[i]) + comp[i - 1];
}



The above C# code, loops through each element of the array and then calculates the AD line for each trading bar.


Passing the result to the composite plug-in:

Now that we have created the AD line from the number of advancing and declining stocks, we would like to pass the new composite array (AD Line -> 'comp' Array) to the composite Plug-in.

Here is how to do this:

Functions.SetCompositeData(comp);


Using a Filter

Back to the composite formula, we can add a "filter" variable to instruct QS trading software to ignore some stocks.

Stocks whose filter variable value is False (equal to zero) on a specific bar will be ignored for that bar (not included in the composite calculation).

To create the advance/decline line of stocks trading above $50, simply add the following line:

filter = close > 50;


Advance Decline Data

I know you can now create your own advance and decline stocks composites.

However, in case you want to download ready-to-use advance/decline/unchanged data from several exchanges (AMEX, NASDAQ, and NYSE), here is a downloader link:
Advance-Decline-Unchanged issues for NYSE, AMEX and NASDAQ


Market Breadth Indicators in QuantShare Sharing Server

Several market breadth indicators were shared by our members, here are some:
Absolute Breadth Index
Arms Index - TRIN
Zweig Breadth Thrust
Advance Decline Ratio
Percentage Hughes Breadth Momentum Oscillator
Open ARMS Index - Open-10 TRIN











no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1427 days ago

Profile Graphs
Posted 1532 days ago

QuantShare
Previous Posts

More Posts

Back







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.