OPEN-SOURCE SCRIPT
Mis à jour Linear Regression Drag-Drop,custom deviations & grid

Overview
This indicator lets you draw a precise linear regression channel between any two points in time that you choose — simply drag two time anchors onto the chart. Unlike TradingView's built-in regression tool, which is locked to a fixed lookback, this script gives you full manual control over the exact start and end of the regression window, plus a deviation-based channel, an optional mirrored grid, and a live stats table to help you judge the quality of the fit.
How It Works
Two draggable time anchors. You place a Start Time and an End Time directly on the chart. The script finds the bars closest to each timestamp and runs a least-squares linear regression on price between them.
Deviation channel. Around the regression line, the script plots four deviation bands (1x–4x). You can choose how the deviation is calculated:
Grid. A second set of lines can be drawn as a mirror image of the regression channel, anchored at the end point. You can choose:
A vertical shift input lets you offset the whole mirrored grid up or down by a multiple of the deviation, so it doesn't have to originate from the same anchor point as the main channel.
Fill and time markers. The area between the deviation bands is shaded, and vertical lines mark your two chosen times, so the exact regression window is always visible at a glance.
Stats table. A table (position and appearance configurable) shows:
How To Use
Drag the Start Time and End Time anchors onto the swing points, session boundaries, or range you want to analyze. The information table is there to help you judge whether a setup is high-probability before you act on it — not every regression window is worth trading, and the table is your filter:
Deviation tends to fit best on AUD/USD and EUR/USD when the pip size is set to a multiple of 10. Other currency pairs (JPY pairs, for example) will usually need a different pip size to get a well-scaled channel — adjust to taste per instrument.
Slope (%/day) gives you a quick read on trend strength: roughly 0.15% = a slow trend, 0.5% = a moderate trend, 1%+ = a steep trend. Use this as a guide for how aggressively price is moving through the window, not as a hard rule.
R² is helps quality check. A high R² means price tracked the line cleanly (more reliable for directional/continuation reads); a low R² means the window was choppy and the line is describing a range rather than a trend (better suited to mean-reversion reads at the deviation bands).
Grid mode adds a second dimension to your analysis: use Mirror Lines to project counter-trend/reversal zones, and Zero Slope to mark horizontal reaction levels. Combined with the ability to freely drag your time anchors to any two points on the chart, this turns the indicator into a fast, repeatable way to test different swing points and see how price is likely to react at the resulting grid levels.
Like any regression-based tool, its usefulness comes from context and repetition. The more windows and instruments you test it against, the better your feel for which slope/R²/deviation combinations mark genuinely high-probability points versus noise — the power of this indicator unfolds with practice.
Notes
This tool describes historical price behavior over a chosen window; it does not predict future price with certainty. Always combine it with your own risk management and additional confluence.
Deviation bands are descriptive statistics, not guaranteed support/resistance — treat penetrations of the outer bands as information, not automatic signals.
This indicator lets you draw a precise linear regression channel between any two points in time that you choose — simply drag two time anchors onto the chart. Unlike TradingView's built-in regression tool, which is locked to a fixed lookback, this script gives you full manual control over the exact start and end of the regression window, plus a deviation-based channel, an optional mirrored grid, and a live stats table to help you judge the quality of the fit.
How It Works
Two draggable time anchors. You place a Start Time and an End Time directly on the chart. The script finds the bars closest to each timestamp and runs a least-squares linear regression on price between them.
Deviation channel. Around the regression line, the script plots four deviation bands (1x–4x). You can choose how the deviation is calculated:
- StdDev — the statistical standard error of the residuals (how far price actually strayed from the line).
- Points (Pips) — a fixed pip value you define, useful when you want consistent, comparable band widths across different sessions or instruments rather than a value that changes with volatility.
Grid. A second set of lines can be drawn as a mirror image of the regression channel, anchored at the end point. You can choose:
- Mirror Lines — the mirror slopes in the opposite direction, useful for spotting counter-trend zones.
- Zero Slope — the mirror is flattened to horizontal, useful for marking flat reaction levels.
- None — hide the mirror set entirely.
A vertical shift input lets you offset the whole mirrored grid up or down by a multiple of the deviation, so it doesn't have to originate from the same anchor point as the main channel.
Fill and time markers. The area between the deviation bands is shaded, and vertical lines mark your two chosen times, so the exact regression window is always visible at a glance.
Stats table. A table (position and appearance configurable) shows:
- Slope (%/day) — the trend's daily rate of change, normalized as a percentage of the starting price, so it's comparable across instruments and timeframes.
- R² — how well the straight line actually fits price over that window (color-coded green/yellow/red).
- Deviation — shown directly in pips.
- Bars — the number of bars in the regression window.
How To Use
Drag the Start Time and End Time anchors onto the swing points, session boundaries, or range you want to analyze. The information table is there to help you judge whether a setup is high-probability before you act on it — not every regression window is worth trading, and the table is your filter:
Deviation tends to fit best on AUD/USD and EUR/USD when the pip size is set to a multiple of 10. Other currency pairs (JPY pairs, for example) will usually need a different pip size to get a well-scaled channel — adjust to taste per instrument.
Slope (%/day) gives you a quick read on trend strength: roughly 0.15% = a slow trend, 0.5% = a moderate trend, 1%+ = a steep trend. Use this as a guide for how aggressively price is moving through the window, not as a hard rule.
R² is helps quality check. A high R² means price tracked the line cleanly (more reliable for directional/continuation reads); a low R² means the window was choppy and the line is describing a range rather than a trend (better suited to mean-reversion reads at the deviation bands).
Grid mode adds a second dimension to your analysis: use Mirror Lines to project counter-trend/reversal zones, and Zero Slope to mark horizontal reaction levels. Combined with the ability to freely drag your time anchors to any two points on the chart, this turns the indicator into a fast, repeatable way to test different swing points and see how price is likely to react at the resulting grid levels.
Like any regression-based tool, its usefulness comes from context and repetition. The more windows and instruments you test it against, the better your feel for which slope/R²/deviation combinations mark genuinely high-probability points versus noise — the power of this indicator unfolds with practice.
Notes
This tool describes historical price behavior over a chosen window; it does not predict future price with certainty. Always combine it with your own risk management and additional confluence.
Deviation bands are descriptive statistics, not guaranteed support/resistance — treat penetrations of the outer bands as information, not automatic signals.
Notes de version
Bug Fixed: The lines disappear on new bar print. This has been fixed.Not: if you see an error on loading the indicator, it is most likely that the dates are out of range.
Just change the input dates to more recent dates and it should work fine
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.