Indicator · Pine Script v5 · On the chart

ATR Retracement EMA Signals

by NakliTechie· code credited to PineScript Development Framework

ATR Retracement EMA Signals identifies momentum setups by detecting large candle expansions relative to Average True Range, followed by brief price retracements and moving average crossovers.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code66
Settings4inputs
LicenceMIT
Last update1 year ago19 Sep 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

66 lines of Pine Script v5 from atr_retracement_ema_signals.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

atr_retracement_ema_signals.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PineScript Development Framework

//@version=5
indicator("ATR Retracement EMA Signals", overlay=true)

// Input parameters
atrLength = input.int(100, "ATR Length", minval=1)
atrMultiplier = input.float(2.5, "ATR Multiplier", minval=0.1)
emaLength = input.int(34, "EMA Length", minval=1)
retracementLookback = input.int(5, "Retracement Lookback Period", minval=1)

// Calculations
atr = ta.atr(atrLength)
ema34 = ta.ema(close, emaLength)

// Detect strong moves (2.5x ATR)
moveUp = high - low > atrMultiplier * atr
moveDown = low - high < -atrMultiplier * atr

// Detect retracements after strong moves
// For long setup: price pulls back after an up move
// Check if we had a strong up move within the lookback period
recentMoveUp = false
for i = 1 to retracementLookback
    if moveUp[i]
        recentMoveUp := true

// Retracement condition for long: price is lower than previous bar but higher than 2 bars ago
retracementUp = recentMoveUp and close < close[1] and close > close[2]

// For short setup: price pulls back after a down move
// Check if we had a strong down move within the lookback period
recentMoveDown = false
for i = 1 to retracementLookback
    if moveDown[i]
        recentMoveDown := true

// Retracement condition for short: price is higher than previous bar but lower than 2 bars ago
retracementDown = recentMoveDown and close > close[1] and close < close[2]

// EMA crossover detection
crossoverUp = ta.crossover(close, ema34)
crossoverDown = ta.crossunder(close, ema34)

// Define buy/sell conditions
// Buy signal: 2.5x ATR up move -> retracement -> EMA crossover
longCondition = retracementUp and crossoverUp

// Sell signal: 2.5x ATR down move -> retracement -> EMA crossover
shortCondition = retracementDown and crossoverDown

// Plotting
plot(ema34, "EMA 34", color=color.blue)

// Plot buy/sell signals
plotshape(longCondition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(shortCondition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")

// Plot strong moves
plotchar(moveUp, "Strong Up Move", "▲", location.abovebar, color=color.green, size=size.tiny)
plotchar(moveDown, "Strong Down Move", "▼", location.belowbar, color=color.red, size=size.tiny)

// Add alerts
alertcondition(longCondition, title="Buy Signal", message="ATR Retracement EMA Buy Signal")
alertcondition(shortCondition, title="Sell Signal", message="ATR Retracement EMA Sell Signal")

Overview

When price experiences a strong bar move, retracing within a configurable lookback window, and subsequently crosses the exponential moving average, buy or sell shapes are plotted on the main price chart. Key settings allow adjustment of ATR length, ATR multiplier, EMA period, and retracement lookback.

Details

Published by

NakliTechie on GitHub

Code credit

PineScript Development Framework, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Moving averages, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
ATR Lengthint100atrLength
ATR Multiplierfloat2.5atrMultiplier
EMA Lengthint34emaLength
Retracement Lookback Periodint5retracementLookback
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
219 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of Adaptive MA Slope

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers