Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Divergence for Many Indicators v4 ST

A Pine Script v4 strategy built on RSI (close, 14), MACD (close, 12) and MOM (close, 10). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 45 settings; defaults include Pivot Period 9, Source for Pivot Points Close and Divergence Type Regular.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does Divergence for Many Indicators v4 ST repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
How did Divergence for Many Indicators v4 ST do on BTCUSDT 1D with default settings?
+25.63%
From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Divergence for Many Indicators v4 ST be converted to Pine Script v5?
No
The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L72:C6: 'obv' was renamed to 'ta.obv' in Pine Script v5), so no v5 download is offered; the edits are shown below.
What alerts does Divergence for Many Indicators v4 ST have?
6
Positive Regular Divergence Detected; Negative Regular Divergence Detected; Positive Hidden Divergence Detected; Negative Hidden Divergence Detected; and more.
Does Divergence for Many Indicators v4 ST use a stop loss?
Yes
strategy.exit sets a stop on line 412, 414.

BTCUSDT · 1D · default settings

  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (45)
121111114212222411212440,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$150,239$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep.
Net profit
+25.63%
$25,626.20
Buy and hold
+102.5%
same period
Closed trades
12
6 won · 6 lost
Profitable
50.0%
of closed trades
Profit factor
1.43
gross profit ÷ gross loss
Max drawdown
45.23%
−$45,228.80

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    2 settings have no label

    In the settings dialog cma1col (line 42), cma2col (line 43) show an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames sma → ta.sma, rsi → ta.rsi, macd → ta.macd, mom → ta.mom, cci → ta.cci, stoch → ta.stoch, vwma → ta.vwma, mfi → ta.mfi, pivothigh → ta.pivothigh, pivotlow → ta.pivotlow, round → math.round, sign → math.sign, tostring → str.tostring, max → math.max, min → math.min.

v4 → v5

Differs

The v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L72:C6: 'obv' was renamed to 'ta.obv' in Pine Script v5.

  • Line 5: //@version=4 → //@version=5
  • Line 44: sma → ta.sma
  • Line 45: sma → ta.sma
  • Line 68: rsi → ta.rsi
  • Line 69: macd → ta.macd
  • Line 70: mom → ta.mom
18 more edits
  • Line 71: cci → ta.cci
  • Line 73: sma → ta.sma
  • Line 73: stoch → ta.stoch
  • Line 74: vwma → ta.vwma
  • Line 74: vwma → ta.vwma
  • Line 75: sma → ta.sma
  • Line 75: sma → ta.sma
  • Line 76: mfi → ta.mfi
  • Line 99: pivothigh → ta.pivothigh
  • Line 100: pivotlow → ta.pivotlow
  • Line 219: round → math.round
  • Line 219: sign → math.sign
  • Line 361: tostring → str.tostring
  • Line 363: tostring → str.tostring
  • Line 369: max → math.max
  • Line 381: min → math.min
  • Line 404: input(type = input.float) → input.float()
  • Line 405: input(type = input.float) → input.float()
⋯// © LonesomeTheBlue-//@version=4+//@version=5strategy("Divergence for Many Indicators v4 ST", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400)⋯cma2col = input(defval = color.red, title = "", inline = "ma12")-plot(showmas ? sma(close, 50) : na, color = showmas ? cma1col : na)+plot(showmas ? ta.sma(close, 50) : na, color = showmas ? cma1col : na)-plot(showmas ? sma(close, 200) : na, color = showmas ? cma2col: na)+plot(showmas ? ta.sma(close, 200) : na, color = showmas ? cma2col: na)// set line styles⋯// get indicators-rsi = rsi(close, 14) // RSI+rsi = ta.rsi(close, 14) // RSI-[macd, signal, deltamacd] = macd(close, 12, 26, 9) // MACD+[macd, signal, deltamacd] = ta.macd(close, 12, 26, 9) // MACD-moment = mom(close, 10) // Momentum+moment = ta.mom(close, 10) // Momentum-cci = cci(close, 10) // CCI+cci = ta.cci(close, 10) // CCIObv = obv // OBV-stk = sma(stoch(close, high, low, 14), 3) // Stoch+stk = ta.sma(ta.stoch(close, high, low, 14), 3) // Stoch-maFast = vwma(close, 12), maSlow = vwma(close, 26), vwmacd = maFast - maSlow // volume weighted macd+maFast = ta.vwma(close, 12), maSlow = ta.vwma(close, 26), vwmacd = maFast - maSlow // volume weighted macd-Cmfm = ((close-low) - (high-close)) / (high - low), Cmfv = Cmfm * volume, cmf = sma(Cmfv, 21) / sma(volume,21) // Chaikin money flow+Cmfm = ((close-low) - (high-close)) / (high - low), Cmfv = Cmfm * volume, cmf = ta.sma(Cmfv, 21) / ta.sma(volume,21) // Chaikin money flow-Mfi = mfi(close, 14) // Moneyt Flow Index+Mfi = ta.mfi(close, 14) // Moneyt Flow Index// keep indicators names and colors in arrays⋯// Check if we get new Pivot High Or Pivot Low-float ph = pivothigh((source == "Close" ? close : high), prd, prd)+float ph = ta.pivothigh((source == "Close" ? close : high), prd, prd)-float pl = pivotlow((source == "Close" ? close : low), prd, prd)+float pl = ta.pivotlow((source == "Close" ? close : low), prd, prd)plotshape(ph and showpivot, text = "H",  style = shape.labeldown, color = color.new(color.white, 100), textcolor = color.red, location = location.abovebar, offset = -prd)⋯for x = 0 to array.size(all_divergences) - 1-    total_div := total_div + round(sign(array.get(all_divergences, x)))+    total_div := total_div + math.round(math.sign(array.get(all_divergences, x)))if total_div < showlimit⋯    if shownum and dnumdiv_top > 0-        divergence_text_top := divergence_text_top + tostring(dnumdiv_top)+        divergence_text_top := divergence_text_top + str.tostring(dnumdiv_top)    if shownum and dnumdiv_bottom > 0-        divergence_text_bottom := divergence_text_bottom + tostring(dnumdiv_bottom)+        divergence_text_bottom := divergence_text_bottom + str.tostring(dnumdiv_bottom)    if divergence_text_top != ""⋯                      label.new( x = bar_index, -                                 y = max(high, high[1]), +                                 y = math.max(high, high[1]),                                  text = divergence_text_top,⋯                      label.new( x = bar_index, -                                 y = min(low, low[1]), +                                 y = math.min(low, low[1]),                                  text = divergence_text_bottom,⋯// User Options to Change Inputs (%)-stopPer = input(100, title='Stop Loss %', type=input.float) / 100+stopPer = input.float(100, title='Stop Loss %') / 100-takePer = input(100, title='Take Profit %', type=input.float) / 100+takePer = input.float(100, title='Take Profit %') / 100// Determine where you've entered and in what direction⋯

Clean v5

Not verified

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L72:C6: 'obv' was renamed to 'ta.obv' in Pine Script v5.), so this step could not be checked.

  • Line 7: input() → input.int()
  • Line 8: input() → input.string()
  • Line 9: input() → input.string()
  • Line 10: input() → input.string()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
37 more edits
  • Line 13: input() → input.int()
  • Line 14: input() → input.bool()
  • Line 15: input() → input.bool()
  • Line 16: input() → input.bool()
  • Line 17: input() → input.bool()
  • Line 18: input() → input.bool()
  • Line 19: input() → input.bool()
  • Line 20: input() → input.bool()
  • Line 21: input() → input.bool()
  • Line 22: input() → input.bool()
  • Line 23: input() → input.bool()
  • Line 24: input() → input.bool()
  • Line 25: input() → input.bool()
  • Line 26: input() → input.bool()
  • Line 27: input() → input.bool()
  • Line 28: input() → input.bool()
  • Line 29: input() → input.bool()
  • Line 30: input() → input.source()
  • Line 31: input() → input.color()
  • Line 32: input() → input.color()
  • Line 33: input() → input.color()
  • Line 34: input() → input.color()
  • Line 35: input() → input.color()
  • Line 36: input() → input.color()
  • Line 37: input() → input.string()
  • Line 38: input() → input.string()
  • Line 39: input() → input.int()
  • Line 40: input() → input.int()
  • Line 41: input() → input.bool()
  • Line 42: input() → input.color()
  • Line 43: input() → input.color()
  • Line 54: input() → input.int()
  • Line 55: input() → input.int()
  • Line 56: input() → input.int()
  • Line 59: input() → input.int()
  • Line 60: input() → input.int()
  • Line 61: input() → input.int()
⋯strategy("Divergence for Many Indicators v4 ST", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400)-prd = input(defval = 9, title = "Pivot Period", minval = 1, maxval = 50)+prd = input.int(defval = 9, title = "Pivot Period", minval = 1, maxval = 50)-source = input(defval = "Close", title = "Source for Pivot Points", options = ["Close", "High/Low"])+source = input.string(defval = "Close", title = "Source for Pivot Points", options = ["Close", "High/Low"])-searchdiv = input(defval = "Regular", title = "Divergence Type", options = ["Regular", "Hidden", "Regular/Hidden"])+searchdiv = input.string(defval = "Regular", title = "Divergence Type", options = ["Regular", "Hidden", "Regular/Hidden"])-showindis = input(defval = "Don't Show", title = "Show Indicator Names", options = ["Full", "First Letter", "Don't Show"])+showindis = input.string(defval = "Don't Show", title = "Show Indicator Names", options = ["Full", "First Letter", "Don't Show"])-showlimit = input(1, title="Minimum Number of Divergence", minval = 1, maxval = 11)+showlimit = input.int(1, title="Minimum Number of Divergence", minval = 1, maxval = 11)-maxpp = input(defval = 10, title = "Maximum Pivot Points to Check", minval = 10, maxval = 20)+maxpp = input.int(defval = 10, title = "Maximum Pivot Points to Check", minval = 10, maxval = 20)-maxbars = input(defval = 100, title = "Maximum Bars to Check", minval = 100, maxval = 200)+maxbars = input.int(defval = 100, title = "Maximum Bars to Check", minval = 100, maxval = 200)-shownum = input(defval = true, title = "Show Divergence Number")+shownum = input.bool(defval = true, title = "Show Divergence Number")-showlast = input(defval = false, title = "Show Only Last Divergence")+showlast = input.bool(defval = false, title = "Show Only Last Divergence")-dontconfirm = input(defval = false, title = "Don't Wait for Confirmation")+dontconfirm = input.bool(defval = false, title = "Don't Wait for Confirmation")-showlines = input(defval = false, title = "Show Divergence Lines")+showlines = input.bool(defval = false, title = "Show Divergence Lines")-showpivot = input(defval = false, title = "Show Pivot Points")+showpivot = input.bool(defval = false, title = "Show Pivot Points")-calcmacd = input(defval = true, title = "MACD")+calcmacd = input.bool(defval = true, title = "MACD")-calcmacda = input(defval = true, title = "MACD Histogram")+calcmacda = input.bool(defval = true, title = "MACD Histogram")-calcrsi = input(defval = true, title = "RSI")+calcrsi = input.bool(defval = true, title = "RSI")-calcstoc = input(defval = true, title = "Stochastic")+calcstoc = input.bool(defval = true, title = "Stochastic")-calccci = input(defval = true, title = "CCI")+calccci = input.bool(defval = true, title = "CCI")-calcmom = input(defval = true, title = "Momentum")+calcmom = input.bool(defval = true, title = "Momentum")-calcobv = input(defval = true, title = "OBV")+calcobv = input.bool(defval = true, title = "OBV")-calcvwmacd = input(true, title = "VWmacd")+calcvwmacd = input.bool(true, title = "VWmacd")-calccmf = input(false, title = "Chaikin Money Flow")+calccmf = input.bool(false, title = "Chaikin Money Flow")-calcmfi = input(false, title = "Money Flow Index")+calcmfi = input.bool(false, title = "Money Flow Index")-calcext = input(false, title = "Check External Indicator")+calcext = input.bool(false, title = "Check External Indicator")-externalindi = input(defval = close, title = "External Indicator")+externalindi = input.source(defval = close, title = "External Indicator")-pos_reg_div_col = input(defval = color.yellow, title = "Positive Regular Divergence")+pos_reg_div_col = input.color(defval = color.yellow, title = "Positive Regular Divergence")-neg_reg_div_col = input(defval = color.navy, title = "Negative Regular Divergence")+neg_reg_div_col = input.color(defval = color.navy, title = "Negative Regular Divergence")-pos_hid_div_col = input(defval = color.lime, title = "Positive Hidden Divergence")+pos_hid_div_col = input.color(defval = color.lime, title = "Positive Hidden Divergence")-neg_hid_div_col = input(defval = color.red, title = "Negative Hidden Divergence")+neg_hid_div_col = input.color(defval = color.red, title = "Negative Hidden Divergence")-pos_div_text_col = input(defval = color.black, title = "Positive Divergence Text Color")+pos_div_text_col = input.color(defval = color.black, title = "Positive Divergence Text Color")-neg_div_text_col = input(defval = color.white, title = "Negative Divergence Text Color")+neg_div_text_col = input.color(defval = color.white, title = "Negative Divergence Text Color")-reg_div_l_style_ = input(defval = "Solid", title = "Regular Divergence Line Style", options = ["Solid", "Dashed", "Dotted"])+reg_div_l_style_ = input.string(defval = "Solid", title = "Regular Divergence Line Style", options = ["Solid", "Dashed", "Dotted"])-hid_div_l_style_ = input(defval = "Dashed", title = "Hdden Divergence Line Style", options = ["Solid", "Dashed", "Dotted"])+hid_div_l_style_ = input.string(defval = "Dashed", title = "Hdden Divergence Line Style", options = ["Solid", "Dashed", "Dotted"])-reg_div_l_width = input(defval = 2, title = "Regular Divergence Line Width", minval = 1, maxval = 5)+reg_div_l_width = input.int(defval = 2, title = "Regular Divergence Line Width", minval = 1, maxval = 5)-hid_div_l_width = input(defval = 1, title = "Hidden Divergence Line Width", minval = 1, maxval = 5)+hid_div_l_width = input.int(defval = 1, title = "Hidden Divergence Line Width", minval = 1, maxval = 5)-showmas = input(defval = false, title = "Show MAs 50 & 200", inline = "ma12")+showmas = input.bool(defval = false, title = "Show MAs 50 & 200", inline = "ma12")-cma1col = input(defval = color.lime, title = "", inline = "ma12")+cma1col = input.color(defval = color.lime, title = "", inline = "ma12")-cma2col = input(defval = color.red, title = "", inline = "ma12")+cma2col = input.color(defval = color.red, title = "", inline = "ma12")plot(showmas ? ta.sma(close, 50) : na, color = showmas ? cma1col : na)⋯// Testing Start dates-testStartYear = input(2021, "Backtest Start Year")+testStartYear = input.int(2021, "Backtest Start Year")-testStartMonth = input(1, "Backtest Start Month")+testStartMonth = input.int(1, "Backtest Start Month")-testStartDay = input(1, "Backtest Start Day")+testStartDay = input.int(1, "Backtest Start Day")testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)//Stop date if you want to use a specific range of dates-testStopYear = input(2030, "Backtest Stop Year")+testStopYear = input.int(2030, "Backtest Stop Year")-testStopMonth = input(12, "Backtest Stop Month")+testStopMonth = input.int(12, "Backtest Stop Month")-testStopDay = input(30, "Backtest Stop Day")+testStopDay = input.int(30, "Backtest Stop Day")testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)⋯

Does it run in Pine Script v6?

Not tested

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L72:C6: 'obv' was renamed to 'ta.obv' in Pine Script v5.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © LonesomeTheBlue-//@version=5+//@version=6strategy("Divergence for Many Indicators v4 ST", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Pivot Period9int · min 1 · max 50ph pl len plotshape
Source for Pivot PointsClosestring · options ["Close", "High/Low"]ph pl prsc new_line
Divergence TypeRegularstring · options ["Regular", "Hidden", "Regular/Hidden"]line 193 line 194 line 195 line 196
Show Indicator NamesDon't Showstring · options ["Full", "First Letter", "Don't Show"]divergence_text_top divergence_text_bottom line 82 line 83 line 84 line 85 line 86 line 87 line 88 line 89 line 90 line 91 line 92 line 359
Minimum Number of Divergence1int · min 1 · max 11line 220
Maximum Pivot Points to Check10int · min 10 · max 20line 133 line 166
Maximum Bars to Check100int · min 100 · max 200line 136 line 169
Show Divergence Numbertrueboolline 359 line 360 line 362
Show Only Last Divergencefalseboolline 324 line 327 line 336 line 339 line 365 line 377
Don't Wait for Confirmationfalseboolstartpoint line 130 line 163
Show Divergence Linesfalseboolnew_line
Show Pivot Pointsfalseboolplotshape
MACDtrueboolline 205
MACD Histogramtrueboolline 206
RSItrueboolline 207
Stochastictrueboolline 208
CCItrueboolline 209
Momentumtrueboolline 210
OBVtrueboolline 211
VWmacdtrueboolline 212
Chaikin Money Flowfalseboolline 213
Money Flow Indexfalseboolline 214
Check External Indicatorfalseboolline 215
External Indicatorclosesourceline 215
Positive Regular Divergencecolor.yellowvalueline 94
Negative Regular Divergencecolor.navyvalueline 95
Positive Hidden Divergencecolor.limevalueline 96
Negative Hidden Divergencecolor.redvalueline 97
Positive Divergence Text Colorcolor.blackvalueline 384
Negative Divergence Text Colorcolor.whitevalueline 372
Regular Divergence Line StyleSolidstring · options ["Solid", "Dashed", "Dotted"]reg_div_l_style
Hdden Divergence Line StyleDashedstring · options ["Solid", "Dashed", "Dotted"]hid_div_l_style
Regular Divergence Line Width2int · min 1 · max 5new_line
Hidden Divergence Line Width1int · min 1 · max 5new_line
Show MAs 50 & 200falseboolplot
Cma1col (no label in the script)color.limevalueplot
Cma2col (no label in the script)color.redvalueplot
Backtest Start Year2021inttestPeriodStart
Backtest Start Month1inttestPeriodStart
Backtest Start Day1inttestPeriodStart
Backtest Stop Year2030inttestPeriodStop
Backtest Stop Month12inttestPeriodStop
Backtest Stop Day30inttestPeriodStop
Stop Loss %100floatlongStop shortStop
Take Profit %100floatshortTake longTake

What it calculates

  • RSI (rsi, ta.rsi in v5)close, 14rsi · line 68
  • MACD (macd, ta.macd in v5)close, 12, 26, 9macd · line 69
  • MACD (macd, ta.macd in v5)close, 12, 26, 9signal · line 69
  • MACD (macd, ta.macd in v5)close, 12, 26, 9deltamacd · line 69
  • MOM (mom, ta.mom in v5)close, 10moment · line 70
  • CCI (cci, ta.cci in v5)close, 10cci · line 71
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 14), 3stk · line 73
  • VWMA (vwma, ta.vwma in v5)close, 12maFast · line 74
  • VWMA (vwma, ta.vwma in v5)close, 26maSlow · line 74
  • SMA (sma, ta.sma in v5)Cmfv, 21cmf · line 75
  • MFI (mfi, ta.mfi in v5)close, 14Mfi · line 76
  • Pivothigh (pivothigh, ta.pivothigh in v5)(source == "Close" ? close : high), Pivot Period (9), Pivot Period (9) · chosen by Source for Pivot Pointsph · line 99
  • Pivotlow (pivotlow, ta.pivotlow in v5)(source == "Close" ? close : low), Pivot Period (9), Pivot Period (9) · chosen by Source for Pivot Pointspl · line 100

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

The script has 72 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open buy longlOn399
Open sell shorts1On401
Exit Close Long stop and limitstrategy.position_size > 0On412
Exit Close Short stop and limitstrategy.position_size < 0On414

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Positive Regular Divergence DetectedalertconditionPositive Regular Divergence Detected389
Negative Regular Divergence DetectedalertconditionNegative Regular Divergence Detected390
Positive Hidden Divergence DetectedalertconditionPositive Hidden Divergence Detected391
Negative Hidden Divergence DetectedalertconditionNegative Hidden Divergence Detected392
Positive Divergence DetectedalertconditionPositive Divergence Detected393
Negative Divergence DetectedalertconditionNegative Divergence Detected394

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

3/3trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+25.6%+102.5%1250%1.4345.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−5.9%+5.5%1362%0.8023.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.8%+9.8%1354%0.603.8%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−1.0%+8.4%1464%0.271.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.2%+16.7%1681%2.670.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%1050%0.650.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.9%+148.3%1040%0.171.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%1560%1.490.1%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market560%$20,257.10
Sideways market425%−$18,623.10
Falling market367%$23,992.20

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

45.9%

The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 28.5% to 45.9%; the tick is what actually happened, 31.6%. Order luck alone moves it this much.

0%53%
All 12 trades
SideEntryExitBarsP&L
long15 Apr 2024 65,661.9017 May 2024 65,235.2032−$426.64
short17 May 2024 65,235.2013 Jun 2024 68,264.0027−$3,028.77
long13 Jun 2024 68,264.0018 Oct 2024 67,421.80127−$842.20
short18 Oct 2024 67,421.8011 Jan 2025 94,726.1085−$27,304.30
long11 Jan 2025 94,726.1020 Jan 2025 101,332.009$6,605.47
short20 Jan 2025 101,332.0028 Feb 2025 84,708.6039$16,623.00
long28 Feb 2025 84,708.6013 Jul 2025 117,420.00135$32,711.40
short13 Jul 2025 117,420.0023 Aug 2025 116,936.0041$484.00
long23 Aug 2025 116,936.007 Jan 2026 93,748.00137−$23,188.00
short7 Jan 2026 93,748.003 Feb 2026 78,738.6027$15,009.40
long3 Feb 2026 78,738.6018 Mar 2026 73,909.4043−$4,829.23
short18 Mar 2026 73,909.4027 Jun 2026 60,097.30101$13,812.10

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Divergence for Many Indicators v4 ST this page—v4 strategy+25.6%1245.2%
Kifier's MFI-STOCH Hidden Divergence-Trend Beater by kifierpivothigh pivotlow stoch vwma sma mfiv4 strategy−2.7%213.7%
Backtesting 3commas DCA Bot v2 by rouxamrsi sma vwma cci mom macdv4 strategydoes not run in Zeal Terminal
Divergence for Many [Dimkud - v5] by dimkudrsi sma cci mom mfi macd vwma pivothigh pivotlowv5 strategy−0.0%240.4%
supertrend with multiple filter strategy by mathlabelsma macd mfi cci stoch pivothigh pivotlow rsiv5 strategydoes not run in Zeal Terminal
CCI Level Zone by Naruephatcci sma rsi stochv5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 110 msYes 1,000 bars in 962 msNot measured
PineTSNo v5 and v6 only—Not measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// It was made with the permission of the original author.// Thank you very much to "Lonesome The Blue" for creating the indicator. -CannyTolany// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © LonesomeTheBlue//@version=4strategy("Divergence for Many Indicators v4 ST", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400)prd = input(defval = 9, title = "Pivot Period", minval = 1, maxval = 50)source = input(defval = "Close", title = "Source for Pivot Points", options = ["Close", "High/Low"])searchdiv = input(defval = "Regular", title = "Divergence Type", options = ["Regular", "Hidden", "Regular/Hidden"])showindis = input(defval = "Don't Show", title = "Show Indicator Names", options = ["Full", "First Letter", "Don't Show"])showlimit = input(1, title="Minimum Number of Divergence", minval = 1, maxval = 11)maxpp = input(defval = 10, title = "Maximum Pivot Points to Check", minval = 10, maxval = 20)maxbars = input(defval = 100, title = "Maximum Bars to Check", minval = 100, maxval = 200)shownum = input(defval = true, title = "Show Divergence Number")showlast = input(defval = false, title = "Show Only Last Divergence")dontconfirm = input(defval = false, title = "Don't Wait for Confirmation")showlines = input(defval = false, title = "Show Divergence Lines")showpivot = input(defval = false, title = "Show Pivot Points")calcmacd = input(defval = true, title = "MACD")calcmacda = input(defval = true, title = "MACD Histogram")calcrsi = input(defval = true, title = "RSI")calcstoc = input(defval = true, title = "Stochastic")calccci = input(defval = true, title = "CCI")calcmom = input(defval = true, title = "Momentum")calcobv = input(defval = true, title = "OBV")calcvwmacd = input(true, title = "VWmacd")calccmf = input(false, title = "Chaikin Money Flow")calcmfi = input(false, title = "Money Flow Index")calcext = input(false, title = "Check External Indicator")externalindi = input(defval = close, title = "External Indicator")pos_reg_div_col = input(defval = color.yellow, title = "Positive Regular Divergence")neg_reg_div_col = input(defval = color.navy, title = "Negative Regular Divergence")pos_hid_div_col = input(defval = color.lime, title = "Positive Hidden Divergence")neg_hid_div_col = input(defval = color.red, title = "Negative Hidden Divergence")pos_div_text_col = input(defval = color.black, title = "Positive Divergence Text Color")neg_div_text_col = input(defval = color.white, title = "Negative Divergence Text Color")reg_div_l_style_ = input(defval = "Solid", title = "Regular Divergence Line Style", options = ["Solid", "Dashed", "Dotted"])hid_div_l_style_ = input(defval = "Dashed", title = "Hdden Divergence Line Style", options = ["Solid", "Dashed", "Dotted"])reg_div_l_width = input(defval = 2, title = "Regular Divergence Line Width", minval = 1, maxval = 5)hid_div_l_width = input(defval = 1, title = "Hidden Divergence Line Width", minval = 1, maxval = 5)showmas = input(defval = false, title = "Show MAs 50 & 200", inline = "ma12")cma1col = input(defval = color.lime, title = "", inline = "ma12")cma2col = input(defval = color.red, title = "", inline = "ma12")plot(showmas ? sma(close, 50) : na, color = showmas ? cma1col : na)plot(showmas ? sma(close, 200) : na, color = showmas ? cma2col: na)// set line stylesvar reg_div_l_style = reg_div_l_style_ == "Solid" ? line.style_solid :                        reg_div_l_style_ == "Dashed" ? line.style_dashed :                       line.style_dottedvar hid_div_l_style = hid_div_l_style_ == "Solid" ? line.style_solid :                        hid_div_l_style_ == "Dashed" ? line.style_dashed :                       line.style_dotted// Testing Start datestestStartYear = input(2021, "Backtest Start Year")testStartMonth = input(1, "Backtest Start Month")testStartDay = input(1, "Backtest Start Day")testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)//Stop date if you want to use a specific range of datestestStopYear = input(2030, "Backtest Stop Year")testStopMonth = input(12, "Backtest Stop Month")testStopDay = input(30, "Backtest Stop Day")testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)testPeriod() =>    time >= testPeriodStart and time <= testPeriodStop ? true : false        // get indicatorsrsi = rsi(close, 14) // RSI[macd, signal, deltamacd] = macd(close, 12, 26, 9) // MACDmoment = mom(close, 10) // Momentumcci = cci(close, 10) // CCIObv = obv // OBVstk = sma(stoch(close, high, low, 14), 3) // StochmaFast = vwma(close, 12), maSlow = vwma(close, 26), vwmacd = maFast - maSlow // volume weighted macdCmfm = ((close-low) - (high-close)) / (high - low), Cmfv = Cmfm * volume, cmf = sma(Cmfv, 21) / sma(volume,21) // Chaikin money flowMfi = mfi(close, 14) // Moneyt Flow Index// keep indicators names and colors in arraysvar indicators_name = array.new_string(11)var div_colors = array.new_color(4)if barstate.isfirst    // names    array.set(indicators_name, 0, showindis == "Full" ? "MACD" : "M")    array.set(indicators_name, 1, showindis == "Full" ? "Hist" : "H")    array.set(indicators_name, 2, showindis == "Full" ? "RSI" : "E")    array.set(indicators_name, 3, showindis == "Full" ? "Stoch" : "S")    array.set(indicators_name, 4, showindis == "Full" ? "CCI" : "C")    array.set(indicators_name, 5, showindis == "Full" ? "MOM" : "M")    array.set(indicators_name, 6, showindis == "Full" ? "OBV" : "O")    array.set(indicators_name, 7, showindis == "Full" ? "VWMACD" : "V")    array.set(indicators_name, 8, showindis == "Full" ? "CMF" : "C")    array.set(indicators_name, 9, showindis == "Full" ? "MFI" : "M")    array.set(indicators_name,10, showindis == "Full" ? "Extrn" : "X")    //colors    array.set(div_colors, 0, pos_reg_div_col)    array.set(div_colors, 1, neg_reg_div_col)    array.set(div_colors, 2, pos_hid_div_col)    array.set(div_colors, 3, neg_hid_div_col)// Check if we get new Pivot High Or Pivot Lowfloat ph = pivothigh((source == "Close" ? close : high), prd, prd)float pl = pivotlow((source == "Close" ? close : low), prd, prd)plotshape(ph and showpivot, text = "H",  style = shape.labeldown, color = color.new(color.white, 100), textcolor = color.red, location = location.abovebar, offset = -prd)plotshape(pl and showpivot, text = "L",  style = shape.labelup, color = color.new(color.white, 100), textcolor = color.lime, location = location.belowbar, offset = -prd)// keep values and positions of Pivot Highs/Lows in the arraysvar int maxarraysize = 20var ph_positions = array.new_int(maxarraysize, 0)var pl_positions = array.new_int(maxarraysize, 0)var ph_vals = array.new_float(maxarraysize, 0.)var pl_vals = array.new_float(maxarraysize, 0.)// add PHs to the arrayif ph    array.unshift(ph_positions, bar_index)    array.unshift(ph_vals, ph)    if array.size(ph_positions) > maxarraysize        array.pop(ph_positions)        array.pop(ph_vals)// add PLs to the arrayif pl    array.unshift(pl_positions, bar_index)    array.unshift(pl_vals, pl)    if array.size(pl_positions) > maxarraysize        array.pop(pl_positions)        array.pop(pl_vals)// functions to check Regular Divergences and Hidden Divergences// function to check positive regular or negative hidden divergence// cond == 1 => positive_regular, cond == 2=> negative_hiddenpositive_regular_positive_hidden_divergence(src, cond)=>    divlen = 0    prsc = source == "Close" ? close : low    // if indicators higher than last value and close price is higher than las close     if dontconfirm or src > src[1] or close > close[1]        startpoint = dontconfirm ? 0 : 1 // don't check last candle        // we search last 15 PPs        for x = 0 to maxpp - 1            len = bar_index - array.get(pl_positions, x) + prd            // if we reach non valued array element or arrived 101. or previous bars then we don't search more            if array.get(pl_positions, x) == 0 or len > maxbars                break            if len > 5 and                ((cond == 1 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(pl_vals, x))) or               (cond == 2 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(pl_vals, x))))                slope1 = (src[startpoint] - src[len]) / (len - startpoint)                virtual_line1 = src[startpoint] - slope1                slope2 = (close[startpoint] - close[len]) / (len - startpoint)                virtual_line2 = close[startpoint] - slope2                arrived = true                for y = 1 + startpoint to len - 1                    if src[y] < virtual_line1 or nz(close[y]) < virtual_line2                        arrived := false                        break                    virtual_line1 := virtual_line1 - slope1                    virtual_line2 := virtual_line2 - slope2                                if arrived                    divlen := len                    break    divlen// function to check negative regular or positive hidden divergence// cond == 1 => negative_regular, cond == 2=> positive_hiddennegative_regular_negative_hidden_divergence(src, cond)=>    divlen = 0    prsc = source == "Close" ? close : high    // if indicators higher than last value and close price is higher than las close     if dontconfirm or src < src[1] or close < close[1]        startpoint = dontconfirm ? 0 : 1 // don't check last candle        // we search last 15 PPs        for x = 0 to maxpp - 1            len = bar_index - array.get(ph_positions, x) + prd            // if we reach non valued array element or arrived 101. or previous bars then we don't search more            if array.get(ph_positions, x) == 0 or len > maxbars                break            if len > 5 and                ((cond == 1 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(ph_vals, x))) or                (cond == 2 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(ph_vals, x))))                slope1 = (src[startpoint] - src[len]) / (len - startpoint)                virtual_line1 = src[startpoint] - slope1                slope2 = (close[startpoint] - nz(close[len])) / (len - startpoint)                virtual_line2 = close[startpoint] - slope2                arrived = true                for y = 1 + startpoint to len - 1                    if src[y] > virtual_line1 or nz(close[y]) > virtual_line2                        arrived := false                        break                    virtual_line1 := virtual_line1 - slope1                    virtual_line2 := virtual_line2 - slope2                                if arrived                    divlen := len                    break    divlen// calculate 4 types of divergence if enabled in the options and return divergences in an arraycalculate_divs(cond, indicator)=>    divs = array.new_int(4, 0)    array.set(divs, 0, cond and (searchdiv == "Regular" or searchdiv == "Regular/Hidden") ? positive_regular_positive_hidden_divergence(indicator, 1) : 0)    array.set(divs, 1, cond and (searchdiv == "Regular" or searchdiv == "Regular/Hidden") ? negative_regular_negative_hidden_divergence(indicator, 1) : 0)    array.set(divs, 2, cond and (searchdiv == "Hidden" or searchdiv == "Regular/Hidden")  ? positive_regular_positive_hidden_divergence(indicator, 2) : 0)    array.set(divs, 3, cond and (searchdiv == "Hidden" or searchdiv == "Regular/Hidden")  ? negative_regular_negative_hidden_divergence(indicator, 2) : 0)    divs// array to keep all divergencesvar all_divergences = array.new_int(44) // 11 indicators * 4 divergence = 44 elements// set related array elementsarray_set_divs(div_pointer, index)=>    for x = 0 to 3        array.set(all_divergences, index * 4 + x, array.get(div_pointer, x))// set divergences array array_set_divs(calculate_divs(calcmacd, macd), 0)array_set_divs(calculate_divs(calcmacda, deltamacd), 1)array_set_divs(calculate_divs(calcrsi, rsi), 2)array_set_divs(calculate_divs(calcstoc, stk), 3)array_set_divs(calculate_divs(calccci, cci), 4)array_set_divs(calculate_divs(calcmom, moment), 5)array_set_divs(calculate_divs(calcobv, Obv), 6)array_set_divs(calculate_divs(calcvwmacd, vwmacd), 7)array_set_divs(calculate_divs(calccmf, cmf), 8)array_set_divs(calculate_divs(calcmfi, Mfi), 9)array_set_divs(calculate_divs(calcext, externalindi), 10)// check minimum number of divergence, if less than showlimit then delete all divergencetotal_div = 0for x = 0 to array.size(all_divergences) - 1    total_div := total_div + round(sign(array.get(all_divergences, x)))if total_div < showlimit    array.fill(all_divergences, 0)// keep line in an arrayvar pos_div_lines = array.new_line(0)var neg_div_lines = array.new_line(0)var pos_div_labels = array.new_label(0)var neg_div_labels = array.new_label(0) // remove old lines and labels if showlast option is enableddelete_old_pos_div_lines()=>    if array.size(pos_div_lines) > 0            for j = 0 to array.size(pos_div_lines) - 1             line.delete(array.get(pos_div_lines, j))        array.clear(pos_div_lines)delete_old_neg_div_lines()=>    if array.size(neg_div_lines) > 0            for j = 0 to array.size(neg_div_lines) - 1             line.delete(array.get(neg_div_lines, j))        array.clear(neg_div_lines)delete_old_pos_div_labels()=>    if array.size(pos_div_labels) > 0         for j = 0 to array.size(pos_div_labels) - 1             label.delete(array.get(pos_div_labels, j))        array.clear(pos_div_labels)delete_old_neg_div_labels()=>    if array.size(neg_div_labels) > 0            for j = 0 to array.size(neg_div_labels) - 1             label.delete(array.get(neg_div_labels, j))        array.clear(neg_div_labels)// delete last creted lines and labels until we met new PH/PV delete_last_pos_div_lines_label(n)=>    if n > 0 and array.size(pos_div_lines) >= n            asz = array.size(pos_div_lines)        for j = 1 to n            line.delete(array.get(pos_div_lines, asz - j))            array.pop(pos_div_lines)        if array.size(pos_div_labels) > 0              label.delete(array.get(pos_div_labels, array.size(pos_div_labels) - 1))            array.pop(pos_div_labels)delete_last_neg_div_lines_label(n)=>    if n > 0 and array.size(neg_div_lines) >= n            asz = array.size(neg_div_lines)        for j = 1 to n            line.delete(array.get(neg_div_lines, asz - j))            array.pop(neg_div_lines)        if array.size(neg_div_labels) > 0              label.delete(array.get(neg_div_labels, array.size(neg_div_labels) - 1))            array.pop(neg_div_labels)            // variables for Alertspos_reg_div_detected = falseneg_reg_div_detected = falsepos_hid_div_detected = falseneg_hid_div_detected = false// to remove lines/labels until we met new // PH/PLvar last_pos_div_lines = 0var last_neg_div_lines = 0var remove_last_pos_divs = false var remove_last_neg_divs = falseif pl    remove_last_pos_divs := false    last_pos_div_lines := 0if ph    remove_last_neg_divs := false    last_neg_div_lines := 0// draw divergences lines and labelsdivergence_text_top = ""divergence_text_bottom = ""distances = array.new_int(0)dnumdiv_top = 0dnumdiv_bottom = 0top_label_col = color.whitebottom_label_col = color.whiteold_pos_divs_can_be_removed = trueold_neg_divs_can_be_removed = truestartpoint = dontconfirm ? 0 : 1 // used for don't confirm optionfor x = 0 to 10    div_type = -1    for y = 0 to 3        if array.get(all_divergences, x * 4 + y) > 0 // any divergence?            div_type := y            if (y % 2) == 1                 dnumdiv_top := dnumdiv_top + 1                top_label_col := array.get(div_colors, y)            if (y % 2) == 0                dnumdiv_bottom := dnumdiv_bottom + 1                bottom_label_col := array.get(div_colors, y)            if not array.includes(distances, array.get(all_divergences, x * 4 + y))  // line not exist ?                array.push(distances, array.get(all_divergences, x * 4 + y))                new_line = showlines ? line.new(x1 = bar_index - array.get(all_divergences, x * 4 + y),                           y1 = (source == "Close" ? close[array.get(all_divergences, x * 4 + y)] :                                            (y % 2) == 0 ? low[array.get(all_divergences, x * 4 + y)] :                                                           high[array.get(all_divergences, x * 4 + y)]),                          x2 = bar_index - startpoint,                          y2 = (source == "Close" ? close[startpoint] :                                            (y % 2) == 0 ? low[startpoint] :                                                           high[startpoint]),                          color = array.get(div_colors, y),                          style = y < 2 ? reg_div_l_style : hid_div_l_style,                          width = y < 2 ? reg_div_l_width : hid_div_l_width                          )                          : na                if (y % 2) == 0                    if old_pos_divs_can_be_removed                        old_pos_divs_can_be_removed := false                        if not showlast and remove_last_pos_divs                            delete_last_pos_div_lines_label(last_pos_div_lines)                            last_pos_div_lines := 0                        if showlast                            delete_old_pos_div_lines()                    array.push(pos_div_lines, new_line)                    last_pos_div_lines := last_pos_div_lines + 1                    remove_last_pos_divs := true                                    if (y % 2) == 1                    if old_neg_divs_can_be_removed                        old_neg_divs_can_be_removed := false                        if not showlast and remove_last_neg_divs                            delete_last_neg_div_lines_label(last_neg_div_lines)                            last_neg_div_lines := 0                        if showlast                            delete_old_neg_div_lines()                    array.push(neg_div_lines, new_line)                    last_neg_div_lines := last_neg_div_lines + 1                    remove_last_neg_divs := true                                // set variables for alerts            if y == 0                pos_reg_div_detected := true            if y == 1                neg_reg_div_detected := true            if y == 2                pos_hid_div_detected := true            if y == 3                neg_hid_div_detected := true    // get text for labels    if div_type >= 0        divergence_text_top    := divergence_text_top    + ((div_type % 2) == 1 ? (showindis != "Don't Show" ? array.get(indicators_name, x) + "\n" : "") : "")        divergence_text_bottom := divergence_text_bottom + ((div_type % 2) == 0 ? (showindis != "Don't Show" ? array.get(indicators_name, x) + "\n" : "") : "")// draw labelsif showindis != "Don't Show" or shownum    if shownum and dnumdiv_top > 0        divergence_text_top := divergence_text_top + tostring(dnumdiv_top)    if shownum and dnumdiv_bottom > 0        divergence_text_bottom := divergence_text_bottom + tostring(dnumdiv_bottom)    if divergence_text_top != ""        if showlast            delete_old_neg_div_labels()        array.push(neg_div_labels,                       label.new( x = bar_index,                                  y = max(high, high[1]),                                  text = divergence_text_top,                                 color = top_label_col,                                 textcolor = neg_div_text_col,                                 style = label.style_label_down                                 ))                                     if divergence_text_bottom != ""        if showlast            delete_old_pos_div_labels()        array.push(pos_div_labels,                       label.new( x = bar_index,                                  y = min(low, low[1]),                                  text = divergence_text_bottom,                                 color = bottom_label_col,                                  textcolor = pos_div_text_col,                                 style = label.style_label_up                                 ))                                     alertcondition(pos_reg_div_detected, title='Positive Regular Divergence Detected', message='Positive Regular Divergence Detected')alertcondition(neg_reg_div_detected, title='Negative Regular Divergence Detected', message='Negative Regular Divergence Detected')alertcondition(pos_hid_div_detected, title='Positive Hidden Divergence Detected', message='Positive Hidden Divergence Detected')alertcondition(neg_hid_div_detected, title='Negative Hidden Divergence Detected', message='Negative Hidden Divergence Detected')alertcondition(pos_reg_div_detected or pos_hid_div_detected, title='Positive Divergence Detected', message='Positive Divergence Detected')alertcondition(neg_reg_div_detected or neg_hid_div_detected, title='Negative Divergence Detected', message='Negative Divergence Detected')l = pos_reg_div_detecteds1 = neg_reg_div_detected        if l     strategy.entry("buy", strategy.long)if s1     strategy.entry("sell", strategy.short)// The Fixed Percent Stop Loss Code// User Options to Change Inputs (%)stopPer = input(100, title='Stop Loss %', type=input.float) / 100takePer = input(100, title='Take Profit %', type=input.float) / 100// Determine where you've entered and in what directionlongStop = strategy.position_avg_price * (1 - stopPer)shortStop = strategy.position_avg_price * (1 + stopPer)shortTake = strategy.position_avg_price * (1 - takePer)longTake = strategy.position_avg_price * (1 + takePer)if strategy.position_size > 0     strategy.exit(id="Close Long", stop=longStop, limit=longTake)if strategy.position_size < 0     strategy.exit(id="Close Short", stop=shortStop, limit=shortTake)