Indicator · Pine Script v5 · On the chart

Reversal Signals [AlgoAlpha]

by theonetrade· code credited to AlgoAlpha

Calculates reversal candidates over a specified lookback period and confirms signals using breakout confirmation windows, optional volume filters against a 20-period volume SMA, and a stepped trend moving average.

View on GitHub

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

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

reversal_signals_algoalpha_htGbg6VL.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoAlpha

//@version=5
indicator("Reversal Signals [AlgoAlpha]", "AlgoAlpha - Reversal Signals", overlay = true)

// Inputs
lookbackPeriod = input.int(defval = 12, title = "Candle Lookback", tooltip = "Number of candles to look back for reversal detection", group = "Reversal Detection Settings")
confirmationPeriod = input.int(defval = 3, title = "Confirm Within", tooltip = "Number of candles within which the reversal must be confirmed", group = "Reversal Detection Settings")
enableVolumeConfirmation = input.bool(defval = true, title = "Use Volume Confirmation", tooltip = "Enable or disable volume confirmation for signals", group = "Reversal Detection Settings")
trendMAPeriod = input.int(defval = 50, title = "Trend MA Period", tooltip = "Period for the moving average used in trend detection", group = "Trend Settings")
trendMAType = input.string(defval = "EMA", title = "MA Type", options = ["SMA", "EMA", "WMA", "VWMA"], tooltip = "Type of moving average to use", group = "Trend Settings")
maStepPeriod = input.int(defval = 33, title = "MA Step Period", tooltip = "Number of bars after which the stepped MA updates", group = "Trend Settings")
bullColor = input.color(#00ffbb, title = "Bullish Color", tooltip = "Color used for bullish signals and trends", group = "Appearance")
bearColor = input.color(#ff1100, title = "Bearish Color", tooltip = "Color used for bearish signals and trends", group = "Appearance")
fill = input.bool(true, "Trend Fill", tooltip = "Enable/disable trend fills", group = "Appearance")
steps = input.bool(true, "MA Steps", tooltip = "Enable/disable MA steps", group = "Appearance")

// Variables
var int bullCandleScore = 0
var int bearCandleScore = 0

bullSignal = false
bearSignal = false

var bool bullReversalCandidate = false
var bool bearReversalCandidate = false

var float bullReversalLow = 0.0
var float bullReversalHigh = 0.0
var float bearReversalLow = 0.0
var float bearReversalHigh = 0.0

var bool bullSignalConfirmed = false
var bool bearSignalConfirmed = false

var int bullCandleCounter = 0
var int bearCandleCounter = 0

volumeIsHigh = volume > ta.sma(volume, 20)

// Calculate the moving average value based on selected type
ma_current = switch trendMAType
    "SMA" => ta.sma(close, trendMAPeriod)
    "EMA" => ta.ema(close, trendMAPeriod)
    "WMA" => ta.wma(close, trendMAPeriod)
    "VWMA" => ta.vwma(close, trendMAPeriod)

// Update the stepped moving average
var float steppedMAValue = na
var int maLastUpdateBar = 0
var int maDirection = 1

if na(steppedMAValue)
    steppedMAValue := ma_current
    maLastUpdateBar := bar_index
else
    if maDirection == 1
        if close < steppedMAValue
            maDirection := -1
            steppedMAValue := ma_current
            maLastUpdateBar := bar_index
        else if bar_index - maLastUpdateBar >= maStepPeriod
            newMAValue = ma_current
            steppedMAValue := math.max(steppedMAValue, newMAValue)
            maLastUpdateBar := bar_index
    else
        if close > steppedMAValue
            maDirection := 1
            steppedMAValue := ma_current
            maLastUpdateBar := bar_index
        else if bar_index - maLastUpdateBar >= maStepPeriod
            newMAValue = ma_current
            steppedMAValue := math.min(steppedMAValue, newMAValue)
            maLastUpdateBar := bar_index

// Reset candle scores
bullCandleScore := 0
bearCandleScore := 0

// Loop through the lookback period
for i = 0 to (lookbackPeriod - 1)
    if close < low[i]
        bullCandleScore += 1
    if close > high[i]
        bearCandleScore += 1

// Bearish reversal detection
if bearCandleScore == (lookbackPeriod - 1)
    bearReversalCandidate := true
    bearReversalLow := low
    bearReversalHigh := high
    bearSignalConfirmed := false
    bearCandleCounter := 0

if bearReversalCandidate
    bearCandleCounter += 1
    if close > bearReversalHigh
        bearReversalCandidate := false

bearCondition = false

if bearReversalCandidate and close < bearReversalLow and not bearSignalConfirmed and bearCandleCounter <= (confirmationPeriod + 1)
    bearSignalConfirmed := true
    bearCondition := true

if bearCondition
    if not enableVolumeConfirmation or volumeIsHigh
        bearSignal := true

// Bullish reversal detection
if bullCandleScore == (lookbackPeriod - 1)
    bullReversalCandidate := true
    bullReversalLow := low
    bullReversalHigh := high
    bullSignalConfirmed := false
    bullCandleCounter := 0

if bullReversalCandidate
    bullCandleCounter += 1
    if close < bullReversalLow
        bullReversalCandidate := false

bullCondition = false

if bullReversalCandidate and close > bullReversalHigh and not bullSignalConfirmed and bullCandleCounter <= (confirmationPeriod + 1)
    bullSignalConfirmed := true
    bullCondition := true

if bullCondition
    if not enableVolumeConfirmation or volumeIsHigh
        bullSignal := true

// Plot signals
plotshape(bullSignal, title = "Buy Signal", style = shape.labelup, location = location.belowbar, color = bullColor, size = size.small, text = "𝓡", textcolor = chart.bg_color)
plotshape(bearSignal, title = "Sell Signal", style = shape.labeldown, location = location.abovebar, color = bearColor, size = size.small, text = "𝓡", textcolor = chart.bg_color)

// Plot moving averages
stma = plot(steppedMAValue, title = "Stepped MA", color = close > steppedMAValue ? bullColor : bearColor, linewidth = 2, display = steps ? display.all : display.none)
cm = plot((open + close) / 2, title = "Center Line", display = display.none)

fill(stma, cm, steppedMAValue, (open + close) / 2, steppedMAValue < close ? color.new(bullColor, 70) : na, steppedMAValue < close ? color.new(bullColor, 100) : na, display = fill ? display.all : display.none)
fill(stma, cm, (open + close) / 2, steppedMAValue, steppedMAValue > close ? color.new(bearColor, 100) : na, steppedMAValue > close ? color.new(bearColor, 70) : na, display = fill ? display.all : display.none)

// Alerts
alertcondition(bullSignal, "Bullish Reversal", "Bullish Reversal Signal Detected")
alertcondition(bearSignal, "Bearish Reversal", "Bearish Reversal Signal Detected")
alertcondition(ta.crossover(close, steppedMAValue), "Bullish Trend", "Bullish Trend Shift")
alertcondition(ta.crossunder(close, steppedMAValue), "Bearish Trend", "Bearish Trend Shift")

Overview

Reversal Signals [AlgoAlpha] offers dynamic moving average choices including SMA, EMA, WMA, and VWMA to define overall market direction. Plots stepped trend lines and trend fills directly on the price chart alongside bullish and bearish visual cues.

Details

Published by

theonetrade on GitHub

Code credit

AlgoAlpha, 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 Lookbackint12lookbackPeriod
Confirm Withinint3confirmationPeriod
Use Volume ConfirmationbooltrueenableVolumeConfirmation
Trend MA Periodint50trendMAPeriod
MA TypestringEMAtrendMAType
MA Step Periodint33maStepPeriod
Bullish Colorcolor#00ffbbbullColor
Bearish Colorcolor#ff1100bearColor
Trend Fillbooltruefill
MA Stepsbooltruesteps
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

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 2 years ago · None stated GitHub repository of Adaptive MA Slope

Signal Strategy 15m

by tripolskypetr
72 stars

This indicator generates trend-following trade signals on the price chart by combining moving average crossovers with multi-factor filters. It triggers entry alerts when fast and slow EMAs cross in the direction of a baseline trend EMA, confirmed by non-extrem

Indicator v5 TrendMoving averages
Updated 4 weeks ago · MIT GitHub repository of Signal Strategy 15m
46 stars

This overlay indicator plots a SuperTrend using a 10-period ATR with a multiplier of 3, drawing up and down stop lines and a faint trend fill on the price chart. It compares a 9-period EMA with an 18-period EMA and a 12/26/9 MACD against its signal, and it req

Indicator v5 TrendOscillators & momentum
Updated 3 years ago · None stated GitHub repository of SuperTrend + MACD + EMA

Bte Acc

by f-cksociety
11 stars

Bte Acc is a chart indicator form of the PineCoders Backtesting and Trading Engine. It seeks an entry trigger from a main or alternate entry method, then checks trade direction, filters, date range, ATR readiness, and remaining capital before filling on the ne

Indicator v5 TrendOscillators & momentum Repaints
Updated 4 years ago · MPL-2.0 GitHub repository of Bte Acc

Signal Forge

by jayadevrana
11 stars

Signal Forge is a multi-filtered trend-following indicator displayed on the main price chart. It calculates an ATR trailing stop line alongside a long-term EMA baseline to identify market direction. Raw signal flips are filtered through ADX chop detection, a v

Indicator v6 TrendVolatility & bands
Updated 4 weeks ago · MPL-2.0 GitHub repository of Signal Forge
9 stars

This indicator plots a volume-weighted moving average as a central trend baseline and surrounds it with ATR-based volatility bands. It colors the trend and optional price bars according to whether price is on the bullish or bearish side of those bands. Users c

Indicator v6 TrendMoving averages
Updated 4 months ago · MIT GitHub repository of Volume Weighted Trend [QuantAlgo]

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