Closest Candle to EMA (CCE)

The Closest Candle to EMA (CCE) indicator is a visual analytical tool designed to identify the historical price (candle close) that is closest to the current Exponential Moving Average (EMA) over a user-defined period. This allows traders to easily detect how price has interacted with the trend line recently, providing insights into potential mean reversion, support/resistance, and price convergence behavior.
๐ Key Features
โ Highlights the candle with a closing price closest to the current EMA
โ Customizable EMA length for various trading styles and timeframes
โ Helps detect potential zones of trend interaction
โ Supports analysis of price behavior near dynamic support/resistance
โ Lightweight and non-intrusive visual overlay (red = closest price, blue = EMA)
๐ง How It Works
The script calculates the EMA using the user-defined length (default: 20).
It then scans the last N candles (equal to the EMA length) and finds the one whose closing price is closest to the current EMA value.
That close is highlighted in red, while the EMA is shown in blue.
This comparison helps traders understand the proximity of past price action to the current trend level.
๐ก Use Cases
Mean Reversion Strategies โ Spot when price historically reverts to the trend
Dynamic Support/Resistance Identification โ Find levels where price respected or returned to the EMA
Consolidation Zone Analysis โ Identify areas where price hovered around trend lines
Backtesting Trend Sensitivity โ See how price reacted to EMA over time
โ๏ธ Settings
EMA Length โ Set the number of periods used for EMA and comparison window (default: 20)
๐ Example Strategy Setup โ EMA Touch with Reversal Candle
This indicator can be incorporated into a price-action strategy that combines candlestick patterns, EMA proximity, and volume confirmation. Here's a practical use case:
๐ง Note: This setup is designed specifically with the EMA length set to 9.
๐ Bullish Setup โ Hammer + EMA (in uptrend)
The market is in an uptrend, confirmed by EMA(9) sloping upward
A Hammer candlestick forms
The EMA (blue) must touch the lower shadow (wick) of the Hammer
It must not touch the candle body
Candle volume is above average
โ โ This may signal a bullish continuation opportunity
๐ Bearish Setup โ Shooting Star + EMA (in downtrend)
The market is in a downtrend, confirmed by EMA(9) sloping downward
A Shooting Star candlestick forms
The EMA (blue) must touch the upper shadow (wick) of the candle
It must not touch the candle body
Candle volume is above average
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda โ ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda โ ketahui lebih lanjut di sini.