Stock Screener – Example 19: n-month Price Performance greater than 100% in the last 5+ years

This is an example of a scan (most recent instance of a 100%+ return in any ‘n’-month rolling period in the last ‘m’ years) that can be written using the Advanced Scanner that ships with ChartAlert

5 minutes

List symbols where DATEWHEN(chg%(cl, cl 2 months ago) > 100) > "01-Jan-2018"

Add Column DATEWHEN(chg%(cl, cl 2 months ago)>100) as Date
Sort on Column Date desc
Add Column VALUEWHEN(chg%(cl, cl 2 months ago)>100,chg%(cl, cl 2 months ago)) as 2moChg
Add Column VALUEWHEN(chg%(cl, cl 2 months ago)>100,SymbolValue(chg%(cl, cl 2 months ago),NIFTY)) as 2moChgNifty

Apply to nifty500

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


Purpose of the Scan

  1. Create a list of symbols, each accompanied by the most recent date on which they experienced a 2-month percentage gain exceeding a 100% return within the past 5+ years.
  2. Arrange the dates obtained in step 1 in descending order, before presenting them in the scan results report.
  3. In the scan results report, include not only the extracted date but also the corresponding 2-month percentage gain for each symbol. Additionally, provide the 2-month percentage gain of NIFTY on that same date for comparative analysis.
  4. Perform this scanning process on the components of the NIFTY500 index.

Let’s go!



Line 1

List symbols where DATEWHEN(chg%(cl, cl 2 months ago) > 100) > "01-Jan-2018"

This scan code consists of several key components that are executed in reverse order, starting from today’s date and going back to a specified date in the code, which is “01-Jan-2018“.

One of the components in this code is a function called “chg%(cl, cl 2 months ago)”. This function calculates the percentage change (“chg%()”) between the current closing price (“cl”) and the closing price from 2 months ago (“cl 2 months ago”).

Another component that is processed is the expression “chg%(cl, cl 2 months ago) > 100”. This function checks if the previously calculated 2-month percentage change is greater than 100%. Symbols that do not meet this condition are excluded from consideration.

The next component involves the “DATEWHEN()” function. This function extracts the date when the value of “chg%(cl, cl 2 months ago)” was greater than 100% from the data stream and temporarily stores it.

Finally, all the components of the entire condition, which is “DATEWHEN(chg%(cl, cl 2 months ago) > 100) > “01-Jan-2018””, are combined and executed. This step further filters the results obtained from the previous components. Specifically, it retains all the dates that come after the specified date of “01-Jan-2018” and filters out all other dates.


Lines 2 and 3

Add Column DATEWHEN(chg%(cl, cl 2 months ago)>100) as Date
  Sort on Column Date desc

Within this scan, we utilize the “Add Column…” function to include extra columns in our scan report.

Specifically, we create a column named “Date ” (which can be renamed as needed). This column will display the most recent date using the “DATEWHEN()” function. This date represents when a particular symbol achieved a 2-month percentage return exceeding 100% at any point over the past 5+ years.

In the scan results report, this “Date” column will be organized in a descending order (“desc”).


Line 4

Add Column VALUEWHEN(chg%(cl, cl 2 months ago)>100,chg%(cl, cl 2 months ago)) as 2moChg

In the scan results report, you will find an additional column labeled “2moChg” (a name you can personalize). This column will present the actual 2-month percentage return value (“VALUEWHEN()”) for each symbol.

In our current context, the ‘QueryExpression’ takes the form of “chg%(cl, cl 2 months ago) > 100”. This expression is essentially a function that assesses whether a symbol’s 2-month percentage return surpasses a 100% gain. On the other hand, the ‘DataField’ is represented by “chg%(cl, cl 2 months ago)”, signifying the actual 2-month percentage return for the given symbol.

Therefore, in practical terms, the “VALUEWHEN()” function retrieves the 2-month percentage return value for a symbol (‘DataField’) each time that symbol’s 2-month percentage return exceeds the threshold of 100% (‘QueryExpression’). This provides a systematic way to identify instances when a symbol achieves substantial returns over a 2-month period.


Line 5

Add Column VALUEWHEN(chg%(cl, cl 2 months ago)>100,SymbolValue(chg%(cl, cl 2 months ago),NIFTY)) as 2moChgNifty

In the scan results report, a new column will be added, which can be customized with a name of your choice, such as “2moChgNifty”. This column will show the value (“VALUEWHEN()”) of Nifty’s real 2-month percentage return. This information is provided to enable easy comparison with the 2-month percentage return of the symbols under consideration.

In this particular scenario, the ‘QueryExpression’ is set to “chg%(cl, cl 2 months ago) > 100”. This expression essentially asks whether a particular financial metric, a symbol’s 2-month percentage return, has exceeded a 100% gain.

The ‘DataField’ is specified as “SymbolValue(chg%(cl, cl 2 months ago), NIFTY)”. This represents the actual 2-month percentage return of the NIFTY Index when a symbol’s 2-month percentage return surpasses the 100% gain.


Line 6

Apply to nifty500

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


The Scan Report in ChartAlert

%d