Skip to content

Instantly share code, notes, and snippets.

@feliperazeek
Created April 8, 2025 18:40
Show Gist options
  • Save feliperazeek/e09b0752dff4396e123326da33ec75fa to your computer and use it in GitHub Desktop.
Save feliperazeek/e09b0752dff4396e123326da33ec75fa to your computer and use it in GitHub Desktop.
PFR
//@version=5
indicator("NakInvest - PFR Identifier", overlay=true)
// === PFR CONDITIONS ===
reversalBody = math.abs(close - open)
prevBody1 = math.abs(close[1] - open[1])
prevBody2 = math.abs(close[2] - open[2])
bullishCandle = close > open
bearishCandle = close < open
prevTwoRed = close[1] < open[1] and close[2] < open[2] // Previous two candles must be red
prevTwoGreen = close[1] > open[1] and close[2] > open[2] // Previous two candles must be green
bullishPFR = bullishCandle and prevTwoRed and low < ta.lowest(low[1], 2) and high > ta.highest(high[1], 2) and close > close[1] and
reversalBody > prevBody1 and reversalBody > prevBody2
bearishPFR = bearishCandle and prevTwoGreen and high > ta.highest(high[1], 2) and low < ta.lowest(low[1], 2) and close < close[1] and
reversalBody > prevBody1 and reversalBody > prevBody2
// === PLOT SIGNALS ===
plotshape(series=bullishPFR, location=location.belowbar, color=color.green, style=shape.labelup, title="Bullish PFR", text="PFR")
plotshape(series=bearishPFR, location=location.abovebar, color=color.red, style=shape.labeldown, title="Bearish PFR", text="PFR")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment