OPEN-SOURCE SCRIPT
Improved McGinley Dynamic

Improved McGinley Dynamic
Description
The McGinley Dynamic is an adaptive moving average originally developed by John R. McGinley. Unlike SMA or EMA, which use fixed smoothing, McGinley adjusts dynamically to market speed. This version includes implementation refinements and stability safeguards ensuring consistent behavior in Pine Script, along with suggested adaptations for practical trading use.

Key Features
The McGinley Dynamic indicator incorporates a smoothing factor that changes based on market volatility. This adaptive behavior is designed to move more slowly in upward markets (to help traders ride the trend longer), but speeds up when prices fall, reflecting the market's tendency for quicker downside moves. The core formula is:
Pine Script®
Implementation Notes
Some public implementations of the McGinley Dynamic suffer from numerical instability under certain price conditions. This version improves consistency by adding ratio clamping, na handling and stable initialization logic.
Pine Script®
How to Use (Classic Interpretation)
Traditionally, used like a moving average to spot support/resistance and align with prevailing price direction.
How I Use It — Resonant Timeframe (“The Pain”)
This interpretation does not treat the McGinley Dynamic as universally meaningful on all timeframes. Instead, timeframe selection is based on empirical respect — observing where price consistently interacts with the McGinley in a structurally meaningful way.

Method
Look for the Resonant Timeframe. They are evaluated by checking if price historically:
Timeframes with random interaction are ignored. This is not parameter curve fitting we do not assume McGinley works equally well on every timeframe or instrument. No tuning is performed to optimize past results.
“The Pain”
Due to its recursive and adaptive formula, McGinley often behaves like a dynamic equilibrium level. This makes McGinley act as a pain threshold: the level where weak hands capitulate and new participants step in.
A decisive break and acceptance below the McGinley on a resonant timeframe indicate that the prior support structure has failed, allowing price to search for a new equilibrium.

Use for Short Limit Buy and general Positioning
McGinley is particularly useful for placing short limit buy orders near its line during pullbacks in uptrends, or for general directional positioning (holding above it = bullish bias). It is not a standalone entry trigger or filter — it serves as a reference level within a broader system. It is advisable to use the McGinley Dynamic in conjunction with other indicators to confirm signals and manage risks.

Recommended Settings
The indicator is controlled by a single parameter, Length (N):
Rule of Thumb: To emulate a 20-day EMA, John McGinley suggested using an N value of 10 (half the period).
Recommended Timeframe
Daily or above.
🇯🇵 日本語概要(Japanese Summary)
McGinley インジケーターは、価格の変動に自動的に適応する移動平均で、従来の移動平均線が抱える「遅れ」や「過剰反応」を抑えることを目的としています。市場の速度に応じて計算式が調整されるため、急激な値動きでも滑らかなラインを維持しつつ、価格により密着した動きを示します。その結果、トレンドの把握やノイズの軽減に役立つ、より実用的な平均線として利用されます。
中文概要(Chinese Summary)
McGinley 指標是一種能自動適應價格變化速度的移動平均線,旨在減少傳統均線常見的「延遲」與「過度反應」問題。其公式會根據市場波動調整,使線條在劇烈走勢中仍保持平滑,同時更貼近實際價格。這種特性使 McGinley 成為一種更能反映真實趨勢、並有效降低雜訊的實用型平均線工具。
Disclaimer:
This script is a research tool for market structure analysis and educational purposes only. It does not constitute financial advice. Trading involves risk.
Description
The McGinley Dynamic is an adaptive moving average originally developed by John R. McGinley. Unlike SMA or EMA, which use fixed smoothing, McGinley adjusts dynamically to market speed. This version includes implementation refinements and stability safeguards ensuring consistent behavior in Pine Script, along with suggested adaptations for practical trading use.
Key Features
The McGinley Dynamic indicator incorporates a smoothing factor that changes based on market volatility. This adaptive behavior is designed to move more slowly in upward markets (to help traders ride the trend longer), but speeds up when prices fall, reflecting the market's tendency for quicker downside moves. The core formula is:
md = md[1] + (close - md[1]) / (N * math.pow(close / md[1], 4
Implementation Notes
Some public implementations of the McGinley Dynamic suffer from numerical instability under certain price conditions. This version improves consistency by adding ratio clamping, na handling and stable initialization logic.
md := nz(md[1]) == 0 ? ta.sma(src, length) :
nz(md[1]) + (src - nz(md[1])) /
(length * math.pow(math.max(math.min(src / nz(md[1]), 2.0), 0.5), 4))
How to Use (Classic Interpretation)
Traditionally, used like a moving average to spot support/resistance and align with prevailing price direction.
How I Use It — Resonant Timeframe (“The Pain”)
This interpretation does not treat the McGinley Dynamic as universally meaningful on all timeframes. Instead, timeframe selection is based on empirical respect — observing where price consistently interacts with the McGinley in a structurally meaningful way.
Method
Look for the Resonant Timeframe. They are evaluated by checking if price historically:
- Treats McGinley as support or dynamic equilibrium
- Interacts near candle body lows or within lower wicks.
- Shows repeatable structural respect
Timeframes with random interaction are ignored. This is not parameter curve fitting we do not assume McGinley works equally well on every timeframe or instrument. No tuning is performed to optimize past results.
“The Pain”
Due to its recursive and adaptive formula, McGinley often behaves like a dynamic equilibrium level. This makes McGinley act as a pain threshold: the level where weak hands capitulate and new participants step in.
A decisive break and acceptance below the McGinley on a resonant timeframe indicate that the prior support structure has failed, allowing price to search for a new equilibrium.
Use for Short Limit Buy and general Positioning
McGinley is particularly useful for placing short limit buy orders near its line during pullbacks in uptrends, or for general directional positioning (holding above it = bullish bias). It is not a standalone entry trigger or filter — it serves as a reference level within a broader system. It is advisable to use the McGinley Dynamic in conjunction with other indicators to confirm signals and manage risks.
Recommended Settings
The indicator is controlled by a single parameter, Length (N):
Rule of Thumb: To emulate a 20-day EMA, John McGinley suggested using an N value of 10 (half the period).
Recommended Timeframe
Daily or above.
🇯🇵 日本語概要(Japanese Summary)
McGinley インジケーターは、価格の変動に自動的に適応する移動平均で、従来の移動平均線が抱える「遅れ」や「過剰反応」を抑えることを目的としています。市場の速度に応じて計算式が調整されるため、急激な値動きでも滑らかなラインを維持しつつ、価格により密着した動きを示します。その結果、トレンドの把握やノイズの軽減に役立つ、より実用的な平均線として利用されます。
中文概要(Chinese Summary)
McGinley 指標是一種能自動適應價格變化速度的移動平均線,旨在減少傳統均線常見的「延遲」與「過度反應」問題。其公式會根據市場波動調整,使線條在劇烈走勢中仍保持平滑,同時更貼近實際價格。這種特性使 McGinley 成為一種更能反映真實趨勢、並有效降低雜訊的實用型平均線工具。
Disclaimer:
This script is a research tool for market structure analysis and educational purposes only. It does not constitute financial advice. Trading involves risk.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.