TV Script - Trading Dashboard Documentation

Comprehensive documentation for TradingView Pine Script indicators and trading strategies

View the Project on GitHub tekram/tv-script

21 EMA Structure Indicator

Overview

The 21 EMA Structure is a powerful moving average indicator that provides a comprehensive view of price action relative to moving averages. This feature calculates separate moving averages for High, Close, and Low prices, creating a visual “structure” that helps identify trend direction and key support/resistance levels.

21 EMA Structure Indicator

Example of the 21 EMA Structure showing High, Close, and Low moving averages with trend-based color coding

Concept Origin

This indicator is inspired by Alex’s Swing Trading System from PrimeTrading Academy, which emphasizes trading pullbacks to the 21-day moving average structure. The methodology focuses on:

Key Features

Three MA Lines

Visual Cloud

Trend Detection

Timeframe Awareness

Configuration Options

MA Settings

Color Customization

Bar Coloring (Optional)

Visual Settings

Default Settings

Trading Applications

Entry Signals

Risk Management

Position Sizing

Integration with Trading System

PrimeTrading Methodology

This indicator integrates with Alex’s swing trading system principles:

Best Practices

  1. Daily Charts: Use for swing trade entries (5-8 day holds)
  2. Weekly Charts: Use for position trade entries (longer holds)
  3. Structure Confluence: Look for weekly structure alignment on daily charts
  4. Avoid Extended: Don’t buy >1x ATR above the 21dma structure

Technical Details

Calculation Method

// Function to calculate MA
getMaStructure(src, length, maType) =>
    switch maType
        'SMA' => ta.sma(src, length)
        'EMA' => ta.ema(src, length)
        => ta.ema(src, length) // default to EMA

// MA calculations
maStructureHigh = getMaStructure(high, maStructureLength, maStructureType)
maStructureClose = getMaStructure(close, maStructureLength, maStructureType)
maStructureLow = getMaStructure(low, maStructureLength, maStructureType)

Trend Detection Logic

// Trend direction (all 3 MAs must agree)
isRisingMA = maStructureHigh > maStructureHigh[1] and 
             maStructureClose > maStructureClose[1] and 
             maStructureLow > maStructureLow[1]

isFallingMA = maStructureHigh < maStructureHigh[1] and 
              maStructureClose < maStructureClose[1] and 
              maStructureLow < maStructureLow[1]

Credits