OPEN-SOURCE SCRIPT
Telah dikemas kini

EMA Percentile Rank [SS]

645
Hello!
Excited to release my EMA percentile Rank indicator!

What this indicator does


  • Plots an EMA and colors it by short-term trend.
  • When price crosses the EMA (up or down) and remains on that side for three subsequent bars, the cross is “confirmed.”
  • At the moment of the most recent cross, it anchors a reference price to the crossover point to ensure static price targets.
  • It measures the historical distance between price and the EMA over a lookback window, separately for bars above and below the EMA.
  • It computes percentile distances (25%, 50%, 85%, 95%, 99%) and draws target bands above/below the anchor.


Essentially what this indicator does, is it converts the raw “distance from EMA” behavior into probabilistic bands and historical hit rates you can use for targets, stop placement, or mean-reversion/continuation decisions.


Indicator Inputs

EMA length: Default is 21 but you can use any EMA you prefer.
Lookback: Default window is 500, this is length that the percentiles are calculated. You can increase or decrease it according to your preference and performance.
Show Accumulation Table: This allows you to see the table that shows the hits/price accumulation of each of the percentile ranges. UCL means upper confidence and LCL means lower confidence (so upper and lower targets).

About Percentiles
A percentile is a way of expressing the position of a value within a dataset relative to all the other values.
It tells you what percentage of the data points fall at or below that value.

For example:

  1. The 25th percentile means 25% of the values are less than or equal to it.
  2. The 50th percentile (also called the median) means half the values are below it and half are above.
  3. The 99th percentile means only 1% of the values are higher.


Percentiles are useful because they turn raw measurements into context — showing how “extreme” or “typical” a value is compared to historical behavior.

In the EMA Percentile Rank indicator, this concept is applied to the distance between price and the EMA. By calculating percentile distances, the script can mark levels that have historically been reached often (low percentiles) or rarely (high percentiles), helping traders gauge whether current price action is stretched or within normal bounds.

Use Cases

The EMA Percentile Rank indicator is best suited for traders who want to quantify how far price has historically moved away from its EMA and use that context to guide decision-making.

One strong use case is target setting after trend shifts: when a confirmed crossover occurs, the percentile bands (25%, 50%, 85%, 95%, 99%) provide statistically grounded levels for scaling out profits or placing stops, based on how often price has historically reached those distances. This makes it valuable for traders who prefer data-driven risk/reward planning instead of arbitrary point targets. Another use case is identifying stretched conditions — if price rapidly tags the 95% or 99% band after a cross, that’s an unusually large move relative to history, which could signal exhaustion and prompt mean-reversion trades or protective actions.

Conversely, if the accumulation table shows price frequently resides in upper bands after bullish crosses, traders may anticipate continuation and hold positions longer. The indicator is also effective as a trend filter when combined with its EMA color-coding: only taking trades in the trend’s direction and using the bands as dynamic profit zones.

Additionally, it can support multi-timeframe confluence (if you align your chart to the timeframes of interest), where higher-timeframe trend direction aligns with lower-timeframe percentile behavior for higher-probability setups. Swing traders can use it to frame pullbacks — entering near lower percentile bands during an uptrend — while intraday traders might use it to fade extremes or ride breakouts past the median band. Because the anchor price resets only on EMA crosses, the indicator preserves a consistent reference for ongoing trades, which is especially helpful for managing swing positions through noise.

Overall, its strength lies in transforming raw EMA distance data into actionable, probability-weighted levels that adapt to the instrument’s own volatility and tendencies.

Summary

This indicator transforms a simple EMA into a distribution-aware framework: it learns how far price tends to travel relative to the EMA on either side, and turns those excursions into percentile bands and historical hit rates anchored to the most recent cross. That makes it a flexible tool for targets, stops, and regime filtering, and a transparent way to reason about “how stretched is stretched?”—with context from your chosen market and timeframe.

I hope you all enjoy!
And as always, safe trades!

Nota Keluaran
Forgot to add the crossunder marker! Fixed!

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.