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 atleast 44 separate scans as was required in the previous versions of ChartAlert.
[BEGIN Top20 Year1-Year2]
Set OptVar Year1 = Min:2001, Max:2022, Step:1
Set OptVar Year2 = Min:2002, Max:2023, Step:1
Set Var Bar1 = BARATDATE("31-Mar-Year1")
Set Var Bar2 = BARATDATE("31-Mar-Year2")
Set Var C1 = ValueAt(Bar1)
Set Var C2 = ValueAt(Bar2)
List symbols
Add Column C1
Add Column C2
Add Column Chg%(C2,C1) as chg%
Sort on Column chg% desc limit 20
Apply to Nifty
[END]
[BEGIN Bottom20 Year1-Year2]
Set OptVar Year1 = Min:2001, Max:2022, Step:1
Set OptVar Year2 = Min:2002, Max:2023, Step:1
Set Var Bar1 = BARATDATE("31-Mar-Year1")
Set Var Bar2 = BARATDATE("31-Mar-Year2")
Set Var C1 = ValueAt(Bar1)
Set Var C2 = ValueAt(Bar2)
List symbols
Add Column C1
Add Column C2
Add Column Chg%(C2,C1) as chg%
Sort on Column chg% limit 20
Apply to Nifty
[END]
Below is a breakdown of the scan presented in a step-by-step manner.
Purpose of the Scan
- To compute the yearly price performance (say, 31-Mar-2002 versus 31-Mar-2001) of a list of symbols and to restrict the scan results to the Top 20 and Bottom 20 symbols per year.
- To display (in the scan results report) the closing prices at the start of a year (say, 31-Mar-2001) and the end of a year (say, 31-Mar-2002), and to also display the 1-year percentage change between those two dates of the year under examination.
- To scan the components of the following index: Nifty
Let’s go!
Line 1
[BEGIN Top20 Year1-Year2]
The first section or block of the optimized scan procedure starts with a “BEGIN” command.
The text “Top20 Year1-Year2” that comes after the “BEGIN” command serves as the designated heading for the scan results that will be showcased in the scan report.
“Top20 Year1-Year2” is designed to work like this: Top20 2022-2023
Line 2 and 3
Set OptVar Year1 = Min:2001, Max:2022, Step:1
Set OptVar Year2 = Min:2002, Max:2023, Step:1
We are configuring or setting multiple optimized variables (“Set OptVar”) that will be referred to as “Year1” and “Year2”.
The optimized variable “Year1” will function as a placeholder within the scan heading and will be substituted with 22 input values starting with “2001” and going through “2022”.
Because the minimum input value is 2001 (“min:2001”), the maximum input value is 2022 (“max:2022”), and it will be stepped up in increments of 1 (“step:1”), the 22 inputs for “Year1” will therefore be 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 and 2022.
Similarly, the variable “Year2” will function as a placeholder within the scan heading and will be substituted with 22 input values starting with “2002” and going through “2023”.
Because the minimum input value is 2002 (“min:2002”), the maximum input value is 2023 (“max:2023”), and it will be stepped up in increments of 1 (“step:1”), the 22 inputs for “Year2” will therefore be 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 and 2023.
You can customize both the terms “Year1” and “Year2” with anything of your choosing . . . Just remember to globally replace them for the scan to work.
See Line 4 and 5 below to know more on how “Year1” and “Year2” get used in the scan.
Line 4 and 5
Set Var Bar1 = BARATDATE("31-Mar-Year1")
Set Var Bar2 = BARATDATE("31-Mar-Year2")
We are configuring a few more variables (“Set Var”) that will be referred to as “Bar1” and “Bar2”.
The variable “Bar1” (to be used in association with the optimized variable “Year1”) will be substituted with 22 input values like “31-Mar-2001,” “31-Mar-2002” and so on until “31-Mar-2022”.
The “BARATDATE” function will simply extract the number of the trading bar on these dates: 31-Mar-2001, 31-Mar-2002 and so on until 31-Mar-2022.
Similarly, the variable “Bar2” (to be used in association with the optimized variable “Year2”) will be substituted with 22 input values like “31-Mar-2002,” “31-Mar-2003” and so on until “31-Mar-2023”.
The “BARATDATE” function will simply extract the number of the trading bar on these dates: 31-Mar-2002, 31-Mar-2003 and so on until 31-Mar-2023.
You can customize both the terms “Bar1” and “Bar2” with anything of your choosing . . . Just remember to globally replace them for the scan to work.
With these variables (“Bar1” and “Bar2”), we have just extracted the number of the trading bar on various dates.
Line 6 and 7
Set Var C1 = ValueAt(Bar1)
Set Var C2 = ValueAt(Bar2)
We are configuring a few more variables (“Set Var”) that will be referred to as “C1” and “C2”.
The variable “C1” (associated with “Bar1”) will be substituted with 22 input values that will be derived on the basis of “Bar1”.
The “ValueAt” function will simply extract the closing price of the symbol based on the trading bar that was earlier extracted on the basis of the variable “Bar1”.
Similarly, the variable “C2” (associated with “Bar2”) will be substituted with 22 input values that will be derived on the basis of “Bar2”.
The “ValueAt” function will simply extract the closing price of the symbol based on the trading bar that was earlier extracted on the basis of the variable “Bar2”.
You can customize both the terms “C1” and “C2” with anything of your choosing . . . Just remember to globally replace them for the scan to work.
With these variables (“C1” and “C2”), and by using the intermediate variables (“Bar1” and “Bar2”), we have just extracted the closing price of the various symbols on various dates.
Line 8
List symbols
The “List symbols” is an important function that is necessary to generate a list of symbols, and it will do so without applying any conditions or filters.
Line 9, 10 and 11
Add Column C1
Add Column C2
Add Column Chg%(C2,C1) 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 three columns: the closing prices derived by the variable “C1”, the closing prices derived by the variable “C2”, and the percentage change between these closing prices.
To keep it simple, these columns will be titled after their variable names, namely “C1,” “C2” and “chg%” (respectively).
Line 12
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 13
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 14
[END]
The optimized scan code concludes with an “END” statement.
Lines 15 through 28
[BEGIN Bottom20 Year1-Year2]
Set OptVar Year1 = Min:2001, Max:2022, Step:1
Set OptVar Year2 = Min:2002, Max:2023, Step:1
Set Var Bar1 = BARATDATE("31-Mar-Year1")
Set Var Bar2 = BARATDATE("31-Mar-Year2")
Set Var C1 = ValueAt(Bar1)
Set Var C2 = ValueAt(Bar2)
List symbols
Add Column C1
Add Column C2
Add Column Chg%(C2,C1) as chg%
Sort on Column chg% limit 20
Apply to Nifty
[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
