21dma-structure TV script
Moving Averages (21dma-structure)
As an intermediate-term swing trader, the 21-day moving average is the backbone of my system. Over time, I’ve simplified my approach to the point where this is really the only indicator I keep on my charts — aside from a few key lines to help define structure and pivots.
To give that moving average more context and flexibility, I use a 21-day EMA structure, built from the lows, highs, and closing prices. This creates a dynamic zone — not just a single line — that helps me visualize trend, momentum, and risk. It gives enough room for natural volatility, while still keeping me anchored to the trend.
Everything I do — from entry to trimming to holding — revolves around this structure. When price is above it, I lean in. When it’s below and declining, I stay out or manage risk tighter. Simple, clean, and consistent.

21dma-STRUCTURE Overview The 21dma-STRUCTURE indicator is a sophisticated overlay indicator that visualizes price action relative to a triple 21-period exponential moving average structure. Originally developed by BalarezoCapital and enhanced by PrimeTrading, this indicator provides clear visual cues for trend direction and momentum through dynamic bar coloring and EMA structure analysis. Key Features Triple EMA Structure - 21 EMA High: Tracks the exponential moving average of high prices - 21 EMA Close: Tracks the exponential moving average of closing prices - 21 EMA Low: Tracks the exponential moving average of low prices - Dynamic Cloud: Gray fill between high and low EMAs for visual structure reference Smart Bar Coloring System - Blue Bars: Price closes above all three EMAs (strong bullish momentum) - Pink Bars: Daily high falls below the lowest EMA (strong bearish signal) - Gray Bars: Neutral conditions or transitional phases - Color Memory: Maintains previous color until new condition is met Dynamic Center Line - Trend-Following Color: Green when all EMAs are rising, red when all are falling - Color Persistence: Maintains trend color during sideways movement - Visual Clarity: Thicker center line for easy trend identification Customizable Visual Elements - Adjustable line thickness for all EMA plots - Customizable colors for bullish and bearish conditions - Configurable trend colors for uptrend and downtrend phases - Optional bar color changes with toggle control How to Use Trend Identification - Rising Green Center Line: All EMAs trending upward (bullish structure) - Falling Red Center Line: All EMAs trending downward (bearish structure) - Flat Center Line: Maintains last trend color during consolidation Momentum Analysis - Blue Bars: Strong bullish momentum with price above entire EMA structure - Pink Bars: Strong bearish momentum with high below lowest EMA - Gray Bars: Neutral or transitional momentum phases Entry and Exit Signals - Bullish Setup: Look for blue bars during green center line periods - Bearish Setup: Look for pink bars during red center line periods - Exit Consideration: Watch for color changes as potential momentum shifts Structure Trading - Support/Resistance: Use EMA cloud as dynamic support and resistance zones - Breakout Confirmation: Bar color changes can confirm structure breakouts - Trend Continuation: Color persistence suggests ongoing momentum Settings Visual Customization - Change Bar Color: Toggle to enable/disable bar coloring - Line Size: Adjust thickness of EMA lines (default: 3) - Bullish Candle Color: Customize blue bar color - Bearish Candle Color: Customize pink bar color Trend Colors - Uptrend Color: Color for rising EMA center line (default: green) - Downtrend Color: Color for falling EMA center line (default: red) - Cloud Color: Fill color between high and low EMAs (default: gray) Advanced Features Modified Bar Logic Unlike traditional EMA systems, this indicator uses refined conditions: - Bullish signals require close above ALL three EMAs - Bearish signals require high below the LOWEST EMA - Enhanced precision reduces false signals compared to single EMA systems Trend Memory System - Intelligent color persistence during sideways movement - Reduces noise from minor EMA fluctuations - Maintains trend context during consolidation periods Performance Optimization - Efficient calculation methods for real-time performance - Clean visual design that doesn't clutter charts - Compatible with all timeframes and instruments Best Practices Multi-Timeframe Analysis - Use higher timeframes to identify overall trend direction - Apply on multiple timeframes for confluence - Combine with weekly/monthly charts for position trading Risk Management - Use bar color changes as early warning signals - Consider position sizing based on EMA structure strength - Set stops relative to EMA support/resistance levels Combination Strategies - Pair with volume indicators for confirmation - Use alongside RSI or MACD for momentum confirmation - Combine with key support/resistance levels Market Context - More effective in trending markets than choppy conditions - Consider overall market environment and sector strength - Adjust expectations during high volatility periods Technical Specifications - Based on 21-period exponential moving averages - Uses Pine Script v6 for optimal performance - Overlay indicator that works with any chart type - Maximum 500 lines for clean performance Ideal Applications - Swing trading on daily charts - Position trading on weekly charts - Intraday momentum trading (adjust timeframe accordingly) - Trend following strategies - Structure-based trading approaches Disclaimer This indicator is for educational and informational purposes only. It should not be used as the sole basis for trading decisions. Always combine with other forms of analysis, proper risk management, and consider your individual trading plan and risk tolerance. Compatible with Pine Script v6 | Works on all timeframes | Optimized for trending markets
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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
Last updated