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
- 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
DiffersThe 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 verifiedThe 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Pivot Period | 9 | int · min 1 · max 50 | ph pl len plotshape |
| Source for Pivot Points | Close | string · options ["Close", "High/Low"] | ph pl prsc new_line |
| Divergence Type | Regular | string · options ["Regular", "Hidden", "Regular/Hidden"] | line 193 line 194 line 195 line 196 |
| Show Indicator Names | Don't Show | string · 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 Divergence | 1 | int · min 1 · max 11 | line 220 |
| Maximum Pivot Points to Check | 10 | int · min 10 · max 20 | line 133 line 166 |
| Maximum Bars to Check | 100 | int · min 100 · max 200 | line 136 line 169 |
| Show Divergence Number | true | bool | line 359 line 360 line 362 |
| Show Only Last Divergence | false | bool | line 324 line 327 line 336 line 339 line 365 line 377 |
| Don't Wait for Confirmation | false | bool | startpoint line 130 line 163 |
| Show Divergence Lines | false | bool | new_line |
| Show Pivot Points | false | bool | plotshape |
| MACD | true | bool | line 205 |
| MACD Histogram | true | bool | line 206 |
| RSI | true | bool | line 207 |
| Stochastic | true | bool | line 208 |
| CCI | true | bool | line 209 |
| Momentum | true | bool | line 210 |
| OBV | true | bool | line 211 |
| VWmacd | true | bool | line 212 |
| Chaikin Money Flow | false | bool | line 213 |
| Money Flow Index | false | bool | line 214 |
| Check External Indicator | false | bool | line 215 |
| External Indicator | close | source | line 215 |
| Positive Regular Divergence | color.yellow | value | line 94 |
| Negative Regular Divergence | color.navy | value | line 95 |
| Positive Hidden Divergence | color.lime | value | line 96 |
| Negative Hidden Divergence | color.red | value | line 97 |
| Positive Divergence Text Color | color.black | value | line 384 |
| Negative Divergence Text Color | color.white | value | line 372 |
| Regular Divergence Line Style | Solid | string · options ["Solid", "Dashed", "Dotted"] | reg_div_l_style |
| Hdden Divergence Line Style | Dashed | string · options ["Solid", "Dashed", "Dotted"] | hid_div_l_style |
| Regular Divergence Line Width | 2 | int · min 1 · max 5 | new_line |
| Hidden Divergence Line Width | 1 | int · min 1 · max 5 | new_line |
| Show MAs 50 & 200 | false | bool | plot |
| Cma1col (no label in the script) | color.lime | value | plot |
| Cma2col (no label in the script) | color.red | value | plot |
| Backtest Start Year | 2021 | int | testPeriodStart |
| Backtest Start Month | 1 | int | testPeriodStart |
| Backtest Start Day | 1 | int | testPeriodStart |
| Backtest Stop Year | 2030 | int | testPeriodStop |
| Backtest Stop Month | 12 | int | testPeriodStop |
| Backtest Stop Day | 30 | int | testPeriodStop |
| Stop Loss % | 100 | float | longStop shortStop |
| Take Profit % | 100 | float | shortTake longTake |
What it calculates
- RSI (
rsi,ta.rsiin v5)close, 14rsi · line 68 - MACD (
macd,ta.macdin v5)close, 12, 26, 9macd · line 69 - MACD (
macd,ta.macdin v5)close, 12, 26, 9signal · line 69 - MACD (
macd,ta.macdin v5)close, 12, 26, 9deltamacd · line 69 - MOM (
mom,ta.momin v5)close, 10moment · line 70 - CCI (
cci,ta.cciin v5)close, 10cci · line 71 - SMA / Stoch (
sma,ta.smain v5)stoch(close, high, low, 14), 3stk · line 73 - VWMA (
vwma,ta.vwmain v5)close, 12maFast · line 74 - VWMA (
vwma,ta.vwmain v5)close, 26maSlow · line 74 - SMA (
sma,ta.smain v5)Cmfv, 21cmf · line 75 - MFI (
mfi,ta.mfiin v5)close, 14Mfi · line 76 - Pivothigh (
pivothigh,ta.pivothighin v5)(source == "Close" ? close : high), Pivot Period (9), Pivot Period (9) · chosen by Source for Pivot Pointsph · line 99 - Pivotlow (
pivotlow,ta.pivotlowin 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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open buy long | l | On | 399 |
| Open sell short | s1 | On | 401 |
| Exit Close Long stop and limit | strategy.position_size > 0 | On | 412 |
| Exit Close Short stop and limit | strategy.position_size < 0 | On | 414 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Positive Regular Divergence Detected | alertcondition | Positive Regular Divergence Detected | 389 |
| Negative Regular Divergence Detected | alertcondition | Negative Regular Divergence Detected | 390 |
| Positive Hidden Divergence Detected | alertcondition | Positive Hidden Divergence Detected | 391 |
| Negative Hidden Divergence Detected | alertcondition | Negative Hidden Divergence Detected | 392 |
| Positive Divergence Detected | alertcondition | Positive Divergence Detected | 393 |
| Negative Divergence Detected | alertcondition | Negative Divergence Detected | 394 |
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +25.6% | +102.5% | 12 | 50% | 1.43 | 45.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −5.9% | +5.5% | 13 | 62% | 0.80 | 23.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.8% | +9.8% | 13 | 54% | 0.60 | 3.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1.0% | +8.4% | 14 | 64% | 0.27 | 1.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.2% | +16.7% | 16 | 81% | 2.67 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 10 | 50% | 0.65 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.9% | +148.3% | 10 | 40% | 0.17 | 1.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.1% | +17.1% | 15 | 60% | 1.49 | 0.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 5 | 60% | $20,257.10 |
| Sideways market | 4 | 25% | −$18,623.10 |
| Falling market | 3 | 67% | $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.
All 12 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 15 Apr 2024 65,661.90 | 17 May 2024 65,235.20 | 32 | −$426.64 |
| short | 17 May 2024 65,235.20 | 13 Jun 2024 68,264.00 | 27 | −$3,028.77 |
| long | 13 Jun 2024 68,264.00 | 18 Oct 2024 67,421.80 | 127 | −$842.20 |
| short | 18 Oct 2024 67,421.80 | 11 Jan 2025 94,726.10 | 85 | −$27,304.30 |
| long | 11 Jan 2025 94,726.10 | 20 Jan 2025 101,332.00 | 9 | $6,605.47 |
| short | 20 Jan 2025 101,332.00 | 28 Feb 2025 84,708.60 | 39 | $16,623.00 |
| long | 28 Feb 2025 84,708.60 | 13 Jul 2025 117,420.00 | 135 | $32,711.40 |
| short | 13 Jul 2025 117,420.00 | 23 Aug 2025 116,936.00 | 41 | $484.00 |
| long | 23 Aug 2025 116,936.00 | 7 Jan 2026 93,748.00 | 137 | −$23,188.00 |
| short | 7 Jan 2026 93,748.00 | 3 Feb 2026 78,738.60 | 27 | $15,009.40 |
| long | 3 Feb 2026 78,738.60 | 18 Mar 2026 73,909.40 | 43 | −$4,829.23 |
| short | 18 Mar 2026 73,909.40 | 27 Jun 2026 60,097.30 | 101 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Divergence for Many Indicators v4 ST this page | — | v4 strategy | +25.6% | 12 | 45.2% |
| Kifier's MFI-STOCH Hidden Divergence-Trend Beater by kifier | pivothigh pivotlow stoch vwma sma mfi | v4 strategy | −2.7% | 2 | 13.7% |
| Backtesting 3commas DCA Bot v2 by rouxam | rsi sma vwma cci mom macd | v4 strategy | does not run in Zeal Terminal | ||
| Divergence for Many [Dimkud - v5] by dimkud | rsi sma cci mom mfi macd vwma pivothigh pivotlow | v5 strategy | −0.0% | 24 | 0.4% |
| supertrend with multiple filter strategy by mathlabel | sma macd mfi cci stoch pivothigh pivotlow rsi | v5 strategy | does not run in Zeal Terminal | ||
| CCI Level Zone by Naruephat | cci sma rsi stoch | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 110 ms | Yes 1,000 bars in 962 ms | Not measured |
| PineTS | No 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)