Indicator · Pine Script v5 · On the chart

Reversal

by theonetrade· code credited to HasanRifat

Reversal is an indicator that detects potential market reversal signals by comparing the current bar close against historical highs and lows over a specified lookback period.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code81
Settings3inputs
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

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

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

//@version=5
indicator("Reversal", overlay = true)

lookback = input.int(defval = 20, title = "Candle Lookback")
confirmation = input.int(defval = 3, title = "Confirm Within")
nonRepaint = input.bool(defval = false, title = "Non-Repainting Mode")

bullCandle = 0
bearCandle = 0

vup = false
vdn = false

var bullActiveCandle = false
var bullActiveCandleLow = 0.0
var bullActiveCandleHigh = 0.0
var bullSignalActive = false
var bullCandleCount = 0

var bearActiveCandle = false
var bearActiveCandleLow = 0.0
var bearActiveCandleHigh = 0.0
var bearSignalActive = false
var bearCandleCount = 0

for i = 0 to (lookback - 1)
    if close < low[i]
        bullCandle += 1
    if close > high[i]
        bearCandle += 1

if bullCandle == (lookback - 1)
    bullActiveCandle := true
    bullActiveCandleLow := low
    bullActiveCandleHigh := high
    bullSignalActive := false
    bullCandleCount := 0

if bullActiveCandle
    bullCandleCount += 1

if bearCandle == (lookback - 1)
    bearActiveCandle := true
    bearActiveCandleLow := low
    bearActiveCandleHigh := high
    bearSignalActive := false
    bearCandleCount := 0

if bearActiveCandle
    bearCandleCount += 1

if close < bullActiveCandleLow
    bullActiveCandle := false

if close > bearActiveCandleHigh
    bearActiveCandle := false

if nonRepaint
    if bullActiveCandle[1] == true and close[1] > bullActiveCandleHigh[1] and bullSignalActive[1] == false and bullCandleCount[1] <= (confirmation+1)
        bullSignalActive := true
        vup := true
else if bullActiveCandle == true and close > bullActiveCandleHigh and bullSignalActive == false and bullCandleCount <= (confirmation+1)
    bullSignalActive := true
    vup := true

if nonRepaint
    if bearActiveCandle[1] == true and close[1] < bearActiveCandleLow[1] and bearSignalActive[1] == false and bearCandleCount[1] <= (confirmation+1)
        bearSignalActive := true
        vdn := true
else if bearActiveCandle  == true and close < bearActiveCandleLow and bearSignalActive == false and bearCandleCount <= (confirmation+1)
    bearSignalActive := true
    vdn := true

plotshape(vup, title = "V Up", style = shape.triangleup, location = location.belowbar, color = color.lime, size = size.small)
plotshape(vdn, title = "V Dn", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small)

alertcondition(vup, "Bullish Revarsal", "Bullish Revarsal")
alertcondition(vdn, "Bearish Revarsal", "Bearish Revarsal")

Overview

Once a potential reversal candle is established, the script waits for price confirmation above its high or below its low within a set bar window. It plots bullish green triangles below the bar and bearish red triangles above the bar on the price chart. Users can adjust the candle lookback length, confirmation window duration, and toggle a non-repainting evaluation mode.

Details

Published by

theonetrade on GitHub

Code credit

HasanRifat, 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.

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
Candle Lookbackint20lookback
Confirm Withinint3confirmation
Non-Repainting ModeboolfalsenonRepaint
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

257 stars

This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds

Indicator v6 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of Auto Trade Futures ES
56 stars

This indicator calculates dynamic upper and lower trendlines from pivot highs and pivot lows across a specified bar length. Trendline slopes are derived using ATR, standard deviation, or linear regression methods. It plots trendlines and breakout signal labels

Indicator v5 TrendSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Trendlines With Breaks [LUX]

Reversal Breakout System

by TamaraKGreen
47 stars

This indicator detects inside candles inside larger parent candles on the price chart. It plots colored boxes around inside and parent candles, fills them with user-adjustable transparency, draws Fibonacci retracement lines and mother candle range lines, and d

Indicator v6 Candlestick patternsBreakout
Updated 2 months ago · None stated GitHub repository of Reversal Breakout System

The Mathematical Indicator calculates session bias by evaluating previous daily and 4-hour closed candles. It draws timeframe support and resistance levels using candle bodies, highlights clean trading zones, and identifies setup patterns involving consolidati

Indicator v6 TrendSupport & resistance Repaints
Updated 3 days ago · MIT GitHub repository of The Mathematical Indicator · 2-Candle Bias
28 stars

This indicator maps Smart Money Concepts (SMC) market structure directly onto the price chart. It detects internal and swing structure breaks (BOS and CHoCH), tracks bullish and bearish order blocks, identifies fair value gaps (FVG), highlights equal highs and

Indicator v5 SMC / ICT / price actionSupport & resistance Repaints
Updated 5 weeks ago · Custom licence GitHub repository of Smart Money Concepts [LuxAlgo] Test B

The Market Tradability Engine calculates multi-factor tradability, balance, compression, and direction scores to evaluate market regime quality. It classifies market conditions into eight distinct states, including Balance, Compression, Ready, Breakout, Trend,

Indicator v6 TrendVolatility & bands
Updated 4 weeks ago · MIT GitHub repository of Market Tradability Engine [WavesUnchained]

More Trend 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