Skip to content
GetProfitable
Search
Trend

EMA Pullback Marker

Marks the bars that trade down into a rising exponential moving average and close back above it, and separately the bars that touch it and close below instead.

indicator
//@version=6
indicator("EMA Pullback Marker", "Pullback", overlay = true)

length = input.int(21, "EMA length", minval = 1, group = "Settings")
slopeLen = input.int(5, "Rising over bars", minval = 1, group = "Settings")
bull = input.color(#26A69A, "Held", group = "Style")
bear = input.color(#EF5350, "Lost", group = "Style")
neutral = input.color(#787B86, "Not rising", group = "Style")

basis = ta.ema(close, length)
rising = basis > basis[slopeLen]
touched = low <= basis
held = rising and touched and close > basis
lost = rising and touched and close < basis

plot(basis, "EMA", color = rising ? bull : neutral, linewidth = 2)
plotshape(held, "Held the EMA", location = location.belowbar, style = shape.circle, color = bull, size = size.tiny)
plotshape(lost, "Lost the EMA", location = location.abovebar, style = shape.xcross, color = bear, size = size.tiny)
alertcondition(held, "Pullback held", "Price traded into a rising EMA and closed back above it")
alertcondition(lost, "Pullback lost", "Price traded into a rising EMA and closed below it")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.

What it will not do

  • A touch only says something while the average is genuinely rising, which is why the slope filter is part of the test rather than an extra.
  • The marker is decided on the close. Intrabar it can appear and disappear as price moves, so treat it as confirmed only once the bar is finished.
  • In a shallow range the average sits inside the noise and nearly every bar touches it, so the markers stop being selective.

Written from this description

Mark bars whose low touches a rising EMA and whose close is back above it with a dot under the bar, mark the ones that close below the EMA instead, and alert on each.

Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.