RSL in TradingView: setting up Levy's relative strength as an indicator
Levy's relative strength can be set up in TradingView as a custom indicator with a short Pine script: closing price divided by the simple average of the last 26 bars. On the weekly chart this gives the RSL over 26 weeks, on the daily chart over 26 days. It does not give you a comparison of many stocks in a ranking.
In short
- Formula: RSL = closing price ÷ simple moving average over 26 bars.
- Weekly chart gives 26 weeks, daily chart 26 days.
- A horizontal line at 1 shows whether the price is above or below its average.
- The indicator always shows only one value, not a ranking.
- TradingView is offered by another company, RSL-scan has no connection with it.
As of 11/25/2026
Don't feel like scripting? The scanner shows the RSL for all stocks of a market.
Go to the scannerWhat you should know beforehand
TradingView is a charting platform on which you can create your own indicators with the Pine Script language. TradingView and Pine Script are trademarks of TradingView, Inc. RSL-scan has no connection with TradingView. TradingView has neither reviewed nor approved these instructions or the script. These instructions only describe how you implement the formula there yourself.
The relative strength according to Levy is a simple calculation: current price divided by the moving average of the prices over a fixed period. If the result is above 1, the price is above its line. The indicator needs nothing more.
Setting it up step by step
- In TradingView, open the chart of the stock you want to look at.
- Set the bar interval: weekly bars for the RSL over 26 weeks, daily bars for the RSL over 26 days.
- Open the Pine Editor at the bottom and create a new, empty script for an indicator.
- Replace the existing text with the script from the next section.
- Save the script and add it to the chart. The indicator appears in its own pane below the price.
The names of the buttons may change with new versions of TradingView. The steps essentially stay the same.
The Pine script
//@version=6
indicator("RSL according to Levy", shorttitle = "RSL")
length = input.int(26, "Number of bars", minval = 2)
rsl = close / ta.sma(close, length)
plot(rsl, "RSL")
hline(1.0, "Line at 1")You may use, modify and share this script freely. It is provided without warranty. Check the result with your own calculation before relying on it.
What the lines do: the first sets the Pine Script version. The second gives the indicator a name. The third sets the number of bars, 26 by default, changeable in the settings. The fourth calculates the RSL: closing price divided by the simple average of the closing prices. The fifth draws the line, the sixth the horizontal line at 1.
If you want to reproduce Levy's original window, set 27 instead of 26. Levy formed the average from the current week and the 26 weeks before it.
Worked example for checking
Sample figures, not a real stock:
- The last 26 weekly closing prices add up to 2,600. The average is 100.
- The current weekly closing price is 108.
- RSL = 108 ÷ 100 = 1.08. So the indicator shows a value just above the line at 1.
With your own calculation in a spreadsheet you can check whether the script gives the same result.
You can see the top 15 per index without signing in on the RSL list.
View RSL listWithout TradingView: the RSL as a spreadsheet calculator
If you don't want to use a charting program, you can also calculate the RSL in a spreadsheet. Enter the 26 weekly closing prices in cells B2 to B27, the most recent last. In C27 you write =AVERAGE(B2:B27) and in D27 =B27/C27. D27 is your RSL.
A week later a new price is added in B28, and the range moves down one row: =AVERAGE(B3:B28) and =B28/C28. This way the time window always stays 26 weeks long.
This is also a good way to check the Pine script. If the spreadsheet and the indicator give the same result for the same prices, the setup is correct.
How to read the indicator
Above the line at 1 the price is above its average, below it the price is below. The further the line is from 1, the larger the distance.
Watch out for the current bar. On the weekly chart, the bar of the current week is only complete on Friday. Until then the RSL changes with every price. Only the value after the weekly close is comparable with a ranking based on weekly closing prices.
Small deviations from other sources are normal. They arise from different exchanges, trading hours, holidays or the treatment of dividends and stock splits in the price data.
What a single chart cannot do
The indicator shows you the RSL of a single stock. It does not tell you whether 1.08 is a lot or a little by comparison. For that you need the RSL of all stocks of an index side by side, sorted by size. After a broad advance, almost all stocks are above 1, and only the rank shows who is ahead.
That is exactly what the ranking by relative strength in RSL-scan does: it calculates the RSL for all stocks of a market and re-sorts them once a day. How rank and the threshold of 1 work together in fixed rules for entry and replacement is described in the rules of the RSL strategy. Without signing in, you can see the top 15 per index on the RSL list.
You can try the full ranking of all markets for 7 days with Scan Pro. No payment details, the trial ends automatically.
Try for 7 daysLimits
A self-written indicator is only as good as its data and its settings. So check once with your own calculation whether the result is correct.
The RSL knows no balance sheet, no valuation and no news. It describes how the price has stood relative to its average so far. Nobody knows whether it will continue that way.
Method and author
RSL-scan editorial team. RSL-scan ranks securities by relative strength (Levy RSL) within one market. This page describes how you implement the formula yourself in a third-party program. TradingView and Pine Script are trademarks of TradingView, Inc.; RSL-scan has no connection with it. No forecast. The basis is the ratio from R. A. Levy, Journal of Finance, 1967. All figures are sample values. As of 11/25/2026.
Frequently asked questions
Is Levy's RSL available as a ready-made indicator in TradingView?
With a short Pine script of your own you can set it up yourself: closing price divided by the simple average over 26 bars. Whether there are also ready-made scripts by other users, you should check yourself before using them.
How do I set 26 weeks in TradingView?
Choose weekly bars and leave the number of bars in the indicator at 26. On daily bars the same setting gives the RSL over 26 days.
Why does my TradingView value differ from RSL-scan?
Possible reasons are a different exchange, a weekly bar that is still running, different price data after dividends or splits, or a different number of bars.
What does the line at 1 mean?
Above 1 the price is above its moving average, below 1 it is below. That says nothing about future prices.
Can I create a ranking with the indicator?
No. The indicator shows the RSL of a single chart. For a ranking you need the RSL of all stocks of an index, sorted by size, as in the RSL-scan scanner.
Is RSL-scan connected with TradingView?
No. TradingView is a trademark of TradingView, Inc. This page only explains how you implement the formula there yourself.
Sources
- TradingView: Pine Script v6 User Manual, section Levels (hline) and examples with indicator() and plot(). https://www.tradingview.com/pine-script-docs/visuals/levels/ (accessed 11/25/2026).
- Levy, Robert A. (1967): "Relative Strength as a Criterion for Investment Selection". The Journal of Finance, vol. 22, no. 4, pp. 595-610. https://doi.org/10.1111/j.1540-6261.1967.tb00295.x
- Foliograph: Die RSL-Strategie nach Levy (German). Time window from the current week and the 26 weeks before it (27 prices). https://foliograph.ch/de/help/rsl-strategie (accessed 11/25/2026).
- RSL-scan, strategy page: formula RSL = price ÷ average price, time frames 26 weeks and 26 days. https://rsl-scan.com/strategy (accessed 11/25/2026).
- RSL-scan, RSL list: top 15 without signing in. https://rsl-scan.com/rsl-list (accessed 11/25/2026).
- All figures in the text are sample values.
The ranking is re-sorted once a day. Choose your market.
Go to the scannerNot a buy recommendation / not investment advice. Past performance is not a reliable indicator of future results.