ucsgears

Linear Regression Slope

Corrected Version, for
UCSgears_Linear Regression Slope


VERSION - 2 (https://www.tradingview.com/v/l9bUW1FZ/) updated for Custom Length, and fixed some formula glitches.
Remove from Favorite Scripts Add to Favorite Scripts
// Created by UCSgears -- Version 1 (redone)
// Simple linear regression slope - Good way see if the trend is accelarating or decelarating

study(title="UCSGEARS - Linear Regression Slope", shorttitle="UCS-LRS", overlay=false)
src = close
len = input(defval=5, minval=1, title="Slope Length")
lrc = linreg(src, 50, 0)
lrs = (lrc-lrc[len])/len
alrs = sma(lrs,9)
loalrs = sma(lrs,50)

uacce = lrs > alrs and lrs > 0 and lrs > loalrs
dacce = lrs < alrs and lrs < 0 and lrs < loalrs

scolor = uacce ? green : dacce ? red : blue

plot(lrs, color = scolor, title = "Linear Regression Slope", style = histogram, linewidth = 4)
plot(alrs, color = white, title = "Average Slope")
plot(0, title = "Zero Line", color = white)
This script was updated: Linear Regression Slope - Version 2
gatorNic
2 years ago
good stuff! thanks
Reply
gmax
5 months ago
how i can add it to my strategy to trade when histogram turns green? Does the color in the histogram represents some value of the regression slope?
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out