OPEN-SOURCE SCRIPT
Z-Score Trend Channels [BackQuant]

Z-Score Trend Channels [BackQuant]
A self-contained price-statistics framework that turns a rolling z-score into price channels, bias states, and trade markers. Run either trend-following or mean-reversion from the same tool with clear, on-chart context.
What it is
Core idea (plain English math)
What you see on the chart
Inputs you will actually use
How to use it: trend-following playbook
How to use it: mean-reversion playbook
Reading the stats table
Parameter guidance (conceptual)
Practical examples
Potential Questions you might have
Summary
Z-Score Trend Channels gives you an adaptive mean, volatility-aware rails, a simple trend lens, and clear signals. Trade the trend by buying pullbacks in green and selling pullbacks in red, or fade stretched extremes back to the mean with defined risk. One framework, two strategies, consistent logic.
A self-contained price-statistics framework that turns a rolling z-score into price channels, bias states, and trade markers. Run either trend-following or mean-reversion from the same tool with clear, on-chart context.
What it is
- A rolling statistical map that measures how far price is from its recent average in standard-deviation units (z-score).
- Adaptive channels drawn in price space from fixed z thresholds, so the rails breathe with volatility.
- A simple trend proxy from z-score momentum to separate trending from ranging conditions.
- On-chart signals for pullback entries, stretched extremes, and practical exits.
Core idea (plain English math)
- Rolling mean and volatility - Over a lookback you get the average price and its standard deviation.
- Z-score - How many standard deviations the current price is above or below its average: z = (price - mean) / stdev. z near 0 means near average; positive is above; negative is below.
- Noise control - An EMA smooths the raw z to reduce jitter and false flickers.
- Channels back in price - Fixed z levels are converted back to price to form the upper, lower, and extreme rails.
- Trend proxy - A smoothed change in z is used as a lightweight trend-strength line. Positive strength with positive z favors uptrend; negative strength with negative z favors downtrend.
What you see on the chart
- Channels and fills - Mean, upper, lower, and optional extreme lines. The area mean->upper tints with the bearish color, mean->lower tints with the bullish color.
- Background tint (optional) - Soft green, red, or neutral based on detected trend state.
- Signals - Bullish Entry (triangle up) when z exits the oversold zone upward; Bearish Entry (triangle down) when z exits the overbought zone downward; Extreme markers (diamonds) at the extreme bands with a one-bar turn.
- Table - Current z, trend state, trend strength, distance to bands, market state tag, and a quick volatility regime label.
- Edge labels - MEAN, OB, and OS labels slightly projected forward with level values.
Inputs you will actually use
- Z-Score Period - Lookback for mean and stdev. Larger = slower and steadier rails, smaller = more reactive.
- Smoothing Period - EMA on z. Lower = earlier but choppier flips; higher = later but cleaner.
- Price Source - Default hlc3. Choose close if you prefer session-close logic.
- Upper and Lower Thresholds - Default around +2.0 and -2.0. Tighten for more signals, widen for fewer and stronger.
- Extreme Upper and Lower - Deeper stretch guards, e.g., +/- 2.5.
- Strength Period - EMA on z momentum. Sets how fast the trend proxy flips.
- Trend Threshold - Minimum absolute z to accept a directional bias.
- Visual toggles - Channels, signals, background tint, stats table, colors, and optional last-bar trend label.
How to use it: trend-following playbook
- Read the state - Uptrend when z > Trend Threshold and trend strength > 0. Downtrend when z < -Trend Threshold and trend strength < 0. Neutral otherwise.
- Entries - In an uptrend, prefer Bullish Entry signals that fire near the lower channel. In a downtrend, prefer Bearish Entry signals that fire near the upper channel.
- Stops - Conservative: beyond the extreme channel on your side. Tighter: just outside the standard band that framed the signal.
- Exits - For longs, exit or trim on a cross back through z = 0 or a clean tag of the upper threshold. For shorts, mirror with z = 0 up-cross or tag of the lower threshold. You can also reduce if trend strength flips against you.
- Adds - In strong trends, additional signals near your side’s band can be add points. Avoid adding once z hovers near the opposite band for several bars.
How to use it: mean-reversion playbook
- Find stretch - Standard reversions: Bullish Entry when z leaves the oversold zone upward; Bearish Entry when z leaves the overbought zone downward. Aggressive reversions: Extreme markers at extreme bands with a one-bar turn.
- Entries - Take the signal as price exits the zone. Prefer setups where trend strength is near zero or tilting against the prior push.
- Targets - First target is the mean line. A runner can aim for the opposite standard channel if momentum keeps flipping.
- Stops - Outside the extreme band beyond your entry. If fading without extremes, place risk just beyond the opposite standard band.
- Filters - Optional: skip counter-trend fades against a very strong trend state unless your risk is tight and predefined.
Reading the stats table
- Current Z-Score - Magnitude and sign of displacement now.
- Trend State - Uptrend, Downtrend, or Ranging.
- Trend Strength - Smoothed z momentum. Higher absolute values imply stronger directional conviction.
- Distance to Upper/Lower - Percent distance from price to each band, useful for sizing targets or judging room left.
- Market State - Overbought, Oversold, Extreme OB, Extreme OS, or Normal.
- Volatility Regime - High, Normal, or Low relative to recent distribution. Expect bands to widen in High and tighten in Low.
Parameter guidance (conceptual)
- Z-Score Period - Choose longer for a structural mean, shorter for a reactive mean.
- Smoothing Period - Lower for earlier but noisier reads; higher for slower but steadier reads.
- Thresholds - Start around +/- 2.0. Tighten for scalping or quiet ranges. Widen for noisy or fast markets.
- Trend Threshold and Strength Period - Raise to avoid weak, transient bias. Lower to capture earlier regime shifts.
Practical examples
- Trend pullback long - State shows Uptrend. Price tests the lower channel; z dips near or below the lower threshold; a Bullish Entry prints. Stop just below extreme lower; first target mean; keep a runner if trend strength stays positive.
- Mean-revert short - State is Ranging. z tags the extreme upper, an Extreme Bearish marker prints, then a Bearish Entry prints on the leave. Stop above extreme upper; target the mean; consider a runner toward the lower channel if strength turns negative.
Potential Questions you might have
- Why z-score instead of fixed offsets - Because the bands adapt with volatility. When the tape gets quiet the rails tighten, when it runs hot the rails expand. Your entries stay normalized.
- Do I need both modes - No. Many users run only trend pullbacks or only mean-reversions. The tool lets you toggle what you need and keep the chart readable.
- Multi-timeframe workflow - A common approach is to set bias from a higher timeframe’s trend state and execute on a lower timeframe’s signals that align with it.
Summary
Z-Score Trend Channels gives you an adaptive mean, volatility-aware rails, a simple trend lens, and clear signals. Trade the trend by buying pullbacks in green and selling pullbacks in red, or fade stretched extremes back to the mean with defined risk. One framework, two strategies, consistent logic.
סקריפט קוד פתוח
ברוח TradingView אמיתית, היוצר של הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יכולים לבדוק ולאמת את הפונקציונליות שלו. כל הכבוד למחבר! למרות שאתה יכול להשתמש בו בחינם, זכור שפרסום מחדש של הקוד כפוף לכללי הבית שלנו.
Check out whop.com/signals-suite for Access to Invite Only Scripts!
כתב ויתור
המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.
סקריפט קוד פתוח
ברוח TradingView אמיתית, היוצר של הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יכולים לבדוק ולאמת את הפונקציונליות שלו. כל הכבוד למחבר! למרות שאתה יכול להשתמש בו בחינם, זכור שפרסום מחדש של הקוד כפוף לכללי הבית שלנו.
Check out whop.com/signals-suite for Access to Invite Only Scripts!
כתב ויתור
המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.