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
- 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.
- Arrange the dates obtained in step 1 in descending order, before presenting them in the scan results report.
- 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.
- 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.
In summary, the end result of this line of code is the determining of the date of the most recent occurrence when a symbol’s 2-month percentage change exceeded a 100% return, considering data from today all the way back to “01-Jan-2018”.
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.
How the “VALUEWHEN()” function works?
Let’s delve into how the “VALUEWHEN()” function operates. The function is structured as follows:
VALUEWHEN(QueryExpression, DataField)
In essence, it retrieves the value from a designated ‘DataField’ but only when the specified ‘QueryExpression’ condition has been met.
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.
How the “VALUEWHEN()” function works?
Let’s delve into how the “VALUEWHEN()” function operates. The function is structured as follows:
VALUEWHEN(QueryExpression, DataField)
In essence, it retrieves the value from a designated ‘DataField’ but only when the specified ‘QueryExpression’ condition has been met.
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.
So, in simple terms, the “VALUEWHEN()” function does this:
Every time a symbol’s 2-month percentage return goes beyond 100%, it retrieves the corresponding 2-month percentage return value for the NIFTY index. This function helps us pinpoint these specific instances in our data.
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
