OPEN-SOURCE SCRIPT

Dynamic 5DMA/EMA with Color for Multiple Products

100
🔹 Dynamic 5DMA/EMA with Slope-Based Coloring (All Timeframes)
This indicator plots a dynamic 5-period moving average that adapts intelligently to your chart's timeframe and product type — giving you a clean, slope-sensitive visual edge across intraday, daily, and weekly views.

✅ Key Features:
📈 Dynamic MA Length Scaling:
On intraday timeframes, the MA adjusts for your selected market session (RTH, ETH, VIX, or Futures), calculating a true 5-day average based on actual session length — not just a flat bar count.

🔄 Automatic Timeframe Detection:

Daily Chart: Uses standard 5DMA or 5EMA.

Weekly Chart: Applies a true 5-week MA.

Intraday Charts: Converts 5 days into bar-length equivalent dynamically.

🎨 Color-Coded Slope Logic:

Green = Rising MA (bullish slope)

Red = Falling MA (bearish slope)

Neutral slope = previous color held for visual continuity
No more guessing — direction is instantly clear.

⚠️ Built-In Slope Flip Alerts:
Set alerts when the slope of the MA turns up or down. Ideal for timing pullback entries or exits across any product.

⚙️ Session Settings for Proper Scaling:
Choose your product's market structure to ensure accurate 5-day conversion on intraday charts:

Stocks - RTH: 390 mins/day

Stocks - ETH: 780 mins/day

VIX: 855 mins/day

Futures: 1440 mins/day

This ensures the MA reflects 5 full trading days, regardless of session irregularities or bar interval.

📌 Why Use This Indicator?
Most MAs misrepresent trend direction on intraday charts because they assume static daily bar counts. This tool corrects that, then adds slope-based coloring to give you a fast, visual read on short-term momentum. Whether you’re swing trading SPY, scalping VIX, or position trading futures, this indicator keeps your view aligned with how institutions see moving averages across timeframes.

🔧 Best For:

VIX & volatility traders

Short-term SPY/SPX traders

Swing traders who value clean setups

Anyone wanting a true 5-day trend anchor on any chart

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.