Indicator · Pine Script v6 · On the chart

Custom Reversal

by rubbermetal· code credited to claygrace74

An overlay indicator that flags possible reversals using pivot points, candle patterns and confirmation filters.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code96
Settings10inputs
LicenceMPL-2.0
Last update4 months ago10 Jun 2026

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

96 lines of Pine Script v6 from Custom Reversal .pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Custom Reversal .pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © claygrace74

//@version=6
indicator("Custom Reversal", shorttitle="Rev", overlay=true)

// ==================== Settings ====================
var rev_group = "Reversal Detection"
pivotLeft   = input.int(5, "Pivot Left Bars", minval=2, group=rev_group)
pivotRight  = input.int(2, "Pivot Right Bars", minval=1, group=rev_group)
rsiLen      = input.int(14, "RSI Length", minval=1, group=rev_group)
rsiOB       = input.int(70, "RSI Overbought", minval=50, maxval=100, group=rev_group)
rsiOS       = input.int(30, "RSI Oversold", minval=0, maxval=50, group=rev_group)
volMulti    = input.float(1.3, "Volume Confirmation Multiplier", minval=1.0, step=0.1, group=rev_group)

var disp_group = "Display Settings"
i_showSignals  = input.bool(true, "Show Reversal Signals", group=disp_group)
i_showPivots   = input.bool(true, "Show Pivot Points", group=disp_group)
i_useVolConf   = input.bool(true, "Require Volume Confirmation", group=disp_group)
i_useRSIConf   = input.bool(true, "Require RSI Confirmation", group=disp_group)

// ==================================================================================
// Core Calculations
// ==================================================================================
rsi = ta.rsi(close, rsiLen)
avgVol = ta.sma(volume, 20)
highVol = volume > avgVol * volMulti

// Pivot detection
pivHigh = ta.pivothigh(high, pivotLeft, pivotRight)
pivLow  = ta.pivotlow(low, pivotLeft, pivotRight)

// Engulfing patterns (strongest single-signal reversals)
bullEngulf = close > open and close > open[1] and open < close[1] and close[1] < open[1] and (close - open) > math.abs(close[1] - open[1])
bearEngulf = close < open and close < open[1] and open > close[1] and close[1] > open[1] and math.abs(close - open) > (close[1] - open[1])

// Pin bar / hammer / shooting star
bodySize = math.abs(close - open)
upperWick = high - math.max(close, open)
lowerWick = math.min(close, open) - low
totalRange = high - low

bullPin = totalRange > 0 and lowerWick > bodySize * 2 and upperWick < bodySize * 0.5 and totalRange > ta.atr(14) * 0.5
bearPin = totalRange > 0 and upperWick > bodySize * 2 and lowerWick < bodySize * 0.5 and totalRange > ta.atr(14) * 0.5

// Swing failure pattern (price makes new high/low but immediately reverses)
newHigh = high > ta.highest(high, 10)[1]
newLow  = low < ta.lowest(low, 10)[1]
swingFailBull = newLow and close > open and close > (high + low) / 2
swingFailBear = newHigh and close < open and close < (high + low) / 2

// Composite reversal signals with optional filters
volOk  = not i_useVolConf or highVol
rsiOkBull = not i_useRSIConf or rsi < rsiOS or rsi[1] < rsiOS
rsiOkBear = not i_useRSIConf or rsi > rsiOB or rsi[1] > rsiOB

bullRev = volOk and rsiOkBull and (bullEngulf or bullPin or swingFailBull)
bearRev = volOk and rsiOkBear and (bearEngulf or bearPin or swingFailBear)

// Pattern name for labels
f_bullName() =>
    bullEngulf ? "Engulf" : bullPin ? "Pin Bar" : swingFailBull ? "Swing Fail" : ""

f_bearName() =>
    bearEngulf ? "Engulf" : bearPin ? "Pin Bar" : swingFailBear ? "Swing Fail" : ""

// ==================================================================================
// Plots
// ==================================================================================

// Pivot point markers
plotshape(i_showPivots and not na(pivHigh), style=shape.circle, location=location.abovebar, color=color.new(color.red, 40), size=size.tiny, offset=-pivotRight, title="Pivot High")
plotshape(i_showPivots and not na(pivLow),  style=shape.circle, location=location.belowbar, color=color.new(color.green, 40), size=size.tiny, offset=-pivotRight, title="Pivot Low")

// Reversal signals
plotshape(i_showSignals and bullRev, style=shape.triangleup,   location=location.belowbar, color=color.green, size=size.small, title="Bull Reversal")
plotshape(i_showSignals and bearRev, style=shape.triangledown, location=location.abovebar, color=color.red,   size=size.small, title="Bear Reversal")

// Pattern name labels
if i_showSignals and bullRev
    label.new(bar_index, low, f_bullName(), style=label.style_none, textcolor=color.green, size=size.small)
if i_showSignals and bearRev
    label.new(bar_index, high, f_bearName(), style=label.style_none, textcolor=color.red, size=size.small)

// Signal background
bgcolor(bullRev ? color.new(color.green, 92) : bearRev ? color.new(color.red, 92) : na, title="Reversal BG")

// ==================================================================================
// Alert Conditions
// ==================================================================================
alertcondition(bullRev,     "Bullish Reversal",        "Bullish reversal pattern detected with confirmations")
alertcondition(bearRev,     "Bearish Reversal",        "Bearish reversal pattern detected with confirmations")
alertcondition(bullEngulf,  "Bullish Engulfing",       "Bullish engulfing candle detected")
alertcondition(bearEngulf,  "Bearish Engulfing",       "Bearish engulfing candle detected")
alertcondition(swingFailBull, "Bullish Swing Failure", "New low followed by bullish close — swing failure")
alertcondition(swingFailBear, "Bearish Swing Failure", "New high followed by bearish close — swing failure")

Overview

Custom Reversal detects swing highs and lows with separate left and right bar counts, bullish and bearish engulfing candles, and pin bars such as hammers and shooting stars. Signals can require an RSI overbought or oversold reading and a volume spike above a multiple of its 20-bar average. Pivots and signals can be shown or hidden. Pivots confirm a few bars late. It gives no exits or position sizing.

Details

Published by

rubbermetal on GitHub

Code credit

claygrace74, as written in the script's header

Draws

On the price chart

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
Pivot Left Barsint5pivotLeft
Pivot Right Barsint2pivotRight
RSI Lengthint14rsiLen
RSI Overboughtint70rsiOB
RSI Oversoldint30rsiOS
Volume Confirmation Multiplierfloat1.3volMulti
Show Reversal Signalsbooltruei_showSignals
Show Pivot Pointsbooltruei_showPivots
Require Volume Confirmationbooltruei_useVolConf
Require RSI Confirmationbooltruei_useRSIConf
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

285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

Exhaustion Reversal

by milocaetano
48 stars

Exhaustion Reversal identifies potential market exhaustion and reversal points on the price chart by detecting strong force bars followed by price give-back patterns. A force bar is defined by an above-average body reaching recent extreme highs or lows. The sc

Indicator v5 Candlestick patternsMean reversion
Updated 2 days ago · MIT GitHub repository of Exhaustion Reversal

Signal Quality Engine [WavesUnchained] is a range-fade indicator that identifies exhaustion at range extremes and signals potential reversals. It applies an ADX and EMA slope regime gate to stand down during strong trends. Using distance, structure, and moment

Indicator v6 Mean reversionSupport & resistance
Updated 2 days ago · MIT GitHub repository of Signal Quality Engine [WavesUnchained]
1 stars

A signal-only indicator that looks for exhaustion after a run of consecutive same-colour candles ending in a doji. A top needs bullish candles with RSI overbought and a new high versus recent bars; a bottom mirrors this. A separate news mode flags unusually la

Indicator v6 Mean reversionCandlestick patterns
Updated 2 weeks ago · None stated GitHub repository of Top Bottom Reversal

RSI Swing Signal

by Web3Degenerate
2 stars

This indicator plots an RSI oscillator in a separate pane and marks long and short setups when RSI is oversold or overbought and a swing low or swing high fractal forms with a reversing candle. It sizes a stop from the recent extreme plus an ATR multiple, then

Indicator v5 Oscillators & momentumCandlestick patterns
Updated 2 years ago · None stated GitHub repository of RSI Swing Signal

More Candlestick patterns scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers