Stock Screener – Example 14: Multiple Parameters Multiple Values; 12Mo PP; Top & Bottom 20

This is an example of an optimized scan that demonstrates some enhanced functionality; it can replace the need for writing several scans (as was required in the older versions of ChartAlert)

6 minutes

This functionality was introduced in October 2023 (Version 23.10.1)

Below is an illustration of an optimized scan that can be created using the Advanced Scanner in ChartAlert.

This one enhanced scan, wherein multiple parameters/ variables can now accept multiple values/ inputs, now replaces the need for writing at least 26 separate scans as was required in the previous versions of ChartAlert.


ATTN: This scan is similar to the earlier scan (refer to Example 13: Multiple Parameters Multiple Values; Yearly PP; Top 20 Bottom 20), with the exception that this scan will list the Top 20 and Bottom 20 symbols of the last 13 months (including the ongoing month).


[BEGIN Top20 M2 mths ago]
Set OptVar M1 = Min:1, Max:13, Step:1
Set OptVar M2 = Min:0, Max:12, Step:1
List symbols
Add Column C M1 bars ago as C1
Add Column C M2 bars ago as C2
Add Column Date M1 bars ago as D1
Add Column Date M2 bars ago as D2
Add Column Chg%(C M2 bars ago, C M1 bars ago) as chg%
Sort on Column chg% desc limit 20
Apply to Nifty
Set periodicity to Monthly
[END]

[BEGIN Bot20 M2 mths ago]
Set OptVar M1 = Min:1, Max:13, Step:1
Set OptVar M2 = Min:0, Max:12, Step:1
List symbols
Add Column C M1 bars ago as C1
Add Column C M2 bars ago as C2
Add Column Date M1 bars ago as D1
Add Column Date M2 bars ago as D2
Add Column Chg%(C M2 bars ago, C M1 bars ago) as chg%
Sort on Column chg% limit 20
Apply to Nifty
Set periodicity to Monthly
[END]

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


Purpose of the Scan

  1. To compute the monthly price performance extending back for a year (say, 6 months ago versus 7 months ago) of a list of symbols and to restrict the scan results to the Top 20 and Bottom 20 symbols per month.
  2. To display (in the scan results report) the closing prices at the end of a month (say, 12 months ago) and the start of that month (say, 13 months ago), and to also display the 1-month percentage change between those two dates of the month under examination.
  3. To scan the components of the following index: Nifty
  4. To convert the OHLC data stream to a monthly time-frame before executing the scan.

Let’s go!



Line 1

[BEGIN Top20 M2 mths ago]

The first section or block of the optimized scan procedure starts with a “BEGIN” command.

The text “Top20 M2 mths ago” that comes after the “BEGIN” command serves as the designated heading for the scan results that will be showcased in the scan report.

“Top20 M2 mths ago” is designed to work like this: Top20 12 mths ago


Line 2 and 3

Set OptVar M1 = Min:1, Max:13, Step:1
Set OptVar M2 = Min:0, Max:12, Step:1

We are configuring or setting multiple optimized variables (“Set OptVar”) that will be referred to as “M1” and “M2”.

The optimized variable “M1” will function as a placeholder within the scan heading and will be substituted with 13 input values starting with “1” and going through “13”.

Because the minimum input value is 1 (“Min:1”), the maximum input value is 13 (“Max:13”), and it will be stepped up in increments of 1 (“Step:1”), the 13 inputs for “M1” will therefore be 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 and 13.

Similarly, the variable “M2” will function as a placeholder within the scan heading and will be substituted with 13 input values starting with “0” and going through “12”.

Because the minimum input value is 0 (“Min:0”), the maximum input value is 12 (“Max:12”), and it will be stepped up in increments of 1 (“Step:1”), the 13 inputs for “M2” will therefore be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 and 12.

You can customize both the terms “M1” and “M2” with anything of your choosing . . . Just remember to globally replace them for the scan to work.


Line 4

List symbols

The “List symbols” is an important function that is necessary to generate a list of symbols, and (in this case) it will do so without applying any conditions or filters.


Line 5, 6, 7, 8 and 9

Add Column C M1 bars ago as C1
Add Column C M2 bars ago as C2
Add Column Date M1 bars ago as D1
Add Column Date M2 bars ago as D2
Add Column Chg%(C M2 bars ago, C M1 bars ago) as chg%

In this scan, the function “Add Column…” serves the purpose of displaying additional columns within a scan report.

In this case, the scanning report will display five columns: the closing prices derived by the variable “M1”, the closing prices derived by the variable “M2”, the date of the closing price (derived by “M1”), the date of the closing price (derived by “M2”), and the percentage change between these closing prices.

These columns will be titled as follows: “C1,” “C2,” “D1,” “D2” and “chg%” (respectively).


Line 10

Sort on Column chg% desc limit 20

Sort on Column chg% desc limit 20

The “Sort on Column” is a function that allows a column to be sorted in an ascending or descending order.

In this case, the column titled “chg%” will be sorted in a descending order (“desc”), and the results will be limited to the top 20 symbols (“limit 20”).


Line 11

Apply to Nifty

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


Line 12

Set periodicity to Monthly

The “Set periodicity to…” function applies the scanning process to the periodicity of the data being examined.

In this case, the scan will effectively examine all the constituent elements of the Nifty Index by converting the data to a Monthly time-frame.


Line 13

[END]

The optimized scan code concludes with an “END” statement.


Line 14 through 26

[BEGIN Bot20 M2 mths ago]
Set OptVar M1 = Min:1, Max:13, Step:1
Set OptVar M2 = Min:0, Max:12, Step:1
List symbols
Add Column C M1 bars ago as C1
Add Column C M2 bars ago as C2
Add Column Date M1 bars ago as D1
Add Column Date M2 bars ago as D2
Add Column Chg%(C M2 bars ago, C M1 bars ago) as chg%
Sort on Column chg% limit 20
Apply to Nifty
Set periodicity to Monthly
[END]

The second block of this optimized scan procedure (listed above) replicates the results of the first block with one exception: the scan results will be limited to the bottom 20 symbols.


The Scan Report in ChartAlert

%d