MESA Adaptive Cycle Engine [MarkitTick]💡 The MESA Adaptive Cycle Engine is an advanced, dynamic trend-following overlay designed to adapt to market volatility and cyclical phases. Unlike traditional moving averages that suffer from significant lag during range-bound periods, this tool leverages digital signal processing to stay aligned with the market's dominant cycle. It features an integrated webhook automation system and a real-time risk management dashboard.
✨ Originality and Utility
Standard exponential or simple moving averages rely on fixed lookback periods, making them inherently flawed when market conditions shift from trending to cycling. This indicator utilizes the MESA (Maximum Entropy Spectral Analysis) Adaptive Moving Average (MAMA) and Following Adaptive Moving Average (FAMA) concepts. By measuring the phase rate of change via a Hilbert Transform, the moving averages mathematically adapt their alpha speeds. Furthermore, this script is uniquely engineered for modern automated trading, featuring a self-cleaning dashboard and dynamically constructed JSON payloads for external execution engines.
🔬 Methodology and Concepts
● The Hilbert Transform
At its core, the script applies a Hilbert Transform to the price source (defaulting to hl2) to extract the real and imaginary components of the market cycle.
● Phase and Period Calculation
By calculating the arctangent of the quadrature and in-phase components, it determines the current phase and dominant cycle period.
● Adaptive Alpha
The phase's rate of change dictates the alpha variable. In trending markets, the phase changes slowly, allowing the alpha to remain near the Fast Limit. In choppy markets, the phase changes rapidly, dropping the alpha toward the Slow Limit to prevent whipsaws.
● Risk Engine
The script establishes automated Stop Loss and Take Profit levels based on an ATR multiplier, updating dynamically upon regime shifts.
🎨 Visual Guide
● MAMA and FAMA Lines
The indicator plots two primary lines: the MAMA line (default Green) and the FAMA line (default Red).
● Regime Fill
The space between MAMA and FAMA is filled with a semi-transparent Bullish color when MAMA is above FAMA, and a Bearish color when MAMA is below FAMA.
● Entry Signals
A small upward triangle is plotted below the bar upon a Golden Cross (Buy Signal), and a downward triangle is plotted above the bar upon a Death Cross (Sell Signal).
● Analytics Dashboard
A table in the bottom-right corner displays the current Market Regime, Phase Volatility (ATR), and the active JSON Payload status.
📖 How to Use
Wait for a confirmed crossover. A Golden Cross (MAMA crossing above FAMA) initiates a Bullish regime, while a Death Cross initiates a Bearish regime.
Use the Regime Fill to hold positions; stay in a long position as long as the fill remains bullish.
Monitor the Dashboard for real-time ATR values to assist with manual trailing stops, or rely on the automated Risk Manager's calculated Take Profit (2x ATR) and Stop Loss (1x ATR).
Non-standard charts (like Heikin Ashi or Renko) will trigger a runtime warning, as cycle measurements rely on standard time-based OHLC data.
⚙️ Inputs and Settings
● MESA DSP Parameters
Price Source: Determines the input data (default hl2).
Fast Limit: The maximum alpha speed, usually set to 0.5.
Slow Limit: The minimum alpha speed, usually set to 0.05.
● Automation & JSON Payload
ATR Multiplier: Controls the width of the Stop Loss and Take Profit levels.
Webhook Action (Long/Short): Defines the string action injected into the outgoing JSON payload.
🔍 Deconstruction of the Underlying Scientific and Academic Framework
The indicator is deeply rooted in digital signal processing (DSP), specifically pioneered for trading by John Ehlers. The framework models market data as a complex waveform. By passing the data through a 4-bar WMA smoother and then applying a Hilbert Transform, the algorithm isolates the in-phase (I) and quadrature (Q) components. This orthogonal relationship allows the script to map the market's analytic signal onto a complex plane, solving for the instantaneous phase angle. The fundamental academic breakthrough here is using the derivative of this phase (the rate of phase change) to govern the exponential smoothing constant (alpha) of the moving average. This ensures the filter's bandwidth dynamically conforms to the signal's spectral density, offering high-fidelity smoothing without the commensurate group delay found in static linear filters.
⚠️ Disclaimer
All provided scripts and indicators are strictly for educational exploration and must not be interpreted as financial advice or a recommendation to execute trades. I expressly disclaim all liability for any financial losses or damages that may result, directly or indirectly, from the reliance on or application of these tools. Market participation carries inherent risk where past performance never guarantees future returns, leaving all investment decisions and due diligence solely at your own discretion.
Pine Script® indicator






















