Indicator · Pine Script v4 · On the chart

Candlestick Reversal System

by theonetrade· code credited to LonesomeTheBlue

This indicator identifies and plots four distinct candlestick reversal patterns directly on the price chart: Wick Reversal, Extreme Reversal, Outside Reversal, and Doji Reversal.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code78
Settings16inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

78 lines of Pine Script v4 from assets/indicator/bit-exact/candlestick_reversal_system_H5290fLn.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

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

//@version=4
study("Candlestick Reversal System", overlay = true)
pivotlbar = input(defval = 5, title ="Length to Highest/Lowest")
highleftempty = pivothigh(pivotlbar, 0)
lowleftempty = pivotlow(pivotlbar, 0)
showma = input(defval = false, title = "SMA", inline = "ma")
malen = input(defval = 10, title = "", inline = "ma")
macol = input(defval = color.blue, title = "", inline = "ma")

plot(showma ? sma(close, malen) : na, color = showma ? macol : na, linewidth = 2)

// Wick Reversal System
l01 = input(true, title = "Enable Wick Reversal System")
wick_multiplier = input(title = "Wick Multiplier", defval = 2.5, step = 0.5, maxval = 20)
body_percentage = input(title = "Body Percentage", defval = 0.25, step = 0.1, maxval = 1)

O = open
C = close
H = high
L = low

Wlongsignal = (C > O) and (O - L) >= ((C - O) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
   (C < O) and (C - L) >= ((O - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
   (C == O and C != H) and (H - L) >= ((H - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
   (O == H and C == H) and (H - L) >= sma((H - L), 50)

Wshortsignal = (C < O) and (H - O) >= ((O - C) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or
   (C > O) and (H - C) >= ((C - O) * wick_multiplier) and (C - L) <= ((H -L) * body_percentage) or
   (C == O and C != L) and (H - L) >= ((C - L) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or
   (O == L and C == L) and (H - L) >= sma((H - L), 50)

// Exteme Reversal System
l02 = input(true, title = "Enable Exteme Reversal System")
bodysize = input(title = "Body Size", defval = 0.525, step = 0.05, maxval = 1)
barsback = input(title = "Bars Back", defval = 50, maxval = 50)
bodymultiplier = input(title = "Body Multiplier", defval = 2, step = 0.25, maxval = 5)

mybodysize = abs(C - O)
AverageBody = sma(mybodysize, barsback)
mycandlesize = (H - L)
AverageCandle = sma(mycandlesize, barsback)

Elongsignal = ((O[1] - C[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((O[1] - C[1]) >  AverageBody) and (C > O)
Eshortsignal = ((C[1] - O[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((C[1] - O[1]) >  AverageBody) and (O > C)

// outside Reversal System
l03  = input(true, title = "Enable Outside Reversal System")

BarMultiplier = input(title = "Body Multiplier", defval = 1.25, step = 0.05, maxval = 3.5)
BarsBack = input(title = "Bars Back", defval = 50, maxval = 250)
AverageCandle1 = sma(mycandlesize, BarsBack)

Olongsignal = L < L[1] and C > H[1] and (H - L) >= AverageCandle1 * BarMultiplier
Oshortsignal = H > H[1] and C < L[1] and (H - L) >= AverageCandle1 * BarMultiplier

// Doji Reversal System
l04 = input(true, title = "Enable Doji Reversal System")

percentage = input(title = "Body Percentage", defval = 0.10, step = 0.1, minval = 0.1)

frangehl = H[1] - L[1]
frangeco = abs(C[1] - O[1])
sma10 = sma(close, 10)

Dshortsignal = (frangeco <= frangehl * percentage and C < L[1] and L[1] > sma10 and C < O)  or (C < L[2] and C[1] >= L[2] and frangeco <= frangeco * percentage and C < O and L[2] > sma10)
Dlongsignal = (frangeco <= frangehl * percentage and C > H[1] and H[1] < sma10 and C > O)  or (C > H[2] and C[1] <= H[2] and frangeco <= frangeco * percentage and C > O and H[2] < sma10)

longsignal = lowleftempty and ((l01 and Wlongsignal) or (l02 and Elongsignal) or (l03 and Olongsignal) or (l04 and Dlongsignal))
shortsignal = highleftempty and ((l01 and Wlongsignal) or (l02 and Eshortsignal) or (l03 and Oshortsignal) or (l04 and Dshortsignal))

plotshape(longsignal, color = color.blue, location = location.belowbar, style = shape.triangleup, size = size.small)
plotshape(shortsignal, color = color.red, location = location.abovebar, style = shape.triangledown, size = size.small)

alertcondition(longsignal, title='Long Signal', message='Long Signal')
alertcondition(shortsignal, title='Short Signal', message='Short Signal')

Overview

Each reversal detection system can be individually enabled or customized using body percentage, wick multiplier, and historical candle size parameters. It also includes an optional Simple Moving Average overlay to help evaluate market context alongside the candlestick reversal signals.

Details

Published by

theonetrade on GitHub

Code credit

LonesomeTheBlue, as written in the script's header

Type

Indicator, Pine Script v4

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.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Length to Highest/Lowestint5pivotlbar
SMAboolfalseshowma
malenint10malen
macolcolorcolor.bluemacol
Enable Wick Reversal Systembooltruel01
Wick Multiplierfloat2.5wick_multiplier
Body Percentagefloat0.25body_percentage
Enable Exteme Reversal Systembooltruel02
Body Sizefloat0.525bodysize
Bars Backint50barsback
Body Multiplierint2bodymultiplier
Enable Outside Reversal Systembooltruel03
Show all 16 settings
SettingTypeDefaultVariable
Body Multiplierfloat1.25BarMultiplier
Bars Backint50BarsBack
Enable Doji Reversal Systembooltruel04
Body Percentagefloat0.10percentage
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

947 stars

The Heikin-Ashi Chart Identifier is an indicator that checks if the current chart uses Heikin-Ashi candles. It tracks matched candles where open equals the average of previous open and close, and verifies no gaps between bars. When conditions match, it display

Indicator v4 Candlestick patterns
Updated 5 weeks ago · GPL-3.0 GitHub repository of Heikin-Ashi Chart Identifier
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns
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

[RS]MTF Candle Sticks

by ricardosantos79
261 stars

This indicator overlays up to five higher-timeframe candlestick groups on the price chart. For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the

Indicator v4 Candlestick patternsSupport & resistance Repaints
Updated 5 years ago · None stated GitHub repository of [RS]MTF Candle Sticks
257 stars

This indicator detects a large set of classic candlestick patterns and plots colored labels on the price chart. Trend context uses a 50-period simple moving average, or the 50 and 200 averages stacked together, and can be switched off. Users filter bullish, be

Indicator v4 Candlestick patternsTrend
Updated 2 months ago · None stated GitHub repository of Snag - All Candlestick Patterns

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