OPEN-SOURCE SCRIPT

TrendGrade Buy Sell Signals

4 649
TrendGrade — Buy & Sell Signals (MTF Confirmed)
What it does
TrendGrade is a signal-grading system built on top of a Supertrend trigger. Instead of treating every Supertrend flip as an equal trade opportunity, it classifies each buy signal by quality using trend-strength analysis (XTL), higher-timeframe confirmation, and a transparent rule-based priority score. It is designed primarily for intraday swing timeframes (e.g., 2H) with 4H confirmation and an optional Daily veto.
How it works
1. Base trigger — Supertrend
The entry engine is the classic ATR-based Supertrend (default ATR 14, multiplier 2.0). A buy setup appears when the trend flips from bearish to bullish; a sell setup appears on the opposite flip.
2. Signal grading — XTL (eXpert Trend Locator)
XTL is based on Tom Joseph's statistical concept for separating directional moves from random market noise, implemented here via a Double-CCI-style calculation with a selectable moving-average engine (28 MA types, default VWMA-26 on HLC3) and a fixed threshold (default 37).
XTL above the threshold = BULL environment
XTL below the negative threshold = BEAR environment
Otherwise = NEUTRAL
Optional bar coloring paints candles by XTL state (bull / neutral / bear).
3. Multi-timeframe confirmation (anti-repaint)
4H confirmation: close above the 4H EMA-21, EMA slope flat or rising, plus an optional RSI(14) momentum check (RSI > 50 or rising).
Daily veto (optional): if the Daily close is below its EMA-21 AND the EMA slope is down (strong downtrend), all buy signals are blocked. Blocked signals are still shown on the chart as an orange × for transparency.
By default only closed higher-timeframe bars are used (`lookahead_off` + confirmed-bar indexing), so MTF confirmation does not repaint. This can be disabled for faster (but mutable) live-bar confirmation.
4. Signal classes
STRONG BUY — Supertrend flip + XTL BULL + 4H confirmation (lime label)
BUY — Supertrend flip without full confirmation (green label)
SELL — Supertrend flip down, only fired if a valid buy occurred first (simple position tracking, so sells are not orphaned)
Filtered/blocked raw signals are plotted as gray circles or orange × marks so you can always see what was suppressed and why.
5. Optional EMA-89 filter
Buy signals can additionally be required to close above EMA-89 (with an adjustable % tolerance). Off by default.
6. Priority score (0–100)
Each signal gets a transparent, rule-based score from RSI, MFI, relative volume, EMA ribbon alignment (5/8/13/34/55/89/200), Parabolic SAR position and CMF. This is a simple checklist score — it is NOT a statistical probability.
7. Alerts & webhook automation
Standard `alertcondition()` alerts for Strong Buy / Buy / Sell / trend change.
A structured JSON alert (via `alert()`) designed for webhook automation (e.g., Make.com / n8n): symbol, timeframe, price, ATR-based Target-1/Target-2, Supertrend stop, R:R ratio, priority score, XTL state, 4H/Daily MTF status, RSI/MFI/CMF, relative volume, EMA support/resistance map, and flags such as "volume spike" (relative volume ≥ 3×) and "strong money inflow" (CMF ≥ 0.15).
Optional early intrabar alert: fires before bar close once a configurable percentage of the bar has elapsed (default 60%), clearly tagged `early_mode=1`. Early alerts can be invalidated before the bar closes (repaint risk is explicitly flagged); the confirmed bar-close alert is always sent separately.
Settings overview
Supertrend: ATR period, multiplier, source, ATR method
XTL: length, MA type (28 options), source, threshold, traditional/modern CCI formula
MTF: confirmation timeframe (default 4H), veto timeframe (default 1D), EMA length, slope lookback, momentum check, closed-bar mode
EMA-89 filter, EMA ribbon display, Parabolic SAR display
Targets: ATR multiples for Target-1 / Target-2 (used in alert messages)
Oscillators/volume lengths and attention thresholds (used in alert messages)
Early-signal toggle and minimum bar progress
Repainting notes
Confirmed signals are evaluated on bar close.
MTF data uses `lookahead_off` and, by default, the last closed higher-timeframe bar, so confirmation status does not change retroactively (at the cost of up to one higher-timeframe bar of delay).
The optional early intrabar alert is intentionally repainting by nature and is clearly labeled as a pre-warning; the final confirmation is always sent at bar close.
Credits
XTL (eXpert Trend Locator) concept by Tom Joseph — a statistical market evaluation distinguishing directional trends from random noise.
XTL implementation adapted from the public "Double CCI" approach on TradingView.
Supertrend logic based on the widely used ATR-based community implementation.
Moving-average library includes public implementations credited in-code to everget (JMA), DonovanWall (FRAMA, COVWMA), allanster (VAMA), RedKTrader (RSS_WMA), Duyck (ADX MA) and glaz (RSI EMA).
Disclaimer
This indicator is for educational and informational purposes only. It is not financial advice and past signal behavior does not guarantee future results. Always do your own research and manage risk appropriately.

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.