ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Can you help me calculate RS with this description ?
Posted by Tuyen on Dec-03-2018 22:51
Relative Strength
This help section explains the Relative Strength indicator, not the Relative Strength Index indicator. If you have questions about how to generate Relative Strength values or how to maintain the Relative Strength database, refer to the Relative Strength database help section.


Relative Strength is a concept created by William J. O’Neil of Investor’s Business Daily. It compares all the financial instruments in a database to see which issues are rising or declining at a faster rate compared with the other financial instruments in the database. The instruments that are rising the fastest are given a value of 99, while the instruments that are declining the fastest are given a value of 1. Investor’s Business Daily generates these values over a one year period. (Approximately 250 trading days.) Investigator allows you to generate these values over multiple time periods. The most popular periods are 25 and 250 days. Unlike Investor’s Business Daily, Investigator also allows you to see the percent change the instrument made over the period. You can use both the Relative Strength value and the percent change value in testing.


Relative Strength is calculated as follows:


Assume that the Relative Strength time period is 200 bars.


For each instrument in the database:


Go back 199 bars and get the closing price.

Go back 149 bars and get the closing price.

Calculate the price percent change between these bars and call this Quarter 1.


Go back 149 bars and get the closing price.

Go back 99 bars and get the closing price.

Calculate the price percent change between these bars and call this Quarter 2.


Go back 99 bars and get the closing price.

Go back 49 bars and get the closing price.

Calculate the price percent change between these bars and call this Quarter 3.


Go back 49 bars and get the closing price.

Get the current bar’s closing price.

Calculate the price percent change between these bars and call this Quarter 4.


Note: For futures trades, the futures lookup table can be used to obtained accurate price percent changes.


We are going to give the final quarter’s percent double significance, so we’ll multiple Quarters 1, 2, and 3 by .2 and multiply Quarter 4 by . 4 and add these values together to arrive at the RS percent change for the instrument.


After finding the RS percent change for each instrument in the database, make a list by sorting the RS percent change values so that the highest percent change is at the top of the list and the lowest percent change is at the bottom of the list.


Take the number of items on the list and divide by 99 (not 100, since the values go from 1 to 99, not 0 to 100) to find out how many instruments are in a Relative Strength value period. For example, if there are 196 financial instruments in your database, there would be 2 instruments in each Relative Strength value period. (Two would have a value of 99, two would have a value of 98, etc.)


Go through the sorted list, starting at the top, and assign each instrument it’s Relative Strength value. (Using the above database example of 196 financial instruments, the first two instruments on the list receive a Relative Strength ranking of 99, the next two instruments on the list receive a Relative Strength ranking of 98, etc.)


Calculation Example


Testing Dialog Box


Note 1: There are two ways to view Relative Strength values and percents. You can either view the values and percents for a particular date by selecting Relative Strength from the Special menu and View / Delete RS Values from the Relative Strength menu, or you can view the values and percents for a particular financial instrument by opening the chart for the instrument and selecting Breadth from the Indicators menu and Relative Strength from the Breadth menu.


When you view relative strength values on a particular chart, the values will not appear on the chart unless the current relative strength directory points to the directory that contains that chart’s relative strength information. Click here for information on how to change the current relative strength directory.


If the proper relative strength directory is chosen, the chart will then show the Relative Strength value and percent lines for the selected bar. If you click on a different bar, the Relative Strength value and percent for that bar will be shown.


Note 2: Your Relative Strength values will most likely be different from those published in Investor’s Business Daily since you are generating Relative Strength values using different financial instruments than Investor’s Business Daily.


Reference: Investor’s Business Daily.

Thanks and Best Regards!

  Re: Can you help me calculate RS with this description ?
Posted by Peter Kwan on Dec-04-2018 04:01
Hi Tuyen,

According to the description, most of the code is about obtain the data from the database. Assuming you have a database and have obtain the last 200 bars for every instruments in your database, in "pseudo code", it is:

for each instrument in the database
{
     data = read_last_200_bars_of_the_instrument_into_an_array;
     Q1 = (data[49] - data[0]) / data[0];
     Q2 = (data[99] - data[50]) / data[50];
     Q3 = (data[149] - data[100]) / data[100];
     Q4 = (data[199] - data[150]) / data[150];
     RSChange[instrument] = Q4 * 0.4 + Q3 * 0.2 + Q2 * 0.2 + Q1 * 0.2;
}

Sort_the_RSChange_in_descending_order;

slotSize = number_of_instruments / 99;

currentValue = 99;
count = 0;

for each instrument in RSChange
{
    RS[instrument] = currentValue;
    if ((++count) % slotSize == 0) --currentValue;
}

Note that like many financial indicators, the definition of RS looks incomplete and can have bugs. For example, "calculate the price percent change" may have an issue if the price can be 0, as this can cause division by 0. Sometimes people use financial instruments to track financial series such as interest rate, and it is perfectly possible for interest rate to be 0 or negative. In your real code, you have to handle all possible cases in your application.

Regards
Peter Kwan

  Re: Can you help me calculate RS with this description ?
Posted by Tuyen on Dec-04-2018 14:09
Thanks for your reply. It's very easy understand. But how can I calculate RS of a instrument by use ArrayMath, because i want calculate and save as array of RS.
Thank You very much and best regards.

  Re: Can you help me calculate RS with this description ?
Posted by Peter Kwan on Dec-05-2018 00:39
Hi Tuyen,

Unluckily, I cannot think of a faster or shorter method to calculate the RS using ArrayMath. It is because the method to calculate RS is mainly an "algorithm", not an arithmetic formula. The arithmetic part of the algorithm is so simple that it is faster just to directly write the code. The algorithmic part has to be implemented in a programming language (that is, writing code).

Regards
Peter Kwan

  Re: Can you help me calculate RS with this description ?
Posted by Tuyen on Dec-05-2018 14:15
Unfortunately.
Thank you so much.
Best regards.