Stock Screener – Create a Relative Strength Matrix via Advanced Scanner; Create and Overwrite a MyFavourite WatchList

This is an illustrative scan that shows how to use the Advanced Scanner to create a Relative Strength Matrix. It also demonstrates the process of filtering symbols based on RS parameters, automatically adding qualifying symbols to a WatchList, and overwriting the MyFav WatchList each time the scan is executed.

15 minutes


ATTN: When performing a scan for a Relative Strength Matrix, please be aware that it is presently constrained to examining a maximum of 200 symbols.

This limitation is in place due to the substantial amount of hardware resources required to scan such a large number of symbols.

To put it into perspective, scanning a RS Matrix of 200 symbols is equivalent to examining a total of 39,800 symbol combinations (200*199), which involves a substantial workload.


'Restricted to 200 symbols at a time

Set Var Total = PFTOTALBUYS + PFTOTALX

List symbols 
where Candle Close > 50 
AND Candle Close < 10000 
AND Candle Volume > 25000 
AND Candle Trades > 1000

Add Column PFSTATUS
Add Column PFTOTALBUYS as Buys
 Sort on Column Buys desc
 Group rows by Buys
Add Column PFTOTALX as X
Add Column Total Format 0

Add Column Candle Close as Close
Add Column Candle Volume AS Volume
Add Column Candle Trades AS Trades
Add Column Sector

Add Column SYMBOL1
 Group rows by SYMBOL1

Set chart type to PF(PERCENTAGETYPE,2,3)
create RSMATRIX

Add to MyFav (SYMBOL1) RSM-NIFTY100 OVERWRITE

Apply Filter 
PFTOTALBX > 0.5 * SYMBOLCOUNT(SYMBOL1) 
AND PFTOTALBUYS > 0.66 * SYMBOLCOUNT(SYMBOL1) 
AND PFTOTALX > 0.66 * SYMBOLCOUNT(SYMBOL1) 

Apply to NIFTY100

Below is a breakdown of the scan presented in a step-by-step manner.


Purpose of the Scan

  1. To assess the strength of a symbol in comparison to a benchmark index, like the Nifty.
  2. To also gauge the relative strength of each symbol when compared to all other symbols (peers) within a specific index: For instance, construct an RS Matrix where each of the 100 stocks (of NIFTY100) is compared against the other 100 stocks and the underlying NIFTY Index.
  3. The entire scan process will be applied to the component stocks after converting the raw datastream into a noiseless chart format, specifically using 2% P&F charts.
  4. The objective is to also extract and present the following information or data based on relative strength and P&F patterns:
    • The current P&F pattern status (e.g., BX, BO, SO, SX) of the symbol under evaluation.
    • The total count of P&F pattern buy signals (e.g., BX and BO) that a symbol has received relative to the rest of the portfolio being assessed.
    • The total count of X columns (e.g., BX and SX) that a symbol has received relative to the rest of the portfolio being assessed.
    • Calculate the cumulative total of all P&F pattern buy signals and the count of X columns (e.g., BX, BO, and SX) that a symbol has earned compared to its peers.
    • Display the current closing price, trading volume, and number of trades for a symbol.
    • Identify the sector to which the qualifying symbol belongs.
  5. Additionally, the process involves applying basic filters, such as minimum closing price, trading volume, and trades, to screen symbols for eligibility. Advanced filters based on the RS Matrix are also employed, including functions like PFTOTALBX, PFTOTALBUYS, PFTOTALX, and SYMBOLCOUNT(), to further refine the selection of symbols.
  6. Finally, the shortlisted or qualifying symbols (the numerators in the relative strength equation) are automatically added to a MyFav WatchList. This scan is designed to run daily, allowing it to update the WatchList regularly by replacing outdated data with the most current information.

Let’s go!



Line 1

Set Var Total = PFTOTALBUYS + PFTOTALX

We are configuring a variable (“Set Var”), denoted as “Total”, which will be used to calculate the sum of two CASL functions: “PFTOTALBUYS” and “PFTOTALX”. But before delving into this calculation, let’s first familiarize ourselves with Point and Figure (P&F) patterns.


Understanding P&F patterns: BX, BO, SO and SX


The “PFTOTALBUYS” function in ChartAlert calculates the total number of symbols in both ‘BX’ and ‘BO’ statuses. In other words, it sums up all symbols with a buy signal, regardless of whether they are currently in an ‘X’ or ‘O’ column.

Similarly, the “PFTOTALX” function in ChartAlert tallies the number of symbols currently in an ‘X’ column, regardless of whether they are associated with a buy or sell signal.

Thus, “PFTOTALBUYS” encompasses symbols with a buy signal, while “PFTOTALX” includes symbols in an ‘X’ column, and the variable “Total” we’ve set up for this scan will calculate the sum of these two functions, “PFTOTALBUYS” and “PFTOTALX”.


Lines 2 through 6

List symbols where 
 Candle Close > 50 
 AND Candle Close < 10000 
 AND Candle Volume > 25000 
 AND Candle Trades > 1000

The function “List symbols where…” holds significant importance in ChartAlert as it plays a crucial role in generating a list of symbols. In the context of this scan, the inclusion of the term “where” is essential, as it signifies that specific conditions or filters are applied during the scanning process.

The scan employs the following ‘AND‘ conditions, meaning that all of these criteria must be satisfied:

  1. The closing price of the candle (“Candle Close”) must be higher than (“>”) Rs.50 (“50”).
  2. The closing price of the candle (“Candle Close”) must be below (“<”) Rs.10,000 (“10000”).
  3. The daily trading volume of the candle (“Candle Volume”) must exceed (“>”) 25,000 shares (“25000”).
  4. The number of trades on the day (“Candle Trades”) must surpass (“>”) 1,000 (“1000”).

In the context of trading, ‘number of trades’ refers to the total count of individual buy and sell transactions executed by market participants on an average trading day. Each time a trader buys a security or sells a previously owned security, it is counted as one trade. The greater the number of trades, the greater the level of participation and liquidity in that specific security.

Since we’re running this scan on a chart type known for its lack of noise, such as Point & Figure (P&F), indicated in line #19 below, it’s crucial to establish a clear distinction between the OHLCV data and the values displayed on the P&F chart. These two sets of values are not the same. The OHLCV data comprises the market’s closing price, trading volumes, and daily trades, whereas the P&F values are calculated or “derived” based on specific P&F parameters in use. To avoid confusion, we use the term ‘candle’ to explicitly refer to the OHLCV market data values.


Line 7

Add Column PFSTATUS

In this scan, the “Add Column…” function is used to show extra columns in a scan report.

In this specific scenario, we’re including a column that will show the value of a CASL function called “PFSTATUS”. This function simply reveals the status of a security in terms of a P&F pattern, which can be one of the following: BX, BO, SO, or SX.

To simplify matters, we will keep the column’s title in its default state. In other words, the column will be referred to as “PFSTATUS”.


Lines 8 through 10

Add Column PFTOTALBUYS as Buys
 Sort on Column Buys desc
 Group rows by Buys

Here, we’re including a new column displaying the results of a function known as “PFTOTALBUYS” (we dealt with this in line #1 above). This function calculates the total number of symbols with a buy signal, without regard to whether they are presently categorized in an ‘X’ or ‘O’ column.

We’re naming this new column “Buys” in the scan report, and you can choose a different name if you prefer.

Once the “Buys” column is added, the scan program will sort the stocks in a descending order (“Sort on Column Buys desc”), meaning those with higher values in the “Buys” column will appear at the top of the list.

Additionally, we are employing a function called “Group rows by…”. This function instructs the scan to group the report results according to a specific column. In this case, the results will be grouped based on the values found in the “Buys” column. That is, the report will be organized according to the number of buy signals each qualifying symbol has.


Line 11

Add Column PFTOTALX as X

We’re adding a new column to our report, which shows the results of a function called “PFTOTALX” (we dealt with this in line #1 above). This function counts how many symbols are in the ‘X’ column, regardless of whether they have a buy or sell signal.

In our scan report, we’re labeling this column as “X”, but you have the option to give it a different name if you’d like.


Line 12

Add Column Total Format 0

We are now introducing an additional column to our scan results report. This column, initially defined as a variable at the beginning of this scan (refer line 1 above), is labeled “Total”. It will display the sum of the two functions, namely “PFTOTALBUYS” and “PFTOTALX”.

Both the name of the variable and the title of the column (“Total”) are customizable and can be personalized to your preferences. However, it is essential to maintain consistent usage of the chosen name throughout the scan code.


Lines 13 through 15

Add Column Candle Close as Close
Add Column Candle Volume AS Volume
Add Column Candle Trades AS Trades

We are expanding our scan results report by introducing three additional columns: specifically, “Close”, “Volume” and “Trades”. You can customize these column names to your preference.

These columns will provide information on the following parameters: “Candle Close”, “Candle Volume” and “Candle Trades”, respectively.

As previously explained in lines 2 through 6 above, when performing this scan on a noiseless chart type P&F, it’s crucial to differentiate between the OHLCV data values and the P&F chart values. These two sets of values are distinct from each other. The OHLCV values represent the closing price, trading volumes, and trades in the market for the day, while the P&F values are calculated based on specific P&F parameters in use. To avoid confusion, we use the term ‘candle’ to specifically refer to the OHLCV market data values.


Line 16

Add Column Sector

We are introducing a new self-titled column called “Sector” which will display the sector to which the qualifying symbol belongs.


Lines 17 and 18

Add Column SYMBOL1
 Group rows by SYMBOL1

Thus, at line 17, we introduce another column named “SYMBOL1”, which corresponds to the “SYMBOL1” function in the Advanced Scanner. This column will contain a list of symbols that meet the criteria to be the numerator in the relative strength equation.

Additionally, we will utilize the “Group rows by…” function to further organize the scan results report. This grouping is based on the numerator of the relative strength equation, which is “SYMBOL1”. In essence, this function will group and arrange the scan results report according to the qualifying symbols (the numerator in the relative strength equation).


Line 19 and 20

Set chart type to PF(PERCENTAGETYPE,2,3)
create RSMATRIX

The “Set chart type to…” function gives you the ability to choose the type of chart you want to use for the scanning process.

In ChartAlert, you can easily change your data from OHLC format to different types of charts like Point & Figure, Renko, Kagi, Three Line Break, or Line charts before you begin scanning. It’s important to note that the default chart type for scanning is Candlestick.

For this specific task, we will convert the data into a Point & Figure chart with a 2% percentage setting and a 3-box reversal type (“PF(PERCENTAGETYPE,2,3)”). This is done just before the actual scan takes place.


Line 21

The explanation for line 21 has been provided below.

However, prior to reading line 21, we advise that you first understand lines 22 through 25.


Lines 22 through 25

Apply Filter
PFTOTALBX > 0.5 * SYMBOLCOUNT(SYMBOL1)
AND PFTOTALBUYS > 0.66 * SYMBOLCOUNT(SYMBOL1)
AND PFTOTALX > 0.66 * SYMBOLCOUNT(SYMBOL1)

We are now applying some advanced filters that are specifically focused on the concept of relative strength and the RS Matrix.

The “PFTOTALBX” function in ChartAlert is used to identify symbols that are currently in the highest ‘BX’ state. In simpler terms, it calculates the total number of buy signals for a symbol that are currently only in an ‘X’ column.

As previously mentioned in line 1 above, we discussed “PFTOTALBUYS” and “PFTOTALX”. The “PFTOTALBUYS” function counts all buy signals for a symbol, regardless of whether they are in an ‘X’ or ‘O’ column, like ‘BX’ or ‘BO’. On the other hand, the “PFTOTALX” function counts the number of ‘X’ columns a symbol is in, regardless of whether they are associated with a buy or sell signal, such as ‘BX’ or ‘SX’.

The “SYMBOL1” function simply represents the symbol name that serves as the numerator in the relative strength equation.

The “SYMBOLCOUNT()” function is used to count the number of symbols that meet a given criteria. For instance, in our scan code, “SYMBOLCOUNT(SYMBOL1)” counts the symbols designated as “SYMBOL1” that serve as the numerator in a relative strength equation.

In the context of NIFTY100, there are 101 symbols that qualify as the numerator. This includes all 100 components of the NIFTY100 Index and the Index itself. Therefore, the expression “SYMBOLCOUNT(SYMBOL1)” will return the value 101, representing the number of symbols being processed as the numerator by this scan code.

The scan code will then evaluate certain conditions to identify symbols that meet specific criteria.

The first condition, expressed as “PFTOTALBX > 0.5 * SYMBOLCOUNT(SYMBOL1)”, requires a symbol to have more than half (“0.5”) of 101 (which is 50.5) buy signals in ‘X’ columns (denoted as “PFTOTALBX”) to qualify.

The second condition, expressed as “PFTOTALBUYS > 0.66 * SYMBOLCOUNT(SYMBOL1)”, mandates that a symbol should have more than two-thirds (“0.66”) of 101 buy signals (equivalent to 66.66), regardless of whether they are in ‘X’ or ‘O’ columns (indicated by “PFTOTALBUYS”) to qualify.

The final condition, expressed as “PFTOTALX > 0.66 * SYMBOLCOUNT(SYMBOL1)”, similarly requires a symbol to have more than two-thirds (“0.66”) of 101 ‘X’ columns (or 66.66), regardless of their association with a buy or sell signal (“PFTOTALX”) to qualify.

All three of these conditions must be met simultaneously for a symbol to be included in the scan results report, as the advanced filter expression uses an ‘AND’ condition.


Line 21

Add to MyFav (SYMBOL1) RSM-NIFTY100 OVERWRITE

The symbols marked as “SYMBOL1” which have passed through the advanced filters (specified in lines 22 through 25 above) will now be included in a personalized watchlist (“Add to MyFav…”) known as “RSM-NIFTY100”. You have the option to change its name according to your preferences.

The “OVERWRITE” function ensures that the MyFavourite WatchList being created is consistently refreshed with up-to-date information every time the scan is run. If the “OVERWRITE” function is not used, the watchlist will keep accumulating results, leading to a mix of outdated and current data.


Line 26

Apply to NIFTY100

The “Apply to…” function applies the scanning process to the “NIFTY100” Index, that is, the scan will effectively examine all the constituent elements of NIFTY100.


The Scan Report in ChartAlert

%d