OPEN-SOURCE SCRIPT
Atualizado

MA Cross + Trend Stats (Probabilistic)

68
Short description (one-liner)

A MA-regime framework with historical regime stats + forward performance + optional trend/noise filters for trending context.
________________________________________
Full description (TradingView-ready)

Overview

This indicator turns a classic Moving Average Cross into a regime-based trend dashboard. Instead of treating a cross as a standalone “buy/sell” event, it measures what historically happened after similar regime shifts on the current symbol and timeframe, and displays the results in a compact table.

It supports:

• EMA or SMA
• Custom fast/slow lengths (including .5 lengths via floor/ceil averaging)
• Optional trend quality filters for trending decisions:
o Slope filter (Slow MA slope)
o Market noise filter using Efficiency Ratio (ER) in real time
________________________________________
What the table shows (how to read it)

The table has two rows: Bull (Fast > Slow) and Bear (Slow > Fast). Metrics are computed on completed regimes (historical segments that already ended).

N
Number of completed regimes measured. More samples generally means more stable estimates.

μ Δ% / Med Δ%
Average and median regime return from regime start to regime end. Median helps reduce the impact of outliers.

⏱ Bars
Average regime duration (in bars). Useful to calibrate realistic holding expectations for trending.

⬆ MFE% / ⬇ MAE%
• MFE (Maximum Favorable Excursion): max move in favor during the regime
• MAE (Maximum Adverse Excursion): max move against during the regime

These are context metrics for typical run-up and typical heat.

ER μ | Hit

Trend-quality proxy:

• ER μ: average Efficiency Ratio during regimes (0–1, higher = more directional / less noisy)
• Hit: % of regimes with ER above the historical threshold you set

Forward performance (+H μ|Hit)

For two user-defined horizons (e.g., +10 / +20 bars):

• μ: average forward return after the cross
• Hit: probability (%) that the forward return was positive

This is designed to provide probabilistic context, not certainty.
________________________________________
“Trending” decision filters (optional)

These filters apply to signals/alerts/markers, not to the raw regime statistics:

1. Slope filter (Slow MA):

Only allow Bull signals if the Slow MA slope is positive (and Bear signals if negative).

2. Market noise filter (ER realtime):

Only allow signals when current ER exceeds your chosen threshold (helps avoid choppy conditions).
________________________________________
Suggested usage (educational)

• Treat Bull/Bear as a regime label (state), not a prediction.
• Use Forward Hit% as an estimate of historical frequency, not a guarantee.
• If ER realtime is below threshold, consider it a noisier environment (higher whipsaw risk).
• Combine with your own risk rules and confirmation (structure, volatility, volume, HTF context, etc.).
________________________________________
Notes
• Results depend on symbol, timeframe, and loaded history.
• Statistics are historical summaries and can change as more data becomes available.
• This tool is intended for research and decision support, not as standalone trade advice.
________________________________________

Disclaimer
This script is for educational and informational purposes only and does not constitute financial, investment, or trading advice. Trading involves risk. You are responsible for your own decisions and risk management.
Notas de Lançamento
Update Notes (v1.x)

What’s new

• Table visual upgrade (🟢/🔴 badges): Added optional “traffic-light” cues to make the stats table easier to scan at a glance. Positive/negative values can be highlighted with configurable colors.
• ER column made clearer: The ER μ | Hit cell now shows:
o ER μ (average Efficiency Ratio for completed regimes)
o Hit = % of regimes where ER exceeded your historical ER threshold (trend-quality proxy)
o Optional 🟢/🔴 classification based on whether ER μ ≥ threshold
• Cleaner string handling: Reworked table text building to avoid Pine parser issues and improve stability across updates.

How to read the table (quick guide)

• N: Number of completed regimes used for the stats.
• μ Δ% / Med Δ%: Average vs. “typical” regime move.
• Bars: Average regime duration (in bars).
• MFE% / MAE%: Max favorable move vs. max adverse move measured from the regime entry.
• +H μ|Hit: Forward return stats after a cross at horizons fwd1 and fwd2 (mean return and hit rate).

Notes / Disclaimer

• This indicator provides historical descriptive statistics, not predictions or financial advice.
• Results depend on the symbol, timeframe, MA type/lengths, and sample size. Always validate with your own testing and risk management.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.