OPEN-SOURCE SCRIPT

EMA Distance Zone Move Matrix

318
This indicator answers one of the most practical questions in trading: "When price is X% away from the EMA, how likely is it to move at least Y% from that point?"
It builds a live probability matrix from historical data — no repainting, no predictions — just raw statistics from how price has actually behaved.

How It Works
The indicator measures the percentage distance between price and a selected EMA at every bar. It then groups historical bars into user-defined zones (e.g. "price is 3–5% above EMA") and tracks how often price made a significant move after entering each zone.
Example read:
If the 3 to 5% zone shows ▲≥5%: 62.3% — that means 62.3% of the time, after price entered that zone, it subsequently rallied at least 5% from the entry price within the tracking window.

Settings
EMA

EMA Length — period of the EMA (default: 20)
EMA Timeframe — use the chart timeframe or any higher timeframe
Lookback Bars — how many historical bars to analyse (default: 1000)
Bars to Track — how many bars after zone entry to watch for the move (default: 50)

From Zones (Rows) — 8 zones, each with:

Enable/disable toggle
Lo% and Hi% — the EMA distance band (supports negative values for below-EMA zones)
Label — custom name shown in the table row

Move Thresholds (Columns) — 10 thresholds, each with:

Enable/disable toggle
Direction — ▲ Up (price rises), ▼ Down (price falls), ↕ Either (either direction)
≥ % — minimum move size to count as a hit

Display

Show % or raw count
Heatmap color mode
Table position and text size


The Matrix Table
Rows = FROM zones (where price was when it entered)
Columns = move thresholds (how far it moved after)
Last column = total number of visits to that zone
Each cell shows the probability (%) or count of times price achieved that move after entering that zone.
Color coding (heatmap mode):

Red — highest probability (≥75% of max)
Orange — high (50–75%)
Yellow — moderate (25–50%)
Teal — low (below 25%)
Gray — zero / no data

Column headers are color-coded by direction:

Teal = Up move ▲
Red = Down move ▼
Purple = Either direction ↕

The footer row shows the currently active zone and the indicator settings summary.

Chart Background
The chart background is lightly shaded to show which zone price is currently in — making it easy to spot your current EMA distance zone at a glance without looking at the table.

Use Cases

Find which EMA distance zones historically lead to strong reversals or continuations
Identify asymmetric zones where up-move probability is much higher than down
Compare behavior at oversold vs overbought EMA distances
Build mean-reversion or momentum setups backed by historical statistics
Use with any EMA (20, 50, 100, 200) on any timeframe


Notes

overlay=true — draws directly on the main chart, no separate pane needed
A move is counted once per zone visit per threshold (first time it's hit within the tracking window)
Works on any instrument: stocks, crypto, forex, futures, indices
The matrix updates live on every bar — no need to refresh
Use a lookback of at least 500 bars for statistically meaningful results
Ensure the chart timeframe has enough history to cover the lookback window


Settings Quick Start (recommended defaults):
Zones: -10 to -5 · -5 to -3 · -3 to 0 · 0 to 3 · 3 to 5 · 5 to 10
Moves: ▲≥1% · ▲≥2% · ▲≥5% · ▲≥10% · ▼≥1% · ▼≥2% · ▼≥5% · ▼≥10%
Lookback: 1000 · Track window: 50 bars

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.