TradingView
alexgrover
Nov 20, 2017 8:18 PM

Regression Line Formula 

EUR/GBPOANDA

描述


A regression line is simply a single line that best fits the data.

In the pinescript you can plot a linear regression line using the linreg function.

Here i share the entire calculation of the linear regression line, you are free to take the code and modify the functions in the script for creating your own kind of filter.



Hope you enjoy :)
评论
CAB_Member
the linreg function on the trading view pine asks for an offset, which number in your formula is representing that?
alexgrover
@khodakarami, add the parameter offset as an input, then replace x by (x - offset) in line 16
jdeleon999
I'm trying to plot this in Excel. Can you teach me how to get the data points of the regression line so I can plot them in a graph?
NareshBiyani
@jdeleon999, I am also interested in to know the same .
Eternal_Gains
Hey Alex,
I'm just trying to get the exact function ported from pine to python,
do you have any idea how the "correlation" function works internally, or in other words could you mokup your formula without using any build in pine functions?

Thanks
alexgrover
@cmos, Hi cmos, in python try using pandas with .rolling(window).corr where window is the correlation coefficient period, pandas allow you to compute any rolling statistic by using rolling(). The correlation coefficient from pine is calculated with : sma(y*x,length) - sma(y,length)*sma(x,length) divided by stdev(length*y,length)*stdev(length*x,length) where stdev is based on the naïve algorithm.
Eternal_Gains
@alexgrover, you nailed it works perfectly!
fx_analyst7
@cmos, can you share your code please?
Soviethead
@fx_analyst7, did you find the solution?
更多