OPEN-SOURCE SCRIPT
Updated

Moving Average Trend Tools

236
I. How M.A.T.T. Adds Value to the TradingView Community:

The "Moving Average Trend Tools" (M.A.T.T.) is a versatile Pine Script v6 indicator that empowers traders with clear trend analysis, reliable trade signals, and real-time insights. Its intuitive design and robust features make it a valuable addition to the TradingView Community Scripts by catering to traders of all levels. Here’s why it stands out:
Clear Trend Visualization: M.A.T.T. plots a moving average (MA) with dynamic coloring—green for rising, red for falling, and gray for flat—based on a user-defined lookback period. This simplifies trend interpretation, helping traders quickly assess market momentum.

Reliable Trade Signals: The script identifies price crossovers above or below the MA, plotting green circles for bullish crosses and red for bearish, confirmed on closed bars to prevent repainting. These signals guide entry and exit points for trend-following or reversal strategies.

Real-Time Extension Detection: M.A.T.T. calculates percentage price deviations from the MA, displaying real-time labels when thresholds (e.g., 6%) are exceeded. This highlights overextended moves, ideal for spotting reversals or pullbacks, with alerts to keep traders informed.

Extensive Customization: Traders can tailor the MA type (SMA, EMA, WMA, HMA), length, colors, line width, and label sizes. This flexibility supports diverse strategies across markets like stocks, forex, and crypto, from scalping to swing trading.

Automated Alerts: Alert conditions for crossovers and extensions integrate seamlessly with TradingView’s system, enabling traders to stay updated without constant chart monitoring.

M.A.T.T. combines trend analysis, signal generation, and overextension detection into a single, user-friendly tool. Its accessibility, reliability, and educational value for Pine Script learners make it a compelling contribution to the community.

II. What M.A.T.T. Does, How It Works, and Its Originality:

What It Does:
M.A.T.T. enhances trend analysis and trade decision-making through three core features:
Dynamic MA Visualization: Plots a customizable MA (SMA, EMA, WMA, or HMA) with trend-based coloring to reflect rising, falling, or flat market conditions.

Price Crossover Signals: Marks bullish (green circles) and bearish (red circles) crossovers, confirmed on closed bars, with alerts for trade opportunities.

Price Extension Labels: Displays real-time percentage deviations of price from the MA, with alerts when user-defined thresholds are breached, signaling potential reversals.

How It Works:
M.A.T.T. leverages Pine Script v6 for precise calculations and user-friendly outputs:
Inputs: Users select MA type, length, lookback period, colors, and thresholds for extensions, plus label styles and sizes for customization.

MA Calculation: A switch function computes the chosen MA (e.g., ta.ema(close, 21) for EMA). Trend direction is determined using ta.rising or ta.falling over the lookback period, coloring the MA accordingly.

Crossover Logic: Bullish crossovers (close > ma and close[1] < ma[1]) and bearish crossovers (close < ma and close[1] > ma[1]) are plotted as circles on confirmed bars (barstate.isconfirmed) to ensure reliability. Alerts trigger only on the first bar of a crossover.

Extension Logic: Percentage deviations are calculated as ((price - ma) / ma) * 100, using the high for above-MA extensions and low for below. Labels appear in real-time when thresholds are exceeded, with alerts on transitions to avoid noise.

Why It’s Original
M.A.T.T. distinguishes itself through a unique blend of features and thoughtful design:

All-in-One Design: It integrates dynamic MA coloring, non-repainting crossover signals, and real-time extension detection, addressing trend identification, trade signals, and overextension warnings in one tool—unlike most MA indicators that focus on a single aspect.

Real-Time Extension Labels: Displaying percentage deviations with customizable thresholds is a rare feature, ideal for volatile markets and not commonly found in standard scripts.

Non-Repainting Signals: Confirmed crossover signals enhance reliability for live trading, setting M.A.T.T. apart from less rigorous indicators.

Optimized Alert Condtions: Alerts trigger only on transitions (e.g., first bar of a crossover or extension), reducing noise and improving usability.

Visual and Functional Flexibility: Support for four MA types, extensive customization, and a clean interface (dynamic colors, tiny circles, clear labels) make it adaptable and user-friendly.

While MA plotting or crossovers exist elsewhere, M.A.T.T.’s seamless integration, real-time extension detection, alert conditions, and focus on reliability and customization create a distinctive, practical tool. Its balance of simplicity and sophistication makes it a unique asset for the TradingView community.

Release Notes
Added switch for MA on user defined time frame (e.g., 10m chart w/ 5D SMA)
Added alert conditions for MA changing colors

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.