Linear Regression - Auto Adjust To Ideal Pearson's R (Min & Max)

Gentleman-Goat アップデート済   
This is meant as a partner to my linear regression strategy script. This one however is just the indicator only so you can overlay the technique over other strategies.

To use this script you need to understand what Pearson's R is; which is how correlated a set of data is to a line within a given deviation (+ or -).

If the Pearson's R is negative (-) then the trend is going upwards. If the value is positive (+) then the trend is going downwards.

There is a lot of debate as to what the ideal negative and positive values are for the Pearson's R, so you can change these in the settings. What the script will do is attempt to automatically find (and draw the trend lines ) based on a given minimum period and a maximum period (both set in the settings) that match the ideal Pearson's R settings selected.

Ideally the data is MOST correlated the closest it is to -1 or 1. This means the pattern is very reliable.

This script was designed and works very well with the bar replay mode. You may need a more professional version of TradingView to use this correctly. This mode allows you to see the script in action as it mutates and changes according to the new data being introduced.

I've pre-set the Pearson's R (+) and (-) ranges to what I think is ideal.

This new version cleans up the code a bit and adds a better infobox thanks to richard santos and some modifications I did to his original code base. The colors of the info box are designed to better match the new oscillator partner script I uploaded as well.
The box adjustment was not working so well so removed it for now.
I changed the default values to 0.85 for both positive and negative to match the oscillator indicator. These can be changed in the settings. I also added alerts for the upper and upper max + lower and lower max trend lines. You can enable these alerts by going to alerts and adding a new alert then selecting my indicator and selecting from the alert options. Enjoy!
Added new alerts for detecting bullish,bearing or sideways trends that you can set and alerts for both the long term and short term when these occurs so users can use webhooks to trigger trades based on these conditions. Some traders like to trade differently during different cycles, so this will allow you to do this programmatically now :). Thanks to TradeBoneDog for this suggestion :).

You can disable what shows in the infobox as well in the settings if you only care about seeing certain results so it doesn't get so cluttered in there ;).

-=Gentleman Goat=- Download the TradingView Input Optimizer at

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。