Linear Regression Trend Channel

This is my first public release of indicator code and my PSv4.0 version of "Linear Regression Channel", as it is more commonly known. It replicates TV's built-in "Linear Regression" without the distraction of heavy red/blue fill bleeding into other indicators. We can't fill() line.new() at this time in Pine Script anyways. I entitled it Linear Regression Trend Channel, simply because it seems more accurate as a proper description. I nicely packaged this to the size of an ordinary napkin within 20 lines of compact code, simplifying the math to the most efficient script I could devise that fits in your pocket. This is commonly what my dense intricate code looks like behind the veil, and if you are wondering why there is no notes, that's because the notation is in the variable naming. I excluded Pearson correlation because it doesn't seem very useful to me, and it would comprise of additional lines of code I would rather avoid in this public release. Pearson correlation is included in my invite-only advanced version of "Enhanced Linear Regression Trend Channel", where I have taken Linear Regression Channeling to another level of fully featured novel attainability using this original source code.

Features List Includes:
"Period" adjustment
"Deviation(s)" adjustment
"Extend Method" option to extend or not extend the upper, medial, and lower channeling

Showcased in the chart below is my free to use "Enhanced Schaff Trend Cycle Indicator", having a common appeal to TV users frequently. If you do have any questions or comments regarding this indicator, I will consider your inquiries, thoughts, and ideas presented below in the comments section, when time provides it. As always, "Like" it if you simply just like it with a proper thumbs up, and also return to my scripts list occasionally for additional postings. Have a profitable future everyone!
릴리즈 노트: Member appreciation for this indicator has now exceeded 500 likes, becoming my most favored published indicator. In recognition of this overwhelming gratitude, I am now freely offering an enhanced version of this indicator in highly optimized Pine Script with a few more features I believe are beneficial to TV members. Enjoy LRTC v2.0!

One major upgrade is, I added a correlation label mimicking TV's built-in version(displayed above too), yet this one is less likely to disappear off your chart. It will appear green in color with a positive upward trend and then red with a negative downward trend. You may also hover on this label revealing "tooltip=" contents, TV's NEW label.new() parameter. Two values will be displayed "onHover" showing Pearson's correlation coefficient(r) and the coefficient of determination(r2) with very high decimal precision.

All of this is surprisingly possible with the ever evolving "Power of Pine" condensed to only 20 lines of super compact Pine Script, the same tiny footprint as my original formulation. Thank you everyone for your kind support, and I will continue supporting the TradingView community within my power, as I have for two years now. MANY, MANY great things are in store for TV members via Pine in 2020 and onward... Yep, Pine's unrelenting destiny to come is even more empowerment to the great people of this quantitative community. It's only getting better folks!
오픈 소스 스크립트

진정한 TradingView의 정신에 따라, 이 스크립트의 작성자는 스크립트를 오픈소스로 게시했기에 거래자들이 이해하고 확인할 수 있습니다. 작가님께 건배! 스크립트를 무료로 사용할 수 있지만, 게시물에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 당신은 스크립트를 차트에 사용하기 위해 그것을 즐겨찾기 할 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?


I am trying hard to implement this in Python using Pandas Library....Can you please help me in explaining the high level logic or any reference to article. Will be greatly helpful...
Is there a way to offset the starting bar index and set an ending bar index?
For eg. I want to see the regression trend from bar index -20 to -10. The current script always gives me latest X bars back based on "period'. I was hoping to modify the script in such a way that I can define starting and ending bars.
@imzeeshan, It is "possible" because my Invite-Only "Enhanced Linear Regression Trend Channel" accommodates that feature. It's proprietary code...
imzeeshan midtownsk8rguy
@midtownsk8rguy, That's fair. Good job man.
whats the pros and cons of linear regression?
I like this without the heavy colouring. Could you show me how to add additional channels please with say dev. 1 on same chart
That's wonderful!!! I have finally the open code of Regression line, instead of the embedded one.
But the version give by default by Tradingview also include the Pearson's R test, may you add it to your code?
@saucius, I just kept it simple to the regression channel alone, but Pearson's R would involve correlation() and label.new(). I wanted to have the worlds smallest implementation of this script, that was my goal. I included R in my more advanced Linear Regression Trend Channel I published before this script. TV's Linear Regression does NOT have negative R like it should have, so theirs is incorrect actually...