OPEN-SOURCE SCRIPT
已更新

Gabriel's Adaptive MA

502
📜 Gabriel's Adaptive MA — Indicator Description
Gabriel's Adaptive Moving Average (GAMA) is a dynamic trend-following indicator that intelligently adjusts its smoothing based on both trend strength and market volatility.
It is designed to provide faster responsiveness during strong moves while maintaining stability during choppy or consolidating periods.

🧠 What it does:
This indicator plots a custom-built, highly dynamic Moving Average that adapts itself intelligently based on:

Trend Strength (via Perry Kaufman's Efficiency Ratio)

Market Volatility (via Tushar Chande's Volatility Ratio)

It reacts faster when the market is trending strongly and/or highly volatile,
and it smooths out and slows down when the market is choppy or calm.

🔍 How it works (step-by-step):
1. User Inputs:
length: (default 14)
How many bars to look back for calculations.

fastSC: Fastest possible smoothing constant (hardcoded as 2 / (2+1))

slowSC: Slowest possible smoothing constant (hardcoded as 2 / (30+1))

(These are used to control how fast/slow the KAMA can react.)

2. Calculate Trendiness — Kaufman Efficiency Ratio (ER):
Net Change = Absolute difference between current close and close from length bars ago.

Sum of Absolute Changes = Sum of absolute price changes between every bar inside the length window.

Efficiency Ratio (ER) = Net Change divided by Sum of Changes.

✅ If ER is close to 1 → Smooth, trending market.
✅ If ER is close to 0 → Choppy, sideways market.

3. Calculate Bumpiness — Volatility Ratio (VR):
Short-Term Volatility = Standard deviation of close over length.

Long-Term Volatility = Standard deviation of close over length * 2.

Volatility Ratio (VR) = Short-Term Volatility divided by Long-Term Volatility.

✅ If VR is >1 → Market is becoming more volatile recently.
✅ If VR is <1 → Market is calming down.

4. Create the Hybrid Alpha:
Multiply ER × VR.

Then square the result (math.pow(..., 2)).

This hybrid alpha decides how aggressive the MA should be based on both trend and volatility.

If ER and VR are both strong → big alpha → fast movement.

If ER and/or VR are weak → small alpha → slow movement.

5. Calculate the Final Adaptive Smoothing Constant (hybridSC):
hybridSC = slowSC + hybridAlpha × (fastSC - slowSC)

This smoothly interpolates between the slowest and fastest smoothing depending on market conditions.

6. Calculate and Plot the Adaptive MA:
The moving average is manually calculated:

hybridMA := na(hybridMA[1]) ? close : hybridMA[1] + hybridSC * (close - hybridMA[1])
It behaves like an EMA but with dynamic smoothing, not a fixed alpha.

✅ If hybridSC is high → MA hugs the price closely.
✅ If hybridSC is low → MA stays smooth and resists noise.

Finally, it plots this Adaptive MA on the chart in blue color.

📊 Visual Summary

Market Type What Happens to GAMA
Trending hard + volatile Follows price quickly
Trending hard + calm Follows steadily but carefully
Sideways + volatile Reacts carefully (won't chase noise)
Sideways + calm Smooths heavily (avoids fakeouts)
✨ Main Strengths:
Adapts automatically without you tuning settings manually every time market changes.

Responds smartly to both trend quality (ER) and market energy (VR).

Reduces lag during real moves.

Filters out false signals during choppy mess.

🧪 Key Innovation compared to normal MAs:

Traditional MA Gabriel's Adaptive MA
Same smoothing every bar Dynamic smoothing every bar
Slow during fast moves Adapts fast during real moves
No understanding of volatility or trendiness Full market sensitivity

⚡ **Simple One-Line Description:**
"Gabriel's Adaptive MA is a dynamic, trend-and-volatility-sensitive moving average that intelligently adjusts its speed to match market conditions."

發行說明
I finished coding the rest.
發行說明
I added Volume and 2 Alerts to it.
發行說明
I added a backtest Engine for an optimal settings search; place your strategy over the alert function. DM me for personal features.
發行說明
I added tooltips, coloring, inputs and new alerts.
發行說明
I made sure it ran without typos.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。