Strategy · Pine Script v5 · On the chart

Divergence Scanner

by g-moe· code credited to goodgains

Calculates buy and sell volume pressure alongside the Awesome Oscillator to scan for market divergence opportunities.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code175
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

175 lines of Pine Script v5 from Tradingview/divergence-scanner.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

divergence-scanner.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
strategy("Divergence Scanner", overlay=true, default_qty_value = 100)

// @keywords: divergence-scanner, awesome-oscillator, buy-sell-volume-pressure, bsvp-convergence, volume-pressure, ao-filter, long-entry, short-entry, profit-target, stop-loss, swing-stop, trading-hours, colored-candles, main-signal, ao-trend, bsvp-trend, tick-stop, recent-high-low-stop, strategy-entries, session-filter

//Strategy 
useTradingHours = input.bool(false, title = "Use Trading Hours", tooltip = "This is ignored if the chart timeframe is greater than or equal to the daily timeframe.", group = "Additional Trade Settings", inline = '1')
trading_time = input.session("0930-1600", title = "Trading Time", tooltip = "This uses Eastern Time Zone or U.S. NY Market Hours.", group = "Additional Trade Settings", inline = '2')
trading_hours_cond = not useTradingHours or time("",trading_time, "America/New_York")
long_trades = input.bool(true, title = "Long Trades", tooltip = "Do we want to take long trades?" , group = "Additional Trade Settings", inline = '3')
short_trades = input.bool(true, title = "Short Trades", tooltip = "Do we want to trade both sides of the market?" , group = "Additional Trade Settings", inline = '3')
use_ao_filter = input.bool(true, title = "AO FIlter", tooltip = "Only enter short trades when AO is red and above 0. And only enter long trades when AO is green and below 0. This will help to remove show chop / buying top of range and shorting bottom of range.", inline = '4')
profit_amount = input.int(300, minval = 1, title = "Profit Target Amount", group = "Additional Trade Settings", tooltip = 'In ticks', inline = '5')
stop_type = input.string("Recent Low/High", title = "Stop Type", options = ['Recent Low/High', 'Ticks'], group = "Additional Trade Settings", inline = '6')
stop_amount = input.int(5, minval = 1, title = "Stop Amount",group = "Additional Trade Settings", inline = '6', tooltip = 'If Stop Type is set to recent high/low and the stop amount is 5 we use the highest high or lowest low from the past 5 bars from entry. 
     \n\nIf Stop Type is set to Ticks then the stop amount is in ticks')

//AO
ao = ta.sma(hl2,5) - ta.sma(hl2,34)
ao_trend = ta.change(ao) <= 0 ? -1 : 1

//BSVP
signal = input.int(title="Base for FastMA Periods:", defval=3, group = "BSVP")
long = input.int(title="Buy to Sell Conv/Div Lookback:", defval=27, group = "BSVP")
vmacd = input.bool(true, title="Buy to Sell Convergence/Div OSC:", group = "BSVP")
vinv = input.bool(false, title="Buy to Sell Conv/Div as cummulative:", group = "BSVP")

vol = volume > 0 ? volume : 1
TR = ta.atr(1)

var BP = 0.00
if close < open 
    if close[1] < open 
        BP := math.max(high - close[1], close - low)
    else
        BP := math.max(high - open, close - low)
else if close > open
    if close[1] > open 
        BP := high - low
    else
        BP := math.max(open - close[1], high - low)
else
    if high - close > close - low 
        if close[1]< open 
            BP := math.max( high -  close[1],close - low )
        else
            BP := high - open
    else if high - close < close - low 
        if close[1] > open
            BP := high - low
        else
            BP := math.max(open - close[1],high - low )
    else
        if close[1] > open
            BP := math.max( high - open, close - low )
        else if close[1] < open
            BP := math.max( open - close[1], high - low )
        else 
            BP := high - low

var SP = 0.00
if close < open 
    if close[1] > open 
        SP := math.max(close[1] - open, high - low)
    else
        SP := high - low
else if close > open
    if close[1] > open 
        SP := math.max(close[1] - low, high - close)
    else
        SP := math.max(open - low, high - close)
else
    if high - close > close - low 
        if close[1] > open 
            SP := math.max(close[1] - open, high -low)
        else
            SP := high - low
    else if high - close < close - low 
        if close[1] > open
            SP := math.max(close[1] - low, high - close)
        else
            SP := open - low
    else
        if close[1] > open
            SP := math.max( close[1] - open, high - low)
        else if close[1] < open
            SP := math.max(open - low, high - close)
        else 
            SP := high - low
TP = BP+SP

// RAW Pressure Volume Calculations
BPV = (BP/TP)*vol
SPV = (SP/TP)*vol
TPV = BPV+SPV
BPVavg = ta.ema(ta.ema(BPV,signal),signal)
SPVavg = ta.ema(ta.ema(SPV,signal),signal)
TPVavg = ta.ema(ta.wma(TPV,signal),signal)

// Karthik Marar's Pressure Volume Normalized Version (XeL-MOD.)
VN = vol/ta.ema(vol,long)
BPN = ((BP/ta.ema(BP,long))*VN)*100
SPN = ((SP/ta.ema(SP,long))*VN)*100
TPN = BPN+SPN
nbf = ta.ema(ta.wma(BPN,signal),signal)
nsf = ta.ema(ta.wma(SPN,signal),signal)
tpf = ta.ema(ta.wma(TPN,signal),signal)
ndif = nbf-nsf


// Volume Pressure Convergence Divergence by XeL_Arjona
vpo1 = vinv ? (( math.sum(BPVavg,long)-math.sum(SPVavg,long))/math.sum(TPVavg,long))*100 : ((BPVavg-SPVavg)/TPVavg)*100
vpo2 = vinv ? (( math.sum(nbf,long)-math.sum(nsf,long))/math.sum(tpf,long))*100 : ((nbf-nsf)/tpf)*100
vph = nz((vpo1 - vpo2),0)

// Plot Indicator
bsvp_trend = vpo1 > 0 ? 1 : -1

main_signal = ao_trend == 1 and bsvp_trend == 1 ? 1 : ao_trend == -1 and bsvp_trend == -1 ? -1 : 0
main_signal_color = main_signal == 1 ? color.teal : main_signal == -1  ? color.red : color.gray

//Visual Settings
color_candles = input.bool(true, title = "Color Candles based on AO and BSVP", group = 'Visual Settings')
plotcandle(color_candles ? open : na, color_candles ? high : na, color_candles ? low : na, color_candles ? close : na, color = main_signal_color, wickcolor = main_signal_color, bordercolor = main_signal_color)

ao_long = not use_ao_filter or use_ao_filter and ao < 0
ao_short = not use_ao_filter or use_ao_filter and ao > 0

long_entry = long_trades and ao_long and trading_hours_cond and main_signal == 1 and main_signal[1] != 1 
long_exit = long_trades and trading_hours_cond and main_signal[1] == 1 and main_signal != 1

short_entry = short_trades and ao_short and  trading_hours_cond and main_signal == -1 and main_signal[1] != -1
short_exit = short_trades and trading_hours_cond and main_signal[1] == -1 and main_signal != -1

//stops and profit targets
var short_StopPrice = 0.00
var long_StopPrice = 0.00

var swing_high_for_stop = 0.00
var swing_low_for_stop = 0.00

high_tracker = ta.highest(high, stop_amount)
low_tracker = ta.lowest(low, stop_amount)

new_pos = strategy.position_size

if stop_type == "Recent Low/High"
    if new_pos != new_pos[1] and strategy.position_size != 0 
        swing_high_for_stop := high_tracker
        swing_low_for_stop := low_tracker
    else
        swing_high_for_stop == swing_high_for_stop[1]
        swing_low_for_stop == swing_low_for_stop[1]
        
    short_StopPrice := swing_high_for_stop
    long_StopPrice := swing_low_for_stop

if stop_type == "Ticks"
    short_StopPrice := strategy.position_avg_price + (syminfo.mintick * stop_amount) 
    long_StopPrice := strategy.position_avg_price - (syminfo.mintick * stop_amount) 
    
if (strategy.position_size > 0)
    strategy.exit(id="Buy", profit=profit_amount, stop=long_StopPrice, comment = " ")
     
if (strategy.position_size < 0)
    strategy.exit(id="Sell", profit=profit_amount, stop=short_StopPrice,  comment = " ")


//entries
strategy.entry("Buy", strategy.long,when = long_entry) 
strategy.entry("Sell", strategy.short, when = short_entry)

Overview

Divergence Scanner initiates long and short strategy entries when divergence signals meet conditions, optionally filtered by New York trading session hours and oscillator polarity. Exits are managed using a configurable tick profit target alongside either a recent swing high or low stop loss or a fixed tick offset. The strategy executes and plots directly on the main price chart with optional trend-based candle coloring.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Divergence, Volume, Oscillators & momentum

Markets

Any symbol

Timeframes

M15-H1, M1-M5

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
Use Trading HoursboolfalseuseTradingHours
Trading Timesession0930-1600trading_time
Long Tradesbooltruelong_trades
Short Tradesbooltrueshort_trades
AO FIlterbooltrueuse_ao_filter
Profit Target Amountint300profit_amount
Stop TypestringRecent Low/Highstop_type
Stop Amountint5stop_amount
Base for FastMA Periods:int3signal
Buy to Sell Conv/Div Lookback:int27long
Buy to Sell Convergence/Div OSC:booltruevmacd
Buy to Sell Conv/Div as cummulative:boolfalsevinv
Show all 13 settings
SettingTypeDefaultVariable
Color Candles based on AO and BSVPbooltruecolor_candles
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

4 stars

Divergence Strategy scans multiple technical oscillators to detect regular and hidden divergences against price action. It evaluates customizable indicators including MACD, RSI, Stochastic, CCI, Momentum, OBV, and Money Flow Index to trigger strategy entries o

Strategy v4 DivergenceOscillators & momentum
Updated 4 years ago · None stated GitHub repository of Divergence Strategy

RSI Pattern Strategy

by fuyuanyuan
1 stars

This script combines five distinct RSI pattern setups with volume ratio filters to generate trading signals. It identifies RSI double bottoms, hooks, bullish divergences, oversold bounces, and midline breakouts to form long conditions, alongside overbought dow

Strategy v6 Oscillators & momentumDivergence
Updated 1 year ago · None stated GitHub repository of RSI Pattern Strategy

Chaikin Oscillator - Eterna MCP

by EternaHybridExchange
9 stars

This strategy calculates the Chaikin Oscillator by taking the difference between fast and slow exponential moving averages of the Accumulation/Distribution line. It generates long and short entries when the oscillator crosses the signal threshold with directio

Strategy v5 Oscillators & momentumVolume
Updated 7 months ago · MIT GitHub repository of Chaikin Oscillator - Eterna MCP
106 stars

This strategy enters long on an outside bar when the candle is bullish, the Klinger Volume Oscillator is positive, and price is above a Hull moving average. It enters short on an inside bar when the candle is bearish, the oscillator is negative, and price is b

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of Advanced OutSide Forex strategy
105 stars

This overlay strategy looks for gold scalps from break of structure and change of character. It enters long when a bullish break, a bullish character change, and an optional volume filter align, and short on the opposite set. Optional RSI levels can block trad

Strategy v6 SMC / ICT / price actionOscillators & momentum Repaints

CombinedBinHAndClucV8

by viktors1982
36 stars

This strategy trades on the price chart using multiple indicators. It enters long positions when price dips meet conditions on Bollinger Bands 40 and 20, RSI, MFI, volume and other thresholds. It exits at custom ROI profit levels based on RSI or after timeout

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV8

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers