Stock Screener – Example 5: Single Parameter Multiple Inputs (EMA Crossover)

This is an example of an optimized scan wherein a single parameter or variable can accept multiple inputs thereby replacing the need for writing several scans (as was required in the older versions of ChartAlert); this functionality for the Advanced Scanner will be introduced in September 2023.

3 minutes

This functionality will be introduced in September 2023 (Version 23.9.1)

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

This one enhanced scan, wherein a single parameter or variable can now accept multiple values or inputs for scanning, now replaces the need for writing six separate scans as was required in the previous versions of ChartAlert.

[BEGIN Close crossed above EMA(timeP1)]

Set OptVar timeP1 = 5,8,13,21,34,55

List symbols where c crossed above EMA(timeP1)

Add Column Close
Add Column EMA(timeP1) chart(color=red, lw=2)

Apply to Nifty100

[END]

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


Purpose of the Scan

  1. To generate a list of symbols where the latest Close has just crossed above several EMAs (Exponential Moving Average); for example: EMA(5), EMA(8), EMA(13), EMA(21), EMA(34) and EMA(55).
  2. To display the values of the latest Close and the various EMAs in the scan results report.
  3. To plot the EMA on the chart if a symbol is opened from inside the scan results report.
  4. To scan the components of the following index: Nifty100.

Let’s go!


Line 1

[BEGIN Close crossed above EMA(timeP1)]

The optimized scan procedure starts with a “BEGIN” command.

The text “Close crossed above EMA(timeP1)” that comes after the “BEGIN” command serves as the designated heading for the scan results that will be showcased in the scan report.

The term “timeP1” functions as a temporary marker or placeholder within the scan heading and will be substituted with terms like “5,” “8,” “13,” “21,” “34” or “55” in the scan report.

You can customize the term “timeP1” with anything of your choosing.

“Close crossed above EMA(timeP1)” is designed to work like this: Close crossed above EMA(55)


Line 2

Set OptVar timeP1 = 5,8,13,21,34,55

We are configuring or setting an optimized variable (“Set OptVar”) that will be referred to as “timeP1”.

Remember, you can customize the term “timeP1” (time period) with anything of your choosing.

This parameter or variable “timeP1” will encompass six indicator settings (number of trading bars) that will be used to compute the Exponential Moving Average (EMA): “5,” “8,” “13,” “21,” “34” and “55”.

In essence, upon execution, this scanning process will sequentially compute the EMA as follows: EMA(5), EMA(8), EMA(13), EMA(21), EMA(34) and EMA(55).


Line 3

List symbols where c crossed above EMA(timeP1)

This scan will generate a list of symbols where the value of “c” (representing the current Close) has recently crossed above “EMA(timeP1)”.

The scan will use EMA(5), EMA(8), EMA(13), EMA(21), EMA(34) and EMA(55) as input to look for symbols where this specific condition has been met.

Here, “EMA” refers to Exponential Moving Average, and “timeP1” refers to the six variable time periods (5, 8, 13, 21, 34 and 55) as mentioned above.


Line 4 and 5

Add Column Close
Add Column EMA(timeP1) chart(color=red, lw=2)

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 two columns: the latest closing value, and the latest values of the EMA.

These columns will be titled “Close” and “EMA(timeP1)”, respectively, wherein “timeP1” will be substituted with the six time periods.

The function “chart(color=red, lw=2)” will simply plot the moving average on the chart of the resultant symbol in ChartAlert, and the color and the line width of the moving average would be set to “red” and at “2” pixels (respectively).


Line 6

Apply to Nifty100

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


Line 7

[END]

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


The Scan Report in ChartAlert

%d bloggers like this: