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.

Adjustable MA Structure

Modified by PrimeTrading — originally by BalarezoCapital

The Adjustable MA Structure is a visual trend framework that highlights directional bias and structure using three dynamic moving averages: one based on high, one on close, and one on low. It helps traders quickly assess whether price is in a confirmed uptrend, downtrend, or neutral zone.


🔧 Key Features

✅ Adaptive to Timeframe

  • Automatically uses Daily settings for intraday/daily charts, and Weekly settings for weekly charts.

  • Separate inputs for MA length and type (SMA or EMA) depending on timeframe.

🎯 Structure Logic

The indicator plots:

  • MA High: moving average of highs (top band)

  • MA Close: moving average of closes (center line)

  • MA Low: moving average of lows (bottom band)

These act like dynamic structure bands. The trend direction is defined only when all three MAs are rising or falling:

  • Uptrend: All MAs rising → center line turns gray

  • Downtrend: All MAs falling → center line turns pink

  • 🔄 Neutral: Mixed trend → center line holds last color

🌫️ Structure Cloud

The space between MA High and MA Low is filled with a neutral gray cloud, which defines the "structure zone." Price trading inside this range often signals chop or indecision.


🟩 Bar Color Logic (Optional)

When enabled (Change Bar Color), bars are colored based on their position relative to the structure:

  • Bullish Color (default black): Close is above all 3 MAs.

  • Bearish Color (default pink):

    • If "Use High Below Structure" is ON: bar is bearish when high is below the lowest MA.

    • If OFF: bar is bearish only if close is below all MAs.

  • Gray: Anything else (neutral memory mode to avoid noise).

This helps highlight moments of strong structure confirmation or breakdown.


⚙️ Custom Inputs

Moving Average Settings

  • Daily Length & Type (EMA/SMA)

  • Weekly Length & Type (EMA/SMA)

Bar Color Settings

  • Toggle bar color on/off

  • Toggle High < MA Low condition for bearish bars

Visual Settings

  • Adjustable line size

  • Custom trend colors and cloud opacity


🧠 Use Case

This indicator is ideal for swing traders and trend followers who want to:

  • Visually track short- or mid-term trend alignment

  • Avoid false signals by requiring full MA agreement

  • Identify high-probability breakout/breakdown zones

  • Reduce screen clutter by using a single structure band setup


Let me know if you want a simplified version for in-app tooltips or a visual chart example added to this!

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