Exp Regression Slope Annualized with R-squared TRADINGVIEW
Forums › ProRealTime English forum › ProBuilder support › Exp Regression Slope Annualized with R-squared TRADINGVIEW
- This topic has 20 replies, 6 voices, and was last updated 3 years ago by RP-Markets.
-
-
03/26/2021 at 10:01 PM #165457
Hi
I was wondering if it was possible to convert such indicator for PRT: this is a useful tool to build a portfolio by ranking stocks by strength based on Andreas Clenow’s book “Stocks on the Move” .
Here’s the strategy:
1. Determine the 90 day annualized exponential regression slope for each stock
2. Determine the 90 day R-squared value for each of the stock
3. Multiply #1 * #2 and then sort from highest to lowest —> screener PRT
4. Buy the top stocks based on the formula ((AccountValue * 0.001)/ATR(20))Thanks.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// Exponential Regression Slope Annualized with R-squared Histogram// by SparkyFlarystudy(title="Exponential Regression Slope Annualized with R-squared Histogram", shorttitle="Exponential Regression Slope Annualized with R-squared", format=format.percent, overlay=false)length = input(90, title="Slope length")rSquaredThreshold = input(0.0, title="R-squared threshold", minval=0, maxval=1)withRsquared = input(true, title="Multiply by R-squared?")withAnnualize = input(true, title="Annualize slope?")daysInYear = input(252, title="Number of bars in a year(if slope is annualized)")src = input(close, title="Source")//natural log of pricenlPrice = log(src)//alexgrover's regression slope codex = bar_indexy = nlPricex_ = sma(x,length)y_ = sma(y,length)mx = stdev(x,length)my = stdev(y,length)c = correlation(x,y,length)slope = c * (my/mx)//inter = y_ - slope*x_//reg = x*slope + interexp_slope = slopeannualized_slope = (pow(exp(slope),daysInYear) - 1) * 100rSquared = pow(correlation(cum(1), nlPrice, length), 2)slopeAnnualized_with_Rsquared = withAnnualize ? annualized_slope * (withRsquared ? rSquared : 1) : exp_slope * (withRsquared ? rSquared : 1)trend = rSquared>rSquaredThresholdrising = slopeAnnualized_with_Rsquared>slopeAnnualized_with_Rsquared[1]falling = slopeAnnualized_with_Rsquared<slopeAnnualized_with_Rsquared[1]up = slopeAnnualized_with_Rsquared>0down = slopeAnnualized_with_Rsquared<0up_rising_color = color.new(color.green, 0)up_falling_color = color.new(color.green, 50)down_falling_color = color.new(color.red, 0)down_rising_color = color.new(color.red, 50)col = trend and up and rising?up_rising_color:trend and up and falling?up_falling_color:trend and down and falling?down_falling_color:trend and down and rising?down_rising_color : color.grayplot(slopeAnnualized_with_Rsquared, title="Annualized slope x R-squared", style=plot.style_histogram, color = col, linewidth=3)03/26/2021 at 10:12 PM #16545903/28/2021 at 7:49 PM #16556303/29/2021 at 8:45 AM #16560003/29/2021 at 5:28 PM #16566003/30/2021 at 8:07 AM #16570403/30/2021 at 5:02 PM #165767Hi Nicolas
Thanks for your feedback.
I did it two times but for whatever reason, the pic did not show up.
I uploaded a screen capture (PNG file, 75ko)…same problem.If you click the link, you can see the picture/detail: https://fr.tradingview.com/script/QWHjwm4B-Exponential-Regression-Slope-Annualized-with-R-squared-Histogram/
04/08/2021 at 8:49 PM #16657809/16/2021 at 4:06 PM #177735Hello Nicholas
It would be really really nice if you could implement this screener. Actually you don’t need the indicator itself in the chart, but as a criterion to screen a list with it.
The annualized exponential regression multiplied by the R² value is then simply the sorting criterion, similar to how you can sort lists by RSL. However, if the stock price intersects the 100 day average, the indicator gets the value 0 and you get out of a stock.
Advantage of the method of Clenow is that one finds little volatile values, which run like clockwork upward.
Many thanks in advance.
Greetings Ronny
Translated with http://www.DeepL.com/Translator (free version)
09/16/2021 at 4:07 PM #17773609/16/2021 at 6:29 PM #177742Hi,
Here is the code for the screener (might be incorrect so please check). Note that only the 50 first results are returned in the screener. It makes it difficult to verify that the stocks you own are still in the 20% of the stock universe. There are workarounds though (such as creating multiple screeners with a condition on the momentum value).
Cheers
Jerome
1234567val = (EXP(250*LOG(EXP(LinearRegressionSlope[90](log(close)))))-1)*R2[90](log(close))capi = Average[90](Volume)*Average[90](Close) > 50000bullish = close > Average[100](Close)testVol = abs(close/close[1]-1) > 0.15volatile = summation[90](testVol)penny = Close < 5SCREENER[bullish and capi and not volatile and not penny](val as "Momentum")1 user thanked author for this post.
09/17/2021 at 7:36 AM #17775909/17/2021 at 7:43 AM #177764Would it still be possible to sort the results in descending order by the value ExpRegression*R2? (I think this should be the variable “val”)
The largest value above09/17/2021 at 7:52 AM #177766Sorry now i see val = Momentum
but I actually forgot one point.
Can you still exclude stocks that have made a gap of more than 15% in the last few days?Thank you very much for your work
09/17/2021 at 7:52 AM #177767As you can see from line 7, VAL is the sorting criterion in use.
As to descending order, you can choose the preferred order clicking the title of the column in ProScreener. -
AuthorPosts
Find exclusive trading pro-tools on