Indicator · Pine Script v6 · On the chart

MESA Phase-Adaptive Band Trend

by theonetrade· code credited to SchizoQuant

The MESA Phase-Adaptive Band Trend is an overlay indicator that dynamically adjusts volatility bands and trend detection using Hilbert Transform phase analysis.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code115
Settings13inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

115 lines of Pine Script v6 from assets/indicator/bit-exact/mesa_phase_adaptive_band_trend_schizoquant_mGCGl56t.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

mesa_phase_adaptive_band_trend_schizoquant_mGCGl56t.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SchizoQuant

//@version=6
indicator("MESA Phase-Adaptive Band Trend", overlay=true)

// USER INPUTS
string phaseTip = "Fast Limit sets the quickest phase response the indicator can use, while Slow Limit sets the slowest. Increase Fast Limit for stronger reactions during rapid phase movement. Lower Slow Limit for more smoothing when phase activity is weak."
string trendTip = "Trend Length controls the EMA centerline, while Volatility Length controls how much return history is used for the adaptive bands. Increase Trend Length for a smoother centerline and increase Volatility Length for steadier band width."
string bandTip  = "Active Multiplier controls band width when phase activity is strong, while Slow Multiplier controls band width when phase activity is weak. Lower Active Multiplier for faster regime changes during active markets, and increase Slow Multiplier to require larger moves during quieter conditions."
string colorTip = "Bullish Color is used for bullish regimes and LONG signals, while Bearish Color is used for bearish regimes and SHORT signals."

float src         = input.source(title="Source", defval=hl2, group="Phase Settings", tooltip="Choose the price source used to estimate Hilbert phase behavior and calculate the trend.")
float fastLimit   = input.float(title="Fast Limit", defval=0.50, minval=0.01, maxval=1.0, step=0.01, group="Phase Settings", inline="P1", tooltip=phaseTip)
float slowLimit   = input.float(title="Slow Limit", defval=0.05, minval=0.001, maxval=1.0, step=0.001, group="Phase Settings", inline="P1", tooltip=phaseTip)
int   trendLength = input.int(title="Trend Length", defval=20, minval=2, group="Trend Settings", inline="T1", tooltip=trendTip)
int   volLength   = input.int(title="Volatility Length", defval=20, minval=2, group="Trend Settings", inline="T1", tooltip=trendTip)
float activeMult  = input.float(title="Active Multiplier", defval=1.5, minval=0.1, step=0.1, group="Adaptive Bands", inline="B1", tooltip=bandTip)
float slowMult    = input.float(title="Slow Multiplier", defval=3.0, minval=0.1, step=0.1, group="Adaptive Bands", inline="B1", tooltip=bandTip)
bool  showBands   = input.bool(title="Show Bands", defval=true, group="Visualization", tooltip="Show or hide the phase-responsive volatility bands. Turning this off only changes the chart display and does not affect the trend or signal calculations.")
bool  showFill    = input.bool(title="Show Fill", defval=true, group="Visualization", tooltip="Show or hide the shaded area between the upper and lower adaptive bands. This is visual only and does not change the indicator calculations.")
bool  showSignals = input.bool(title="Show Signals", defval=true, group="Visualization", tooltip="Show or hide LONG and SHORT markers when the active trend regime changes. Turning this off does not change the underlying regime calculation.")
bool  colorBars   = input.bool(title="Color Bars", defval=true, group="Visualization", tooltip="Color the price candles according to the currently active trend regime. Turning this off only removes candle coloring and does not affect signals.")
color longColor   = input.color(title="Bullish Color", defval=color.rgb(57, 255, 20), group="Color Settings", inline="C1", tooltip=colorTip)
color shortColor  = input.color(title="Bearish Color", defval=color.rgb(138, 43, 226), group="Color Settings", inline="C1", tooltip=colorTip)

// CALCULATIONS
float smooth       = (4.0 * src + 3.0 * nz(src[1], src) + 2.0 * nz(src[2], src) + nz(src[3], src)) / 10.0
var float period   = 10.0
float periodFactor = 0.075 * nz(period[1], 10.0) + 0.54

float detrender = (0.0962 * smooth + 0.5769 * nz(smooth[2]) - 0.5769 * nz(smooth[4]) - 0.0962 * nz(smooth[6])) * periodFactor
float q1        = (0.0962 * detrender + 0.5769 * nz(detrender[2]) - 0.5769 * nz(detrender[4]) - 0.0962 * nz(detrender[6])) * periodFactor
float i1        = nz(detrender[3])

float jI = (0.0962 * i1 + 0.5769 * nz(i1[2]) - 0.5769 * nz(i1[4]) - 0.0962 * nz(i1[6])) * periodFactor
float jQ = (0.0962 * q1 + 0.5769 * nz(q1[2]) - 0.5769 * nz(q1[4]) - 0.0962 * nz(q1[6])) * periodFactor

float i2Raw = i1 - jQ
float q2Raw = q1 + jI

var float i2 = 0.0
var float q2 = 0.0

i2 := 0.2 * i2Raw + 0.8 * nz(i2[1])
q2 := 0.2 * q2Raw + 0.8 * nz(q2[1])

float reRaw = i2 * nz(i2[1]) + q2 * nz(q2[1])
float imRaw = i2 * nz(q2[1]) - q2 * nz(i2[1])

var float re = 0.0
var float im = 0.0

re := 0.2 * reRaw + 0.8 * nz(re[1])
im := 0.2 * imRaw + 0.8 * nz(im[1])

float angle          = re != 0.0 ? math.atan(im / re) * 180.0 / math.pi : 0.0
float rawPeriod      = angle != 0.0 ? math.abs(360.0 / angle) : nz(period[1], 10.0)
float previousPeriod = nz(period[1], 10.0)
float limitedPeriod  = math.min(rawPeriod, 1.5 * previousPeriod)

limitedPeriod := math.max(limitedPeriod, 0.67 * previousPeriod)
limitedPeriod := math.max(6.0, math.min(50.0, limitedPeriod))
period        := 0.2 * limitedPeriod + 0.8 * previousPeriod

var float phase = 0.0
phase := i1 != 0.0 ? math.atan(q1 / i1) * 180.0 / math.pi : nz(phase[1])

float deltaPhase = nz(phase[1]) - phase
deltaPhase := math.max(deltaPhase, 1.0)

float alphaPhase = fastLimit / deltaPhase
alphaPhase := math.max(alphaPhase, slowLimit)

float phaseRange    = math.max(fastLimit - slowLimit, 0.0001)
float phaseActivity = math.max(0.0, math.min(1.0, (alphaPhase - slowLimit) / phaseRange))

float trend       = ta.ema(src, trendLength)
float priceReturn = src[1] != 0.0 ? (src - src[1]) / src[1] : 0.0
float volatility  = ta.stdev(priceReturn, volLength)[1]

float adaptiveMult = slowMult - (slowMult - activeMult) * phaseActivity
float upperBand    = trend + adaptiveMult * volatility * trend
float lowerBand    = trend - adaptiveMult * volatility * trend

// SIGNALS
bool long  = close > upperBand
bool short = close < lowerBand

var int SQ = 0

if long
    SQ := 1
else if short
    SQ := -1

bool longSignal  = SQ == 1 and SQ[1] != 1
bool shortSignal = SQ == -1 and SQ[1] != -1

// COLORS
color col = SQ == 1 ? longColor : shortColor

// PLOTS
plot(trend, title="Trend", color=col, linewidth=2)
upperPlot = plot(showBands ? upperBand : na, title="Upper Phase Band", color=color.new(longColor, 35), linewidth=1)
lowerPlot = plot(showBands ? lowerBand : na, title="Lower Phase Band", color=color.new(shortColor, 35), linewidth=1)
fill(upperPlot, lowerPlot, title="Phase Band Fill", color=showFill ? color.new(col, 90) : na)
plotshape(showSignals and longSignal, title="Long Signal", style=shape.triangleup, location=location.belowbar, color=longColor, size=size.small, text="LONG", textcolor=color.white)
plotshape(showSignals and shortSignal, title="Short Signal", style=shape.triangledown, location=location.abovebar, color=shortColor, size=size.small, text="SHORT", textcolor=color.white)
barcolor(colorBars ? col : na)

// ALERTS

alertcondition(longSignal, title="Long Signal", message="Phase-Responsive Band Trend Long Signal on {{ticker}}")
alertcondition(shortSignal, title="Short Signal", message="Phase-Responsive Band Trend Short Signal on {{ticker}}")

Overview

MESA Phase-Adaptive Band Trend evaluates cyclical phase activity between fast and slow limits to adaptively scale volatility multipliers around an exponential moving average centerline. When active phase movement or regime shifts occur, it displays directional signals, plots upper and lower adaptive bands with optional channel filling, and paints candle bars according to the active regime.

Details

Published by

theonetrade on GitHub

Code credit

SchizoQuant, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Sourcesourcehl2src
Fast Limitfloat0.50fastLimit
Slow Limitfloat0.05slowLimit
Trend Lengthint20trendLength
Volatility Lengthint20volLength
Active Multiplierfloat1.5activeMult
Slow Multiplierfloat3.0slowMult
Show BandsbooltrueshowBands
Show FillbooltrueshowFill
Show SignalsbooltrueshowSignals
Color BarsbooltruecolorBars
Bullish Colorcolorcolor.rgb(57, 255, 20)longColor
Show all 13 settings
SettingTypeDefaultVariable
Bearish Colorcolorcolor.rgb(138, 43, 226)shortColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
257 stars

An overlay indicator that combines an ATR-based SuperTrend trailing stop with an integrated RSI-derived midline calculation on the price chart. The SuperTrend uses an ATR period and factor multiplier to plot dynamic green or red trend lines based on price dire

Indicator v5 TrendVolatility & bands
Updated 2 months ago · None stated GitHub repository of SuperTrend ATR + RSI
114 stars

ADX Strategy (original) is an overlay indicator that identifies trend-following trade signals using the Average Directional Index (ADX) combined with a Simple Moving Average filter. A long signal is generated when the ADX rises above a user-defined trend level

Indicator v4 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of ADX Strategy (original)

Moon Dev Lunar Sniper

by moondevonyt
98 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Lunar Sniper
57 stars

Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision
55 stars

The VibeTrader Signal System is an overlay indicator that identifies trend direction and potential reversal conditions. It calculates a Supertrend line alongside Bollinger Bands and a 14-period RSI indicator. The script highlights bullish and bearish trends by

Indicator v6 TrendVolatility & bands
Updated 7 months ago · Apache-2.0 GitHub repository of VibeTrader Signal System

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers