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. Indicator

Indicator

Indicator

Indicator

Indicator

Indicator

Indicator

[blackcat] L2 Ehlers MESA Stochastic IndicatorLevel: 2
Background
John F. Ehlers introuced MESA Stochastic Indicator in Jan, 2014.
Function
The MESA Stochastic oscillator, a stochastic successor that removes the effect of spectral dilation through the use of a roofing filter.
Key Signal
MESAStochastic --> Ehlers MESA Stochastic Indicator fast line
Trigger --> Ehlers MESA Stochastic Indicator slow line
Pros and Cons
100% John F. Ehlers definition translation, even variable names are the same. This help readers who would like to use pine to read his book.
Remarks
The 101th script for Blackcat1402 John F. Ehlers Week publication.
Readme
In real life, I am a prolific inventor. I have successfully applied for more than 60 international and regional patents in the past 12 years. But in the past two years or so, I have tried to transfer my creativity to the development of trading strategies. Tradingview is the ideal platform for me. I am selecting and contributing some of the hundreds of scripts to publish in Tradingview community. Welcome everyone to interact with me to discuss these interesting pine scripts.
The scripts posted are categorized into 5 levels according to my efforts or manhours put into these works.
Level 1 : interesting script snippets or distinctive improvement from classic indicators or strategy. Level 1 scripts can usually appear in more complex indicators as a function module or element.
Level 2 : composite indicator/strategy. By selecting or combining several independent or dependent functions or sub indicators in proper way, the composite script exhibits a resonance phenomenon which can filter out noise or fake trading signal to enhance trading confidence level.
Level 3 : comprehensive indicator/strategy. They are simple trading systems based on my strategies. They are commonly containing several or all of entry signal, close signal, stop loss, take profit, re-entry, risk management, and position sizing techniques. Even some interesting fundamental and mass psychological aspects are incorporated.
Level 4 : script snippets or functions that do not disclose source code. Interesting element that can reveal market laws and work as raw material for indicators and strategies. If you find Level 1~2 scripts are helpful, Level 4 is a private version that took me far more efforts to develop.
Level 5 : indicator/strategy that do not disclose source code. private version of Level 3 script with my accumulated script processing skills or a large number of custom functions. I had a private function library built in past two years. Level 5 scripts use many of them to achieve private trading strategy. Indicator

Indicator

MESA Adaptive Moving Average - Improved MTFThis indicator is a huge upgrade to my original MTF MESA
Plots are now extremely smooth and accurate on all timeframes **
Missing data points are automatically filled with the "best fit"
This is a Trend indicator and should be used to trade "top-down" aka:
Start with the Daily chart to confirm a trend
Move to 4H
2H
Etc...
Use your favorite entry method or simply watch for wicks forming when the price gets near the MESA adaptive moving average.
This is one of the few indicators that I've been using for years with success. Being able to plot both the current & higher timeframe MESA
can sometimes feel like cheating.
Due to the nature of the recursive calculation, you may notice slight differences between this version of MESA and others that either
approximate higher timeframes with fewer samples or make use of the latest "Resolution" argument in Pinescript V4. Both of which are
fine, until you start looking at M5 charts while plotting the Daily MESA.
As always, happy trading!
** Currently supports
M 1,3,5,15,30,45
H 1,2,3,4
Day 1
Week 1
Month 1 Indicator

Strategy

Strategy

Indicator

Indicator

Dominant Cycle Tuned RsiIntroduction
Adaptive technical indicators are importants in a non stationary market, the ability to adapt to a situation can boost the efficiency of your strategy. A lot of methods have been proposed to make technical indicators "smarters" , from the use of variable smoothing constant for exponential smoothing to artificial intelligence.
The dominant cycle tuned rsi depend on the dominant cycle period of the market, such method allow the rsi to return accurate peaks and valleys levels. This indicator is an estimation of the cycle finder tuned rsi proposed by Lars von Thienen published in Decoding the Hidden Market Rhythm/Fine-tuning technical indicators using the dominant market vibration/2010 using the cycle measurement method described by John F.Ehlers in Cybernetic Analysis for Stocks and Futures .
The following section is for information purpose only, it can be technical so you can skip directly to the The Indicator section.
Frequency Estimation and Maximum Entropy Spectral Analysis
“Looks like rain,” said Tom precipitously.
Tom would have been a great weather forecaster, but market patterns are more complex than weather ones. The ability to measure dominant cycles in a complex signal is hard, also a method able to estimate it really fast add even more challenge to the task. First lets talk about the term dominant cycle , signals can be decomposed in a sum of various sine waves of different frequencies and amplitudes, the dominant cycle is considered to be the frequency of the sine wave with the highest amplitude. In general the highest frequencies are those who form the trend (often called fundamentals) , so detrending is used to eliminate those frequencies in order to keep only mid/mid - highs ones.
A lot of methods have been introduced but not that many target market price, Lars von Thienen proposed a method relying on the following processing chain :
Lars von Thienen Method = Input -> Filtering and Detrending -> Discrete Fourier Transform of the result -> Selection using Bartels statistical test -> Output
Thienen said that his method is better than the one proposed by Elhers. The method from Elhers called MESA was originally developed to interpret seismographic information. This method in short involve the estimation of the phase using low amount of information which divided by 360 return the frequency. At first sight there are no relations with the Maximum entropy spectral estimation proposed by Burg J.P. (1967). Maximum Entropy Spectral Analysis. Proceedings of 37th Meeting, Society of Exploration Geophysics, Oklahoma City.
You may also notice that these methods are plotted in the time domain where more classic method such as : power spectrum, spectrogram or FFT are not. The method from Elhers is the one used to tune our rsi.
The Indicator
Our indicator use the dominant cycle frequency to calculate the period of the rsi thus producing an adaptive rsi . When our adaptive rsi cross under 70, price might start a downtrend, else when our adaptive rsi crossover 30, price might start an uptrend. The alpha parameter is a parameter set to be always lower than 1 and greater than 0. Lower values of alpha minimize the number of detected peaks/valleys while higher ones increase the number of those. 0.07 for alpha seems like a great parameter but it can sometimes need to be changed.
The adaptive indicator can also detect small top/bottoms of small periods
Of course the indicator is subject to failures
At the end it is totally dependent of the dominant cycle estimation, which is still a rough method subject to uncertainty.
Conclusion
Tuning your indicator is a great way to make it adapt to the market, but its also a complex way to do so and i'm not that convinced about the complexity/result ratio. The version using chart background will be published separately.
Feel free to tune your indicators with the estimator from elhers and see if it provide a great enhancement :)
Thanks for reading !
References
for the calculation of the dominant cycle estimator originally from www.davenewberg.com
Decoding the Hidden Market Rhythm (2010) Lars von Thienen
Ehlers , J. F. 2004 . Cybernetic Analysis for Stocks and Futures: Cutting-Edge DSP Technology to Improve Your Trading . Wiley
Indicator

MESA Adaptive Moving AverageIntro
One of Ehlers most well-known indicators! I've seen many variations of this on TradingView, however, none seem to be true to the original released by Ehlers himself.
I've taken it upon myself to simply translate the MAMA into Pinescript, instead of re-writing like some others have done.
You can use it as a very effective & adaptive moving average with other signals or
as a standalone signal.
In the case that you're going to use it for signals and not simple technical trading (non-quantitative),
I've also added a threshold parameter to filter out weak signals.
My MAMA indicator is different from others in very simple ways - I don't use the nz() command, which sets all "Not a Number" values to 0. In others' scripts, you immediately load the indicator with several 0 values,
causing a slight lag in future calculations since this code is recursive (refers to previous values it generated).
In my version, I simply wait until the script has access to all the bar data it needs, instead of instantly performing calculations and
setting erroneous values to 0. In this case, we start with the correct values (or closer to correct).
If you want to compare this indicator the current most popular MAMA by LazyBear, you'll notice it often gives buy and sell crosses one bar earlier than theirs.
Setting Parameters
Source - the data series to perform calculations on. (Initially, Ehlers himself favored hl/2, but conceded that there isn't empirical benefit over close.)
Fast Limit - controls how quickly the MAMA will "ratchet up" fast price action. (Higher values are faster)
Slow Limit - controls how closely the FAMA will follow the MAMA. (Again, higher is faster. You typically want the FAMA to be slower though.)
Crossover Threshold - simple error thresholding to limit the number of weak trade signals. (Lower means lower tolerance)
Show Crosses? - show/hide the arrows at moving average crosses
Indicator

Indicator

Indicator

Indicator

Indicator

Indicator

Strategy

Strategy
