gaperton

Linear Regression Relative Strength

gaperton 已更新   
[image/x/iZvwDWEY/

Relative Strength indicator comparing the current symbol to SPY (or any other benchmark). It may help to pick the right assets to complement the portfolio build around core ETFs such as SPY.

The general idea is to show if the current symbol outperforms or underperforms the benchmark (SPY by default) when bought some certain time ago. Relative performance is displayed as percent and is calculated for three different time ranges - short (1 mo by default), mid (1 quarter), and long (half a year). To smooth the volatility, the script uses linear regression to estimate the trend and takes the start and the end points of the linear regression line to compute the relative strength.

It is important to remember that the script shows the gain relative to SPY (or other selected benchmark), not the asset's gain. Therefore, it may indicate that the asset is profitable, but it still may lose value if SPY is in downtrend.

Therefore, it is crucial to check other indicators before making a decision. In the example above, standard linear regression for one quarter is used to indicate the direction of the trend.
版本注释:
Added source filtering options:

- "None" - Relative Strength computed using the raw data: the current price and the price back in time.
- "3-point average" - an average of the three neighboring prices is used instead of the raw price.
- "5-point average" - an average of the five neighboring prices is used instead of the raw price.
- "Linear Regression Trend" - instead of the prices, linear regression trend is computed for the period and its first and last values are taken.

Comparison with baseline is now optional. You can turn it off in options and see how the asset alone performed.
版本注释:
Fixed bug in the calculation.

New formula:

Gain = ( endPrice - startPrice ) / startPrice
RS = Gain( X ) - Gain( S&P )

The values are percent and they have clear economic sense. Given the period is P, RS is the profit which you would receive from buying the asset P days ago when compared to S&P (or other selected baseline).
版本注释:
- Added source selection, which is daily by default. It keeps the indicator values when switching to intraday.
- 3 and 5 points average filters now use the weighted average, with wights 1-2-3 and 1-2-3-4-5 respectively. It reduces the delay of the filter to one and two bars.
- Changed the colors. Red is a short one, yellow is mid, and the blue area chart is long range.
- Changed the default periods so the red line is really close to MACD (and it can be used as MACD).
版本注释:
- Added Sharpe Ratio as another strength metric option
- Various usability fixes
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?