OPEN-SOURCE SCRIPT
AWR Optimized LR Graph

Hello Trading Viewers !
Drawing linear regression channels at the best place and for many periods can be time consuming.
In the library, I've found some indicators that draw 1 or 2 but based on fixed number of bars or a duration...
Not always relevant, that's why I decide to create this indicator.
It calculates 8 linear regression channels according to 8 differents configurable periods.
Each time, the indicator will calculate for each specified duration range the best linear regression line & channel (2 standard regressions) for that period and then plot it on the graph.
You can settle how many linear regression channels you want to display.
For period, defaults configurations (number of candles studied) are :
Period 1
min1 = 33
max1 = 66
Period 2
min2 = 67
max2 = 128
Period 3
min3 = 129
max3 = 255
Period 4
min4 = 256
max4 = 510
Period 5
min5 = 511
max5 = 1020
Period 6
min6 = 1021
max6 = 2040
Period 7
min7 = 2041
max7 = 3500
Period 8
min8 = 3501
max8 = 4999
This default settings provide short-term, mid term, long term and a very long-term view.
You have to go back on the chart to display the channels that start on previous period that are currently not on the screen.
You can set a specific color for each linear regression channels.
The linear regression line is based on the least squares method, meaning: it calculates along each period the gap between a linear & the price & squarred it. Then it defines the linear in order to have always the least distance between price and the linear.
The more the price deviates from its regression line, the more statistically likely it is to return to its regression line.
Application of Regression Lines in Trading
Regression lines are widely used in trading and financial analysis to understand market trends and make informed predictions. Here are some key applications:
1. Trend Identification – Traders use regression lines to visualize the general direction of a stock or asset price, helping to confirm an upward or downward trend.
2. Price Predictions – Linear regression models assist in estimating future price movements based on historical data, allowing traders to anticipate changes.
3. Risk Assessment – By analyzing the slope and variation of a regression line, traders can gauge market volatility and potential risks.
4. Support and Resistance Levels – Regression channels help traders identify support and resistance zones, providing insight into optimal entry and exit points in a trend.
5. You can also use the short period linear regression channels vs the long period linear regression channels to identify important pivot points.
Drawing linear regression channels at the best place and for many periods can be time consuming.
In the library, I've found some indicators that draw 1 or 2 but based on fixed number of bars or a duration...
Not always relevant, that's why I decide to create this indicator.
It calculates 8 linear regression channels according to 8 differents configurable periods.
Each time, the indicator will calculate for each specified duration range the best linear regression line & channel (2 standard regressions) for that period and then plot it on the graph.
You can settle how many linear regression channels you want to display.
For period, defaults configurations (number of candles studied) are :
Period 1
min1 = 33
max1 = 66
Period 2
min2 = 67
max2 = 128
Period 3
min3 = 129
max3 = 255
Period 4
min4 = 256
max4 = 510
Period 5
min5 = 511
max5 = 1020
Period 6
min6 = 1021
max6 = 2040
Period 7
min7 = 2041
max7 = 3500
Period 8
min8 = 3501
max8 = 4999
This default settings provide short-term, mid term, long term and a very long-term view.
You have to go back on the chart to display the channels that start on previous period that are currently not on the screen.
You can set a specific color for each linear regression channels.
The linear regression line is based on the least squares method, meaning: it calculates along each period the gap between a linear & the price & squarred it. Then it defines the linear in order to have always the least distance between price and the linear.
The more the price deviates from its regression line, the more statistically likely it is to return to its regression line.
Application of Regression Lines in Trading
Regression lines are widely used in trading and financial analysis to understand market trends and make informed predictions. Here are some key applications:
1. Trend Identification – Traders use regression lines to visualize the general direction of a stock or asset price, helping to confirm an upward or downward trend.
2. Price Predictions – Linear regression models assist in estimating future price movements based on historical data, allowing traders to anticipate changes.
3. Risk Assessment – By analyzing the slope and variation of a regression line, traders can gauge market volatility and potential risks.
4. Support and Resistance Levels – Regression channels help traders identify support and resistance zones, providing insight into optimal entry and exit points in a trend.
5. You can also use the short period linear regression channels vs the long period linear regression channels to identify important pivot points.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.