MA Crossover with Adaptive Trend Strength

๐ Overview
This TradingView indicator plots two moving averages (Fast & Slow) with user-selected types (T3, EMA, SMA, HMA), visual crossovers, and dynamically calculates an adaptive trend strength score using Z-scores of multiple features. Optional higher timeframe (HTF) confirmation is supported. A color-filled region between the MAs visually indicates momentum direction.
โ๏ธ Inputs & Controls
๐ Moving Average Settings
Fast MA Length: Length of the fast-moving average (default: 9).
Slow MA Length: Length of the slow-moving average (default: 21).
MA Type: Type of moving average used (T3, EMA, SMA, HMA).
Source: Input data source (default: close).
T3 Volume Factor: Only used when T3 is selected, controls smoothing (range: 0โ1).
๐จ Visual Controls
Bullish Fill Color: Fill color when Fast MA is above Slow MA.
Bearish Fill Color: Fill color when Fast MA is below Slow MA.
Show Gradient Fill: Enable or disable the colored area between Fast & Slow MAs.
Trend Label Position: Choose where the trend strength label appears (top or bottom).
Label Update Interval: Number of bars between label updates (reduces clutter).
โฑ Multi-Timeframe Support
Higher Timeframe: Timeframe used for confirmation (default: 60 min).
Use HTF Confirmation: Enables filtering of trend score by higher timeframe trend direction.
๐ Lookback Configuration
Auto Lookback Based on Timeframe: Dynamically adapts scoring lookback period per chart timeframe.
Manual Lookback: Manual fallback lookback length when auto is off.
๐งฎ MA Calculation Options
T3 MA: Custom T3 function with exponential moving averages and volume factor.
EMA/SMA: Built-in Pine functions (ta.ema, ta.sma).
HMA: Hull Moving Average using WMA calculations.
๐ Trend Strength Calculation
๐ง Z-Score Inputs
Distance between MAs (zDist)
Slope of the Fast MA (zSlope)
Volume (zVol)
ATR (zATR)
๐ Choppiness & Adaptive Weighting
A Choppiness Index (based on ATR & price range) reduces score impact in sideways markets.
Dynamically adjusts Z-score weights:
W1: Distance
W2: Slope
W3: Volume
W4: ATR
๐ HTF Confirmation
Optionally multiplies the trend score by the direction of the higher timeframe trend to filter noise.
๐ฉ Plot & Visual Elements
๐ MA Lines
Plots Fast and Slow MA lines in colors based on selected MA type.
๐ Gradient Fill
Fills the area between Fast and Slow MAs with opacity proportional to their difference.
Colors based on bullish/bearish condition.
๐ท๏ธ Trend Strength Label
Updates every n bars (Label Update Interval).
Shows:
Trend Classification: Weak, Moderate, Strong
Numerical Score
Label position (top or bottom) is configurable.
๐ Crossover Signals
Bullish Crossover ("B"): Fast MA crosses above Slow MA.
Bearish Crossover ("S"): Fast MA crosses below Slow MA.
Labels are plotted at crossover points.
Old labels are removed after a threshold (100) to reduce chart clutter.
๐ Score Summary Table
A table showing:
Max Score within the lookback period
Min Score
HTF Confirmation Status (ON / OFF)
Updates on the same user-defined interval as the trend label.
๐จ Alerts
Condition Description
Bullish MA Cross Fast MA crosses above Slow MA
Bearish MA Cross Fast MA crosses below Slow MA
These are provided via alertcondition() for use in alert creation.
๐ Customization Tips
Turn off the gradient fill for a cleaner chart.
Use HTF confirmation to reduce false positives in ranging markets.
Adjust label update frequency to prevent visual clutter on faster timeframes.
Use T3 MA with volume factor for smoother signals in volatile markets.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda โ ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda โ ketahui lebih lanjut di sini.