1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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
430 lines of Pine Script v4 from strategies/v4/divergence_strategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.
Divergence Strategy evaluates customizable indicators including MACD, RSI, Stochastic, CCI, Momentum, OBV, and Money Flow Index to trigger strategy entries on confirmed divergence signals. Input parameters allow users to set pivot evaluation periods, set minimum divergence count thresholds, adjust line display styles, and overlay 50-period and 200-period moving averages directly on the price chart. The script does not include automated stop loss or take profit exit rules.
Multi-indicator divergence detection
Supports regular and hidden divergence types
Customizable pivot periods and divergence count thresholds
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Pivot Period
int
5
prd
Source for Pivot Points
string
Close
source
Divergence Type
string
Regular
searchdiv
Show Indicator Names
string
Full
showindis
Minimum Number of Divergence
int
1
showlimit
Maximum Pivot Points to Check
int
10
maxpp
Maximum Bars to Check
int
100
maxbars
Show Divergence Number
bool
true
shownum
Show Only Last Divergence
bool
false
showlast
Don't Wait for Confirmation
bool
false
dontconfirm
Show Divergence Lines
bool
true
showlines
Show Pivot Points
bool
false
showpivot
Show all 37 settings
Setting
Type
Default
Variable
MACD
bool
true
calcmacd
MACD Histogram
bool
true
calcmacda
RSI
bool
true
calcrsi
Stochastic
bool
true
calcstoc
CCI
bool
false
calccci
Momentum
bool
false
calcmom
OBV
bool
false
calcobv
VWmacd
bool
false
calcvwmacd
Chaikin Money Flow
bool
false
calccmf
Money Flow Index
bool
false
calcmfi
Check External Indicator
bool
false
calcext
External Indicator
source
close
externalindi
Positive Regular Divergence
color
color.yellow
pos_reg_div_col
Negative Regular Divergence
color
color.navy
neg_reg_div_col
Positive Hidden Divergence
color
color.lime
pos_hid_div_col
Negative Hidden Divergence
color
color.red
neg_hid_div_col
Positive Divergence Text Color
color
color.black
pos_div_text_col
Negative Divergence Text Color
color
color.white
neg_div_text_col
Regular Divergence Line Style
string
Solid
reg_div_l_style_
Hdden Divergence Line Style
string
Dashed
hid_div_l_style_
Regular Divergence Line Width
int
2
reg_div_l_width
Hidden Divergence Line Width
int
1
hid_div_l_width
Show MAs 50 & 200
bool
false
showmas
cma1col
color
color.lime
cma1col
cma2col
color
color.red
cma2col
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.
Calculates buy and sell volume pressure alongside the Awesome Oscillator to scan for market divergence opportunities. It initiates long and short strategy entries when divergence signals meet conditions, optionally filtered by New York trading session hours an
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
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
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
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
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