This ProBuilder code snippet is designed to calculate and screen the relative strength of a stock compared to the CAC40 index on a weekly basis. The relative strength is a measure used to identify how strong or weak a stock is compared to an index.
//https://www.prorealcode.com/documentation/equityframe/
TIMEFRAME(weekly)
CloseVal = Close
EQUITYFRAME("Indices - European","PXI")
CloseInd = Close
EQUITYFRAME(default)
Ratio = (CloseVal / CloseInd) *100
RelativeStrength = (Ratio - Ratio[1]) *100
test = RelativeStrength > 0.015
SCREENER[test](RelativeStrength AS "RelativeStrength")
Explanation of the Code:
- TIMEFRAME(weekly): This function sets the analysis to a weekly timeframe, meaning all data points (like closing prices) are considered on a weekly basis.
- CloseVal = Close: This line assigns the weekly closing price of the stock to the variable CloseVal.
- EQUITYFRAME(“Indices – European”,”PXI”): Changes the data context to the CAC40 index, allowing the retrieval of index data. “PXI” should be replaced with the appropriate code for the CAC40 or any other index as needed.
- CloseInd = Close: Retrieves the closing price of the index and assigns it to CloseInd.
- EQUITYFRAME(default): Resets the data context back to the default, which is typically the main stock being analyzed.
- Ratio = (CloseVal / CloseInd) * 100: Calculates the ratio of the stock’s closing price to the index’s closing price, multiplied by 100 to convert it into a percentage. This ratio shows how the stock is performing relative to the index.
- RelativeStrength = (Ratio – Ratio[1]) * 100: Computes the change in the ratio from the previous week, multiplied by 100. This value represents the weekly change in relative strength.
- test = RelativeStrength > 0.015: Defines a condition to test if the relative strength has increased by more than 0.015% from the previous week.
- SCREENER[test](RelativeStrength AS “RelativeStrength”): Uses the SCREENER function to filter and display stocks that meet the condition defined in test. The results show the relative strength values for stocks that pass the screener.
This code is useful for traders and analysts who want to compare the performance of a stock against a major index like the CAC40 on a weekly basis, helping in decisions related to relative strength investments.