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!
Remove from Favorite Scripts Add to Favorite Scripts
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...
x11joe saucius
@saucius, I agree, I'm looking for this also.
Quite an elegant script!!!
been done already...
@ballofpaper, Thanks for you endearing comment. I already know... because I endorsed glaz's version release on the GS forum before mine. He released firstly, so I gave him some credit. glaz and I were working on the same problem simultaneously yet independently. There have been numerous outstanding requests for its algorithm on the GS forum, and after months of waiting, I decided, the time is now. My version is another mathemagical way to generate Linear Regression Channel that is pure Pine powered excluding the use of pow() and sqrt(). For the record, I had this days before glaz released his implementation. Another prominent member on TV can attest for that if he so wishes to. I decided to sit on it and build upon it for my other published enhanced version. I published my enhanced version the same day glaz released his oddly. This is the base code for it, free for all now on TV to expand upon in novel ways.
dang, well done sir
This is excellent, nice work friend!
Home Stock Screener Forex Screener Crypto Screener Economic Calendar Shows How It Works Chart Features Pricing House Rules Moderators Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Help Center Refer a friend Feature Request Blog & News Twitter
Profile Profile Settings Account and Billing Refer a friend My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out