OPEN-SOURCE SCRIPT
Monotonic Trend Consensus [QuantAlgo]

🟢 Overview
Monotonic Trend Consensus is a trend-following oscillator built on rank correlation between price and time rather than moving averages or crossovers. It scores how consistently price is ordered across multiple lookback windows and combines them into a single bounded reading on a -1 to +1 scale, holding the same meaning on any symbol or timeframe so traders can separate a broadly aligned trend from directionless noise and read when a move has stretched to saturation.

🟢 How It Works
The foundation is Spearman rank correlation between price and time, computed over each active window. Closes inside the window are ranked against one another, time forms its own rising sequence of ranks, and the difference between the two collapses to a single coefficient (rho):
Pine Script®
The coefficient reads +1 when each bar closes above the last in unbroken order, 0 when there is no consistent order, and -1 when each bar steps lower. Because it scores ordering rather than smoothing price into a line, it reflects the current window directly rather than trailing behind it, though it still needs a full window of bars to form. Ranking also limits the pull of any single outlier bar, and the bounded output is what lets one threshold hold across markets without rescaling.
A single window describes direction; the tool runs several and averages them into a consensus spanning fast, medium, and slow horizons:
Pine Script®
Agreement is then measured as the share of windows leaning the same way as the consensus, and this conviction figure must clear a floor before a direction prints, working alongside the strength threshold:
Pine Script®
A reading registers only when both clear at once: consensus past the threshold and windows aligned enough to meet the conviction floor. Fail either and the line stays flat. With Show Neutral on, those flat stretches reset to neutral; with it off, the line holds its last direction until the next qualifying move.

🟢 Signal Interpretation
▶ Bullish Consensus (Green): Consensus sits above the upper threshold with enough windows aligned, meaning recent bars are ordered upward across horizons. Trend traders read the turn into green as a possible long or continuation as the score presses toward +1. Mean-reversion traders treat a reading pinned near +1 as a stretched, broadly-agreed advance rather than a buy, and look to fade only once the line rolls back off the extreme, since the score can hold high through a sustained trend.
▶ Bearish Consensus (Red): Consensus sits below the lower threshold with conviction met, with bars ordered downward across horizons. Trend traders read the turn into red as a possible short or continuation as the score presses toward -1. Mean-reversion traders treat a reading pinned near -1 as a saturated decline where a bounce becomes more plausible, and look to fade on the turn back up rather than at the low itself.
▶ Neutral (Gray): With Show Neutral on, the line goes gray whenever no direction qualifies, either because consensus sits inside the threshold or conviction falls short. The zero line acts as the balance point and behaves like support or resistance for the reading itself: a score rejected at zero from above points to bullish order reasserting, a score capped at zero from below points to bearish order holding, and a clean break through leans toward a regime change. Reading this midline behavior against price is where market structure tools pair well, separating a base building above a structural level from a coil forming under overhead supply. Trend traders stand aside until the line commits; mean-reversion traders find less to work with here than at the edges.
▶ Reading the Extremes: The axis caps at +1 and -1, marking maximum agreement across every active window. Trend traders take an extreme as a sign a move is still in force; mean-reversion traders take it as a stretched zone and watch for the score to turn back toward zero as agreement breaks. An extreme that aligns with a known structural level gives a fade a cleaner reference than one in open space, and neither read holds on the extreme alone, since a strong trend can stay saturated before it cools.

🟢 Features
▶ Preconfigured Presets: Three setups map to different holding styles. "Default" suits swing work on 4-hour and daily charts, pairing a mid-range window spread of 8, 13, 21, and 34 with a 0.35 threshold and a 60% conviction floor, so a direction needs both strength and agreement before it flags. "Fast Response" pulls the windows in to 5, 8, 13, and 21 and eases the threshold and conviction floor so the reading keeps pace with quicker intraday swings. "Smooth Trend" stretches the windows out to 21, 34, 55, and 89 and raises both gates for daily and weekly position trading, where a premature flip costs more than a late one. Choosing a preset takes over the manual window, threshold, and conviction fields.

▶ Built-in Alerts: Four conditions track every change in state. "Bullish Trend Signal" triggers when the consensus confirms to the upside. "Bearish Trend Signal" triggers when it confirms to the downside. "Trend Lost / Neutral" triggers when an active direction fades back to flat, which is also the event a mean-reversion trader watches for after an extreme. "Any Trend Change" rolls the two directional events into a single notification for anyone who wants one alert covering both ways.

▶ Visual Customization: Six color schemes (Classic, Aqua, Cosmic, Cyber, Neon, and Custom) carry a matched pair of bullish and bearish colors through the consensus line, its tiered gradient fill down to the zero baseline, and the optional bar and background tints. Marker lines sit at the positive and negative trigger levels to show the zone the consensus has to cross, and each window's own score can be switched on as a faint backing line so you can see which horizons are driving or dragging the combined figure. Bar coloring paints the price candles in the active trend color at an adjustable transparency, while background coloring spreads that tint across the pane.

Monotonic Trend Consensus is a trend-following oscillator built on rank correlation between price and time rather than moving averages or crossovers. It scores how consistently price is ordered across multiple lookback windows and combines them into a single bounded reading on a -1 to +1 scale, holding the same meaning on any symbol or timeframe so traders can separate a broadly aligned trend from directionless noise and read when a move has stretched to saturation.
🟢 How It Works
The foundation is Spearman rank correlation between price and time, computed over each active window. Closes inside the window are ranked against one another, time forms its own rising sequence of ranks, and the difference between the two collapses to a single coefficient (rho):
The coefficient reads +1 when each bar closes above the last in unbroken order, 0 when there is no consistent order, and -1 when each bar steps lower. Because it scores ordering rather than smoothing price into a line, it reflects the current window directly rather than trailing behind it, though it still needs a full window of bars to form. Ranking also limits the pull of any single outlier bar, and the bounded output is what lets one threshold hold across markets without rescaling.
A single window describes direction; the tool runs several and averages them into a consensus spanning fast, medium, and slow horizons:
Agreement is then measured as the share of windows leaning the same way as the consensus, and this conviction figure must clear a floor before a direction prints, working alongside the strength threshold:
A reading registers only when both clear at once: consensus past the threshold and windows aligned enough to meet the conviction floor. Fail either and the line stays flat. With Show Neutral on, those flat stretches reset to neutral; with it off, the line holds its last direction until the next qualifying move.
🟢 Signal Interpretation
▶ Bullish Consensus (Green): Consensus sits above the upper threshold with enough windows aligned, meaning recent bars are ordered upward across horizons. Trend traders read the turn into green as a possible long or continuation as the score presses toward +1. Mean-reversion traders treat a reading pinned near +1 as a stretched, broadly-agreed advance rather than a buy, and look to fade only once the line rolls back off the extreme, since the score can hold high through a sustained trend.
▶ Bearish Consensus (Red): Consensus sits below the lower threshold with conviction met, with bars ordered downward across horizons. Trend traders read the turn into red as a possible short or continuation as the score presses toward -1. Mean-reversion traders treat a reading pinned near -1 as a saturated decline where a bounce becomes more plausible, and look to fade on the turn back up rather than at the low itself.
▶ Neutral (Gray): With Show Neutral on, the line goes gray whenever no direction qualifies, either because consensus sits inside the threshold or conviction falls short. The zero line acts as the balance point and behaves like support or resistance for the reading itself: a score rejected at zero from above points to bullish order reasserting, a score capped at zero from below points to bearish order holding, and a clean break through leans toward a regime change. Reading this midline behavior against price is where market structure tools pair well, separating a base building above a structural level from a coil forming under overhead supply. Trend traders stand aside until the line commits; mean-reversion traders find less to work with here than at the edges.
▶ Reading the Extremes: The axis caps at +1 and -1, marking maximum agreement across every active window. Trend traders take an extreme as a sign a move is still in force; mean-reversion traders take it as a stretched zone and watch for the score to turn back toward zero as agreement breaks. An extreme that aligns with a known structural level gives a fade a cleaner reference than one in open space, and neither read holds on the extreme alone, since a strong trend can stay saturated before it cools.
🟢 Features
▶ Preconfigured Presets: Three setups map to different holding styles. "Default" suits swing work on 4-hour and daily charts, pairing a mid-range window spread of 8, 13, 21, and 34 with a 0.35 threshold and a 60% conviction floor, so a direction needs both strength and agreement before it flags. "Fast Response" pulls the windows in to 5, 8, 13, and 21 and eases the threshold and conviction floor so the reading keeps pace with quicker intraday swings. "Smooth Trend" stretches the windows out to 21, 34, 55, and 89 and raises both gates for daily and weekly position trading, where a premature flip costs more than a late one. Choosing a preset takes over the manual window, threshold, and conviction fields.
▶ Built-in Alerts: Four conditions track every change in state. "Bullish Trend Signal" triggers when the consensus confirms to the upside. "Bearish Trend Signal" triggers when it confirms to the downside. "Trend Lost / Neutral" triggers when an active direction fades back to flat, which is also the event a mean-reversion trader watches for after an extreme. "Any Trend Change" rolls the two directional events into a single notification for anyone who wants one alert covering both ways.
▶ Visual Customization: Six color schemes (Classic, Aqua, Cosmic, Cyber, Neon, and Custom) carry a matched pair of bullish and bearish colors through the consensus line, its tiered gradient fill down to the zero baseline, and the optional bar and background tints. Marker lines sit at the positive and negative trigger levels to show the zone the consensus has to cross, and each window's own score can be switched on as a faint backing line so you can see which horizons are driving or dragging the combined figure. Bar coloring paints the price candles in the active trend color at an adjustable transparency, while background coloring spreads that tint across the pane.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
🟢 Access our best trading & investing tools here (3-day FREE trial): whop.com/quantalgo/
🟢 Free Special Edition indicators: joinquantalgo.com/special-editions
🟢 Discord: discord.gg/hJaFyGEAyX
🟢 Free Special Edition indicators: joinquantalgo.com/special-editions
🟢 Discord: discord.gg/hJaFyGEAyX
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
🟢 Access our best trading & investing tools here (3-day FREE trial): whop.com/quantalgo/
🟢 Free Special Edition indicators: joinquantalgo.com/special-editions
🟢 Discord: discord.gg/hJaFyGEAyX
🟢 Free Special Edition indicators: joinquantalgo.com/special-editions
🟢 Discord: discord.gg/hJaFyGEAyX
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.