Zeal Terminal Open Zeal Terminal

Pine Script v5 · Strategy

RSI Overbought Oversold Divergence Strategy w- Buy-Sell Signals

A Pine Script v5 strategy built on EMA (low, 200), SMA (close, 9) and Lowest (low, 200). It has 5 order rules, 2 entries among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.05% commission. 100 settings; defaults include Select Oscillator RSI, Oscillator Source low and Oscillator Length 14.

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 RSI Overbought Oversold Divergence Strategy w- Buy-Sell Signals repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
What alerts does RSI Overbought Oversold Divergence Strategy w- Buy-Sell Signals have?
4
str.tostring(BuyAlertMessage); str.tostring(BuyAlertMessage) + str.tostring(longSlLow) + str.tostring(AfterSLMessage); str.tostring(BuyAlertMessage) + str.tostring(longSlLow) + str.tostring(AfterSLMessage); Bullish divergence.
Does RSI Overbought Oversold Divergence Strategy w- Buy-Sell Signals run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).), so this step could not be checked. The v6 version is shown for reference and is not offered as a download.
Does RSI Overbought Oversold Divergence Strategy w- Buy-Sell Signals use a stop loss?
Yes
strategy.exit sets a stop on line 1190, 1199.
Does RSI Overbought Oversold Divergence Strategy w- Buy-Sell Signals run in Zeal Terminal?
No
Not yet: request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).
Does not run in Zeal Terminal yetRequest.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples). The settings, logic and review below are read from the source, which does not need a run.

Review

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

  • Likely bug

    ta.highest(low, 2) ignores the settings line 193

    Line 193 hard-codes 2 where line 185 uses “Auto Fib Lookback”. Changing those settings moves one band but not this one.

    ta.highest(low, 2)ta.highest(low, fibbullHighLookback)
  • Likely bug

    ta.highest(high, 1) ignores the settings line 1080

    Line 1080 hard-codes 1 where line 185 uses “Auto Fib Lookback”. Changing those settings moves one band but not this one.

    ta.highest(high, 1)ta.highest(high, fibbullHighLookback)
  • Likely bug

    ta.lowest(low, 2) ignores the settings line 188

    Line 188 hard-codes 2 where line 186 uses “Auto Fib Lookback”. Changing those settings moves one band but not this one.

    ta.lowest(low, 2)ta.lowest(low, fibbullHighLookback)
  • Check

    3 settings do nothing

    “deviation”, “deviation”, “Offset” are declared but never read.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    Uses an argument v6 removed

    when = on line 1186, 1187. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
Oscillator settings
Select OscillatorRSI = Relative Strengh Index; OBV = On Balance Volume; RVSI = Relative Volume Strengh Index; MFI Money Flow Index; TRIX RSI = Tripple Exponetial Relative StrengthRSIstring · options ["RSI","OBV","RVSI","MFI","TRIX RSI"]line 247 line 250 line 257 line 261 line 266
Oscillator SourceRSI, RVSI, OBV and TRIX RSI default Source: Close; MFI default Source: hlc3lowsourceEmaUptrend sumSrcVol sumSrcSrcVol osc nv upper lower trix EmaIsBroken
Oscillator LengthRSI/MFI default Period = 14; RVSI = 10; TRIX RSI = 9; OBV has no period.14int · min 1osc RVSI upper lower
Oscillator secondary lengthaffects only RVSI and Trix RSI. For the TRIX RSI this defines the length of the TRIX. default value = 9 and for the RVSI it defines the Volume moving average length, default value = 59int · min 1av trix
Oscillator Moving Average Lengthdefines the length of the of the Oscillator moving average9intoscema
Oscillator Divergence Settings
Min Lookback Range0intline 297 line 323 line 348 line 374 line 400 line 426 line 452 line 478 line 504 line 530 line 556 line 582 line 608 line 634 line 660 line 686 line 712 line 738 line 764 line 790 line 816 line 842 line 868 line 894 line 920 line 946 line 972 line 998 line 1024 line 1050
Max Lookbackreduces the Lookback range that you define with Pivot Lookback Left 1-30 200intline 297 line 323 line 348 line 374 line 400 line 426 line 452 line 478 line 504 line 530 line 556 line 582 line 608 line 634 line 660 line 686 line 712 line 738 line 764 line 790 line 816 line 842 line 868 line 894 line 920 line 946 line 972 line 998 line 1024 line 1050
Only use the first look back periodfalseboolbullCond2 hiddenBullCond2 bullCond3 hiddenBullCond3 bullCond4 hiddenBullCond4 bullCond5 hiddenBullCond5 bullCond6 hiddenBullCond6 bullCond7 hiddenBullCond7 bullCond8 hiddenBullCond8 bullCond9 hiddenBullCond9 bullCond10 hiddenBullCond10 bullCond11 hiddenBullCond11 bullCond12 hiddenBullCond12 bullCond13 hiddenBullCond13 bullCond14 hiddenBullCond14 bullCond15 hiddenBullCond15 bullCond16 hiddenBullCond16 bullCond17 hiddenBullCond17 bullCond18 hiddenBullCond18 bullCond19 hiddenBullCond19 bullCond20 hiddenBullCond20 bullCond21 hiddenBullCond21 bullCond22 hiddenBullCond22 bullCond23 hiddenBullCond23 bullCond24 hiddenBullCond24 bullCond25 hiddenBullCond25 bullCond26 hiddenBullCond26 bullCond27 hiddenBullCond27 bullCond28 hiddenBullCond28 bullCond29 hiddenBullCond29 bullCond30 hiddenBullCond30
Pivot Lookback Left-1Amount of bars to look back to find pivot lows on the Oscillator and Price2intplFound1
Lookback Left-23intplFound2
Pivot Lookback Left-34intplFound3
Lookback Left-45intplFound4
Pivot Lookback Left-56intplFound5
Lookback Left-67intplFound6
Pivot Lookback Left-79intplFound7
Lookback Left-810intplFound8
Pivot Lookback Left-911intplFound9
Lookback Left-1012intplFound10
Pivot Lookback Left-1113intplFound11
Lookback Left-1214intplFound12
Pivot Lookback Left-1315intplFound13
Lookback Left-1416intplFound14
Pivot Lookback Left-1517intplFound15
Lookback Left-1618intplFound16
Pivot Lookback Left-1719intplFound17
Lookback Left-1820intplFound18
Pivot Lookback Left-1922intplFound19
Lookback Left-2025intplFound20
Pivot Lookback Left-2128intplFound21
Lookback Left-2231intplFound22
Pivot Lookback Left-2334intplFound23
Lookback Left-2437intplFound24
Pivot Lookback Left-2539intplFound25
Lookback Left-2642intplFound26
Pivot Lookback Left-2745intplFound27
Lookback Left-2848intplFound28
Pivot Lookback Left-2951intplFound29
Lookback Left-3054intplFound30
Plot BullishPrice makes a lower low while the Oscillator is making a higher lowtrueboolbullCond1 bullCond2 bullCond3 bullCond4 bullCond5 bullCond6 bullCond7 bullCond8 bullCond9 bullCond10 bullCond11 bullCond12 bullCond13 bullCond14 bullCond15 bullCond16 bullCond17 bullCond18 bullCond19 bullCond20 bullCond21 bullCond22 bullCond23 bullCond24 bullCond25 bullCond26 bullCond27 bullCond28 bullCond29 bullCond30 longTrading
Plot Hidden BullishPrice makes a higher low while Oscillator is making a lower lowfalseboolhiddenBullCond1 hiddenBullCond2 hiddenBullCond3 hiddenBullCond4 hiddenBullCond5 hiddenBullCond6 hiddenBullCond7 hiddenBullCond8 hiddenBullCond9 hiddenBullCond10 hiddenBullCond11 hiddenBullCond12 hiddenBullCond13 hiddenBullCond14 hiddenBullCond15 hiddenBullCond16 hiddenBullCond17 hiddenBullCond18 hiddenBullCond19 hiddenBullCond20 hiddenBullCond21 hiddenBullCond22 hiddenBullCond23 hiddenBullCond24 hiddenBullCond25 hiddenBullCond26 hiddenBullCond27 hiddenBullCond28 hiddenBullCond29 hiddenBullCond30 longTrading
Signal Delays
enable $ bounce delayfalseboolpriceBounced delaysEnabled
min $ bounce needed to flash buy35intpriceBounced
Amount of Candles until giving up3int · min 0 · max 10priceBounced
Time Delay
Confirmation Time (bars) needed0 means the first candle - no candle close needed to flash a signal. Wait for a candle close to be sure (for alerts on the first cadle close set it to 0 and set the to "once per bar close")0int · min 0plFound1 oscHL1 priceLL1 oscLL1 priceHL1 plFound2 oscHL2 priceLL2 oscLL2 priceHL2 plFound3 oscHL3 priceLL3 oscLL3 priceHL3 plFound4 oscHL4 priceLL4 oscLL4 priceHL4 plFound5 oscHL5 priceLL5 oscLL5 priceHL5 plFound6 oscHL6 priceLL6 oscLL6 priceHL6 plFound7 oscHL7 priceLL7 oscLL7 priceHL7 plFound8 oscHL8 priceLL8 oscLL8 priceHL8 plFound9 oscHL9 priceLL9 oscLL9 priceHL9 plFound10 oscHL10 priceLL10 oscLL10 priceHL10 plFound11 oscHL11 priceLL11 oscLL11 priceHL11 plFound12 oscHL12 priceLL12 oscLL12 priceHL12 plFound13 oscHL13 priceLL13 oscLL13 priceHL13 plFound14 oscHL14 priceLL14 oscLL14 priceHL14 plFound15 oscHL15 priceLL15 oscLL15 priceHL15 plFound16 oscHL16 priceLL16 oscLL16 priceHL16 plFound17 oscHL17 priceLL17 oscLL17 priceHL17 plFound18 oscHL18 priceLL18 oscLL18 priceHL18 plFound19 oscHL19 priceLL19 oscLL19 priceHL19 plFound20 oscHL20 priceLL20 oscLL20 priceHL20 plFound21 oscHL21 priceLL21 oscLL21 priceHL21 plFound22 oscHL22 priceLL22 oscLL22 priceHL22 plFound23 oscHL23 priceLL23 oscLL23 priceHL23 plFound24 oscHL24 priceLL24 oscLL24 priceHL24 plFound25 oscHL25 priceLL25 oscLL25 priceHL25 plFound26 oscHL26 priceLL26 oscLL26 priceHL26 plFound27 oscHL27 priceLL27 oscLL27 priceHL27 plFound28 oscHL28 priceLL28 oscLL28 priceHL28 plFound29 oscHL29 priceLL29 oscLL29 priceHL29 plFound30 oscHL30 priceLL30 oscLL30 priceHL30 Regular Bullish 1 Label Hidden Bullish 1 Label Regular Bullish 2 Label Hidden Bullish 2 Label Regular Bullish 3 Label Hidden Bullish 3 Label Regular Bullish 4 Label Hidden Bullish 4 Label Regular Bullish 5 Label Hidden Bullish 5 Label Regular Bullish 6 Label Hidden Bullish 6 Label Regular Bullish 7 Label Hidden Bullish 7 Label Regular Bullish 8 Label Hidden Bullish 8 Label Regular Bullish 9 Label Hidden Bullish 9 Label Regular Bullish 10 Label Hidden Bullish 10 Label Regular Bullish 11 Label Hidden Bullish 11 Label Regular Bullish 12 Label Hidden Bullish 12 Label Regular Bullish 13 Label Hidden Bullish 13 Label Regular Bullish 14 Label Hidden Bullish 14 Label Regular Bullish 15 Label Hidden Bullish 15 Label Regular Bullish 16 Label Hidden Bullish 16 Label Regular Bullish 17 Label Hidden Bullish 17 Label Regular Bullish 18 Label Hidden Bullish 18 Label Regular Bullish 19 Label Hidden Bullish 19 Label Regular Bullish 20 Label Hidden Bullish 20 Label Regular Bullish 21 Label Hidden Bullish 21 Label Regular Bullish 22 Label Hidden Bullish 22 Label Regular Bullish 23 Label Hidden Bullish 23 Label Regular Bullish 24 Label Hidden Bullish 24 Label Regular Bullish 25 Label Hidden Bullish 25 Label Regular Bullish 26 Label Hidden Bullish 26 Label Regular Bullish 27 Label Hidden Bullish 27 Label Regular Bullish 28 Label Hidden Bullish 28 Label Regular Bullish 29 Label Hidden Bullish 29 Label Regular Bullish 30 Label Hidden Bullish 30 Label
EMA break Delay
enable wait for moving average breakwaits for a break of the moving average to flash a signalfalseboolEmaIsBroken delaysEnabled
EMA Lengthdefines the length of the moving average which it needs to break before a signal flashes5intEmaIsBroken
Oscillator EMA Cross Delay
enable wait for Oscillator and Oscillator EMA CrossfalsebooloscCross delaysEnabled
Amount of Candles until giving up3int · min 0 · max 10oscCross
Ranges & Filter
only long on in an uptrend (rising moving average)falseboolisInEMAUptrend
EMA Length to determine an uptrenddefines the length of the of the moving average200intEmaUptrend
divergence below OverSold
enable Oversold limitsonly works with RSI, MFI and RVSIfalseboolRSIwasBelowOS isBelowRsiBull
only show Signals if the Oscillator was below30intRSIwasBelowOS Oversold
within the last (x candles)2intosLowestRsi
only show signals if the Oscillator is35intisBelowRsiBull max RSI for Bull divergence
manual Range for divergence signal
enable manual Bullish Range-1falseboolisWithinLongRange line 96
Range 1 - Bullish high10000000intisWithinLongRange1
Range 1 - Bullish low0intisWithinLongRange1
enable manual Bullish Range-2falseboolisWithinLongRange line 96
Range 2 - Bullish high10000000intisWithinLongRange2
Range 2 - Bullish low0intisWithinLongRange2
enable manual Bullish Range-1falseboolisWithinLongRange line 96
Range 3 - Bullish high10000000intisWithinLongRange3
Range 3 - Bullish low0intisWithinLongRange3
enable manual Bullish Range-2falseboolisWithinLongRange line 96
Range 4 - Bullish high10000000intisWithinLongRange4
Range 4 - Bullish low0intisWithinLongRange4
EMA Range for divergence signal
enable EMA as High of the Long RangefalseboolisBelowEmaBullHigh
Length9int · min 1emaBullHighOut
SourceclosesourceemaBullHighOut
deviation0int · min -500 · max 500unused
enable EMA as Low of the Long RangefalseboolisBelowEmaBullLow
Length55int · min 1emaBullLowOut
SourceclosesourceemaBullLowOut
deviation0int · min -500 · max 500unused
VWAP Range for divergence signal
enable VWAP as High of the Long RangefalseboolisBelowVwap
enable VWAP as Low of the Long RangefalseboolisAboveVwap
enable VWAP Upper Diviation as High of the Long RangefalseboolisBelowVwapUpperDivi
enable VWAP Lower Diviation as Low of the Long RangefalseboolisAboveVwapLowerDivi
VWAP Settings
Anchor PeriodSessionstring · options ['Session', 'Week', 'Month', 'Quarter', 'Year', 'Decade', 'Century', 'Earnings', 'Dividends', 'Splits']isNewPeriod
Sourcehlc3source_vwap isNewPeriod bottom top
Offset0intunused
Bands Standard Diviation Multiplier1.0float_vwap bottom top
auto fib range for divergence signal
enable Auto fib as High of the Long RangefalseboolisBelowfibbullHigh line 184
fib Level0.5float · options [0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1]fibHighPrice
Auto Fib Lookback200int · min 1fibHighLow fibHighHigh
enable Auto fib as Low of the Long RangefalseboolisBelowfibbullLow line 189
fib Level0.886float · options [0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1]fibLowPrice
Auto Fib Lookback200int · min 1fibLowHigh fibLowLow
Stop Loss Settings
enable Stop Losstrueboolexit longTP-SL exit longTP-SL exit longTP-SL line 1137 line 1139 line 1189 line 1198 line 1203
SL based on static % or based on the lowuse the low as SLstring · options ['use the low as SL', 'use the static % as SL']exit longTP-SL exit longTP-SL line 1137 line 1139 line 1189 line 1198
Stop Loss at the low
choose offset from the lowuse % as offsetstring · options ['use $ as offset', 'use % as offset']line 1137 line 1139
SL Offset from the Low in %0.35floatlongSlLow
SL Offset from the Low in $100floatlongSlLow
SL lookback for Low5int · min 1 · max 50longSlLow
static % Stop Loss
Stop Loss in %0.5floatlongSL
Take Profit
Take Profit in %2floatlongTP1
alert settings
Alert Optionsonce per bar closestring · options ['once per bar', 'once per bar close', 'all']alertFreq
Buy Alert MessageBullish Divergence detected, put your SL @stringalert
enable Stop Loss Value at the end of "buy Alert message"trueboolline 1159 line 1161 line 1163
Buy Alert message after SL Valuestringalert

What it calculates

  • EMAOscillator Source (low), EMA Length to determine an uptrend (200)EmaUptrend · line 70
  • SMASource (close), Length (9)emaBullHighOut · line 105
  • SMASource (close), Length (55)emaBullLowOut · line 112
  • Lowestlow, Auto Fib Lookback (200)fibHighLow · line 186
  • Highesthigh, Auto Fib Lookback (200)fibHighHigh · line 185
  • Highesthigh, Auto Fib Lookback (200)fibLowHigh · line 190
  • Lowestlow, Auto Fib Lookback (200)fibLowLow · line 191
  • RSIOscillator Source (low), Oscillator Length (14)osc · line 245
  • CUM / Changeta.change(src) * volumenv · line 251
  • EMAnv, Oscillator secondary length (9)av · line 252
  • RSIav, Oscillator Length (14)RVSI · line 253
  • ChangeOscillator Source (low)upper · line 262
  • ChangeOscillator Source (low)lower · line 263
  • Change / EMAta.ema(ta.ema(ta.ema(math.log(src), seclen), seclen), seclen)trix · line 267
  • EMAosc, Oscillator Moving Average Length (9)oscema · line 269
  • Lowestosc, within the last (x candles) (2)osLowestRsi · line 273
  • Pivotlowosc, Pivot Lookback Left-1 (2), Confirmation Time (bars) needed (0)plFound1 · line 294
  • Pivotlowosc, Lookback Left-2 (3), Confirmation Time (bars) needed (0)plFound2 · line 320
  • Pivotlowosc, Pivot Lookback Left-3 (4), Confirmation Time (bars) needed (0)plFound3 · line 345
  • Pivotlowosc, Lookback Left-4 (5), Confirmation Time (bars) needed (0)plFound4 · line 371
  • Pivotlowosc, Pivot Lookback Left-5 (6), Confirmation Time (bars) needed (0)plFound5 · line 397
  • Pivotlowosc, Lookback Left-6 (7), Confirmation Time (bars) needed (0)plFound6 · line 423
  • Pivotlowosc, Pivot Lookback Left-7 (9), Confirmation Time (bars) needed (0)plFound7 · line 449
  • Pivotlowosc, Lookback Left-8 (10), Confirmation Time (bars) needed (0)plFound8 · line 475
  • Pivotlowosc, Pivot Lookback Left-9 (11), Confirmation Time (bars) needed (0)plFound9 · line 501
  • Pivotlowosc, Lookback Left-10 (12), Confirmation Time (bars) needed (0)plFound10 · line 527
  • Pivotlowosc, Pivot Lookback Left-11 (13), Confirmation Time (bars) needed (0)plFound11 · line 553
  • Pivotlowosc, Lookback Left-12 (14), Confirmation Time (bars) needed (0)plFound12 · line 579
  • Pivotlowosc, Pivot Lookback Left-13 (15), Confirmation Time (bars) needed (0)plFound13 · line 605
  • Pivotlowosc, Lookback Left-14 (16), Confirmation Time (bars) needed (0)plFound14 · line 631
  • Pivotlowosc, Pivot Lookback Left-15 (17), Confirmation Time (bars) needed (0)plFound15 · line 657
  • Pivotlowosc, Lookback Left-16 (18), Confirmation Time (bars) needed (0)plFound16 · line 683
  • Pivotlowosc, Pivot Lookback Left-17 (19), Confirmation Time (bars) needed (0)plFound17 · line 709
  • Pivotlowosc, Lookback Left-18 (20), Confirmation Time (bars) needed (0)plFound18 · line 735
  • Pivotlowosc, Pivot Lookback Left-19 (22), Confirmation Time (bars) needed (0)plFound19 · line 761
  • Pivotlowosc, Lookback Left-20 (25), Confirmation Time (bars) needed (0)plFound20 · line 787
  • Pivotlowosc, Pivot Lookback Left-21 (28), Confirmation Time (bars) needed (0)plFound21 · line 813
  • Pivotlowosc, Lookback Left-22 (31), Confirmation Time (bars) needed (0)plFound22 · line 839
  • Pivotlowosc, Pivot Lookback Left-23 (34), Confirmation Time (bars) needed (0)plFound23 · line 865
  • Pivotlowosc, Lookback Left-24 (37), Confirmation Time (bars) needed (0)plFound24 · line 891
  • Pivotlowosc, Pivot Lookback Left-25 (39), Confirmation Time (bars) needed (0)plFound25 · line 917
  • Pivotlowosc, Lookback Left-26 (42), Confirmation Time (bars) needed (0)plFound26 · line 943
  • Pivotlowosc, Pivot Lookback Left-27 (45), Confirmation Time (bars) needed (0)plFound27 · line 969
  • Pivotlowosc, Lookback Left-28 (48), Confirmation Time (bars) needed (0)plFound28 · line 995
  • Pivotlowosc, Pivot Lookback Left-29 (51), Confirmation Time (bars) needed (0)plFound29 · line 1021
  • Pivotlowosc, Lookback Left-30 (54), Confirmation Time (bars) needed (0)plFound30 · line 1047
  • Lowestlow, SL lookback for Low (5)longSlLow · line 1136

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 383 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Bull longFinalBullAlert or FinalBullAlert2On1186
Open Bull longFinalHiddenBullAlert2 or FinalHiddenBullAlertOn1187
Exit longTP-SL stop and limitenableSL and whichSL == 'use the static % as SL'On1190
Exit longTP-SL stop and limitenableSL and whichSL == 'use the low as SL' and ta.barssince(veryFinalAlert) < 2 and barsSinceLastEntry() < 2On1199
Exit longTP-SL limitnot enableSLOn1204

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

Alerts

AlertCallMessageLine
(no title)alertstr.tostring(BuyAlertMessage)1160
(no title)alertstr.tostring(BuyAlertMessage) + str.tostring(longSlLow) + str.tostring(AfterSLMessage)1162
(no title)alertstr.tostring(BuyAlertMessage) + str.tostring(longSlLow) + str.tostring(AfterSLMessage)1164
Bullish divergencealertconditionBull Div {{ticker}}1165

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.

  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
  • ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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

Similar scripts

Indicators and strategies built from the same calculations.

ScriptSharesTypeNetTradesMax drawdown
MACD 5 iN 1 [Pro-Tool] by HamidBoxsma ema rsi pivotlow highest lowestv4 strategyNo trades on this market
sma RSI & sudden buy and sell Strategy v1 by samwillingtonema rsi highest lowest smav5 strategy+7.6%153.7%
VXD Supercycle by Vvaz_ema sma cum pivotlow highest lowest rsiv5 strategydoes not run in Zeal Terminal
X48 - Strategy - MA Type Cross + TPSL - Future&Spot - V.2 by X4815162342ema rsi sma highest lowest pivotlowv5 strategydoes not run in Zeal Terminal
MZ SRSI Strategy V1.0 by MightyZingerema sma highest lowest rsiv4 strategyNo trades on this market

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 2 strategy calls use the when = argument (line 1186, 1187). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 5 settings use the untyped input() (line 16, 62, 69, 103, 110). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

Not verified

The v5 script does not run in Zeal Terminal's engine (request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).), so this step could not be checked.

  • Line 16: input() → input.int()
  • Line 62: input() → input.int()
  • Line 69: input() → input.int()
  • Line 103: input() → input.source()
  • Line 110: input() → input.source()
  • Line 1186: when = FinalBullAlert or FinalBullAlert2 → if block
  • Line 1187: when = FinalHiddenBullAlert2 or FinalHiddenBullAlert → if block
⋯seclen = input.int(9, minval=1, title="Oscillator secondary length", group="═════════ Oscillator settings ══════════", tooltip="affects only RVSI and Trix RSI. For the TRIX RSI this defines the length of the TRIX. default value = 9 and for the RVSI it defines the Volume moving average length, default value = 5")-emalen = input(9, 'Oscillator Moving Average Length', group='═════════ Oscillator settings ══════════', tooltip="defines the length of the of the Oscillator moving average")+emalen = input.int(9, 'Oscillator Moving Average Length', group='═════════ Oscillator settings ══════════', tooltip="defines the length of the of the Oscillator moving average")rangeLower = input.int(title='Min Lookback Range', defval=0, group='═════ Oscillator Divergence Settings ══════', inline='Input 0')⋯enableWaitForEmaBreak =  input.bool(title='enable wait for moving average break', defval=false, group='EMA break Delay', tooltip="waits for a break of the moving average to flash a signal")-WaitForEmaBreakLen = input(5, 'EMA Length', group='EMA break Delay', tooltip="defines the length of the moving average which it needs to break before a signal flashes")+WaitForEmaBreakLen = input.int(5, 'EMA Length', group='EMA break Delay', tooltip="defines the length of the moving average which it needs to break before a signal flashes")// wait Oscillator and Oscillator EMA cross⋯enableOnlyLongUptrend =  input.bool(title='only long on in an uptrend (rising moving average)', defval=false, group='═══════════ Ranges & Filter ═══════════', tooltip="")-OnlyLongUptrendEmaLen = input(200, 'EMA Length to determine an uptrend', group='═══════════ Ranges & Filter ═══════════', tooltip="defines the length of the of the moving average")+OnlyLongUptrendEmaLen = input.int(200, 'EMA Length to determine an uptrend', group='═══════════ Ranges & Filter ═══════════', tooltip="defines the length of the of the moving average")EmaUptrend = ta.ema(src, OnlyLongUptrendEmaLen)⋯emaBullHighLen = input.int(9, minval=1, title='Length', group='══════ EMA Range for divergence signal', inline='Input 4')-emaBullHighSrc = input(close, title='Source', group='══════ EMA Range for divergence signal', inline='Input 4')+emaBullHighSrc = input.source(close, title='Source', group='══════ EMA Range for divergence signal', inline='Input 4')emaBullHighDevi = input.int(title='deviation', defval=0, minval=-500, maxval=500, group='══════ EMA Range for divergence signal', inline='Input 4')⋯emaBullLowLen = input.int(55, minval=1, title='Length', group='══════ EMA Range for divergence signal', inline='Input 5')-emaBullLowSrc = input(close, title='Source', group='══════ EMA Range for divergence signal', inline='Input 5')+emaBullLowSrc = input.source(close, title='Source', group='══════ EMA Range for divergence signal', inline='Input 5')emaBullLowOffset = input.int(title='deviation', defval=0, minval=-500, maxval=500, group='══════ EMA Range for divergence signal', inline='Input 5')⋯strategy.risk.allow_entry_in(longTrading == true and shortTrading == true ? strategy.direction.all : longTrading == true ? strategy.direction.long : shortTrading == true ? strategy.direction.short : na)-strategy.entry('Bull', strategy.long, comment='B Long', when=FinalBullAlert or FinalBullAlert2)+if FinalBullAlert or FinalBullAlert2+    strategy.entry('Bull', strategy.long, comment='B Long')-strategy.entry('Bull', strategy.long, comment='HB Long', when=FinalHiddenBullAlert2 or FinalHiddenBullAlert)+if FinalHiddenBullAlert2 or FinalHiddenBullAlert+    strategy.entry('Bull', strategy.long, comment='HB Long')// check which SL to use⋯

Does it run in Pine Script v6?

Not tested

The v5 script does not run in Zeal Terminal's engine (request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).), 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.

⋯// thanks to JayTradingCharts RSI Divergence /w Alerts indicator for the base code. -//@version=5+//@version=6//⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2No Request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).Not measured
PineTSNot testedNot testedNot 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.

Source

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// made by Imal_Max // thanks to The1IamNeo's and brandons idea//// thanks to JayTradingCharts RSI Divergence /w Alerts indicator for the base code. //@version=5//// 🔥 uncomment the line below to enable the alerts and disable the backtester//indicator(title="Ultimate Bullish Divergence for RSI MFI RVSI OBV TRIXRSI w/ Buy Alerts", shorttitle="Ultimate Bull Divergence", format=format.price)//, timeframe="")// 🔥 comment the line below to disable the backtester + uncomment the lines slightly below and at the bottom of the scriptstrategy(title="Ultimate Bullish Divergence for RSI MFI RVSI OBV TRIXRSI w/ Buy Signals", shorttitle="Ultimate Bull Divergence Backtester", overlay=false, pyramiding=1, process_orders_on_close=true, calc_on_every_tick=true, initial_capital=1000, currency = currency.USD, default_qty_value=100, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.05, slippage=2)selectOsc = input.string("RSI", title="Select Oscillator", group='═════════ Oscillator settings ══════════', options=["RSI","OBV","RVSI","MFI","TRIX RSI"], tooltip="RSI = Relative Strengh Index; OBV = On Balance Volume; RVSI = Relative Volume Strengh Index; MFI Money Flow Index; TRIX RSI = Tripple Exponetial Relative Strength")src = input.source(title='Oscillator Source', defval=low, group='═════════ Oscillator settings ══════════', tooltip="RSI, RVSI, OBV and TRIX RSI default Source: Close; MFI default Source: hlc3")len = input.int(title='Oscillator Length', minval=1, defval=14, group='═════════ Oscillator settings ══════════', tooltip="RSI/MFI default Period = 14; RVSI = 10; TRIX RSI = 9; OBV has no period.")seclen = input.int(9, minval=1, title="Oscillator secondary length", group="═════════ Oscillator settings ══════════", tooltip="affects only RVSI and Trix RSI. For the TRIX RSI this defines the length of the TRIX. default value = 9 and for the RVSI it defines the Volume moving average length, default value = 5")emalen = input(9, 'Oscillator Moving Average Length', group='═════════ Oscillator settings ══════════', tooltip="defines the length of the of the Oscillator moving average")rangeLower = input.int(title='Min Lookback Range', defval=0, group='═════ Oscillator Divergence Settings ══════', inline='Input 0')rangeUpper = input.int(title='Max Lookback', defval=200, group='═════ Oscillator Divergence Settings ══════', inline='Input 0', tooltip="reduces the Lookback range that you define with Pivot Lookback Left 1-30 ")enableonlyOneLB = input.bool(title='Only use the first look back period', defval=false, group='═════ Oscillator Divergence Settings ══════')                                                         lbL1 = input.int(title='Pivot Lookback Left-1', defval=2, group='═════ Oscillator Divergence Settings ══════', inline='Input 1', tooltip="Amount of bars to look back to find pivot lows on the Oscillator and Price")lbL2 = input.int(title='Lookback Left-2', defval=3, group='═════ Oscillator Divergence Settings ══════', inline='Input 1')lbL3 = input.int(title='Pivot Lookback Left-3', defval=4, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL4 = input.int(title='Lookback Left-4', defval=5, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL5 = input.int(title='Pivot Lookback Left-5', defval=6, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL6 = input.int(title='Lookback Left-6', defval=7, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL7 = input.int(title='Pivot Lookback Left-7', defval=9, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL8 = input.int(title='Lookback Left-8', defval=10, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL9 = input.int(title='Pivot Lookback Left-9', defval=11, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL10 = input.int(title='Lookback Left-10', defval=12, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL11 = input.int(title='Pivot Lookback Left-11', defval=13, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL12 = input.int(title='Lookback Left-12', defval=14, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL13 = input.int(title='Pivot Lookback Left-13', defval=15, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL14 = input.int(title='Lookback Left-14', defval=16, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL15 = input.int(title='Pivot Lookback Left-15', defval=17, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL16 = input.int(title='Lookback Left-16', defval=18, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL17 = input.int(title='Pivot Lookback Left-17', defval=19, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL18 = input.int(title='Lookback Left-18', defval=20, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL19 = input.int(title='Pivot Lookback Left-19', defval=22, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL20 = input.int(title='Lookback Left-20', defval=25, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL21 = input.int(title='Pivot Lookback Left-21', defval=28, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL22 = input.int(title='Lookback Left-22', defval=31, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL23 = input.int(title='Pivot Lookback Left-23', defval=34, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL24 = input.int(title='Lookback Left-24', defval=37, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL25 = input.int(title='Pivot Lookback Left-25', defval=39, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL26 = input.int(title='Lookback Left-26', defval=42, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL27 = input.int(title='Pivot Lookback Left-27', defval=45, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL28 = input.int(title='Lookback Left-28', defval=48, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL29 = input.int(title='Pivot Lookback Left-29', defval=51, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')lbL30 = input.int(title='Lookback Left-30', defval=54, group='═════ Oscillator Divergence Settings ══════', inline='Input 2')plotBull = input.bool(title='Plot Bullish', defval=true, group='═════ Oscillator Divergence Settings ══════', inline='Input 4', tooltip="Price makes a lower low while the Oscillator is making a higher low")plotHiddenBull = input.bool(title='Plot Hidden Bullish', defval=false, group='═════ Oscillator Divergence Settings ══════', inline='Input 4', tooltip="Price makes a higher low while Oscillator is making a lower low")///////////// Delay inputs// Price bounce delay   enablepriceBounceNeeded = input.bool(title='enable $ bounce delay', defval=false, group='═══════════ Signal Delays  ═══════════')priceBounceNeeded = input.int(title='min $ bounce needed to flash buy', defval=35, group='═══════════ Signal Delays  ═══════════')priceBounceNeededLbL = input.int(title='Amount of Candles until giving up', defval=3, minval=0, maxval=10, group='═══════════ Signal Delays  ═══════════')// bars delaylbR = input.int(title='Confirmation Time (bars) needed', minval=0, defval=0, group='Time Delay', tooltip='0 means the first candle - no candle close needed to flash a signal. Wait for a candle close to be sure (for alerts on the first cadle close set it to 0 and set the to "once per bar close")')// EMA break delayenableWaitForEmaBreak =  input.bool(title='enable wait for moving average break', defval=false, group='EMA break Delay', tooltip="waits for a break of the moving average to flash a signal")WaitForEmaBreakLen = input(5, 'EMA Length', group='EMA break Delay', tooltip="defines the length of the moving average which it needs to break before a signal flashes")// wait Oscillator and Oscillator EMA crossenableOscCross = input.bool(title='enable wait for Oscillator and Oscillator EMA Cross', defval=false, group='Oscillator EMA Cross Delay', tooltip="")oscCrosslookback = input.int(title='Amount of Candles until giving up', defval=3, minval=0, maxval=10, group='Oscillator EMA Cross Delay')// ranges and filter// only long on rising EMA inputsenableOnlyLongUptrend =  input.bool(title='only long on in an uptrend (rising moving average)', defval=false, group='═══════════ Ranges & Filter ═══════════', tooltip="")OnlyLongUptrendEmaLen = input(200, 'EMA Length to determine an uptrend', group='═══════════ Ranges & Filter ═══════════', tooltip="defines the length of the of the moving average")EmaUptrend = ta.ema(src, OnlyLongUptrendEmaLen)isInEMAUptrend = ta.change(EmaUptrend) > 0 or not enableOnlyLongUptrend// ob/os divergence settingsenableRsiLimit = input.bool(title='enable Oversold limits', defval=false, group='divergence below OverSold', tooltip="only works with RSI, MFI and RVSI")osvalue = input.int(title='only show Signals if the Oscillator was below', defval=30, group='divergence below OverSold', inline='Input 1')oslookback = input.int(title='within the last (x candles)', defval=2, group='divergence below OverSold', inline='Input 1')maxBullRSI = input.int(title='only show signals if the Oscillator is', defval=35, group='divergence below OverSold')// manual ranges for divergence                                                           enableManualbull1 = input.bool(title='enable manual Bullish Range-1', defval=false, group='══════ manual Range for divergence signal')manualbullHigh1 = input.int(title='Range 1 - Bullish high', defval=10000000, group='══════ manual Range for divergence signal', inline='Input 0')manualbullLow1 = input.int(title='Range 1 - Bullish low', defval=0, group='══════ manual Range for divergence signal', inline='Input 0')enableManualbull2 = input.bool(title='enable manual Bullish Range-2', defval=false, group='══════ manual Range for divergence signal')manualbullHigh2 = input.int(title='Range 2 - Bullish high', defval=10000000, group='══════ manual Range for divergence signal', inline='Input 1')manualbullLow2 = input.int(title='Range 2 - Bullish low', defval=0, group='══════ manual Range for divergence signal', inline='Input 1')enableManualbull3 = input.bool(title='enable manual Bullish Range-1', defval=false, group='══════ manual Range for divergence signal')manualbullHigh3 = input.int(title='Range 3 - Bullish high', defval=10000000, group='══════ manual Range for divergence signal', inline='Input 2')manualbullLow3 = input.int(title='Range 3 - Bullish low', defval=0, group='══════ manual Range for divergence signal', inline='Input 2')enableManualbull4 = input.bool(title='enable manual Bullish Range-2', defval=false, group='══════ manual Range for divergence signal')manualbullHigh4 = input.int(title='Range 4 - Bullish high', defval=10000000, group='══════ manual Range for divergence signal', inline='Input 3')manualbullLow4 = input.int(title='Range 4 - Bullish low', defval=0, group='══════ manual Range for divergence signal', inline='Input 3')// check if divergence happend within manual levelsisWithinLongRange1 = (close < manualbullHigh1 and close > manualbullLow1)isWithinLongRange2 = (close < manualbullHigh2 and close > manualbullLow2)isWithinLongRange3 = (close < manualbullHigh3 and close > manualbullLow3)isWithinLongRange4 = (close < manualbullHigh4 and close > manualbullLow4)isWithinLongRange = trueif enableManualbull1 or enableManualbull2 or enableManualbull3 or enableManualbull4    isWithinLongRange := (isWithinLongRange1 and enableManualbull1) or (isWithinLongRange2 and enableManualbull2) or (isWithinLongRange3 and enableManualbull3) or (isWithinLongRange4 and enableManualbull4)/////////////////////////// Get ranges to look for divergences from indicators// EMA // EMA Bull range highenableEmaBullHigh = input.bool(title='enable EMA as High of the Long Range', defval=false, group='══════ EMA Range for divergence signal')emaBullHighLen = input.int(9, minval=1, title='Length', group='══════ EMA Range for divergence signal', inline='Input 4')emaBullHighSrc = input(close, title='Source', group='══════ EMA Range for divergence signal', inline='Input 4')emaBullHighDevi = input.int(title='deviation', defval=0, minval=-500, maxval=500, group='══════ EMA Range for divergence signal', inline='Input 4')emaBullHighOut = ta.sma(emaBullHighSrc, emaBullHighLen)isBelowEmaBullHigh = close < emaBullHighOut or not enableEmaBullHigh// EMA Bull range lowenableEmaBullLow = input.bool(title='enable EMA as Low of the Long Range', defval=false, group='══════ EMA Range for divergence signal')emaBullLowLen = input.int(55, minval=1, title='Length', group='══════ EMA Range for divergence signal', inline='Input 5')emaBullLowSrc = input(close, title='Source', group='══════ EMA Range for divergence signal', inline='Input 5')emaBullLowOffset = input.int(title='deviation', defval=0, minval=-500, maxval=500, group='══════ EMA Range for divergence signal', inline='Input 5')emaBullLowOut = ta.sma(emaBullLowSrc, emaBullLowLen)isBelowEmaBullLow = close > emaBullLowOut or not enableEmaBullLowiswithinEmaRange = isBelowEmaBullHigh and isBelowEmaBullLow// EMA END// VWAPenableVwapBullHigh = input.bool(title='enable VWAP as High of the Long Range', defval=false, group='════ VWAP Range for divergence signal')enableVwapBullLow = input.bool(title='enable VWAP as Low of the Long Range', defval=false, group='════ VWAP Range for divergence signal')enableVwapDiviBullHigh = input.bool(title='enable VWAP Upper Diviation as High of the Long Range', defval=false, group='════ VWAP Range for divergence signal')enableVwapDiviBullLow = input.bool(title='enable VWAP Lower Diviation as Low of the Long Range', defval=false, group='════ VWAP Range for divergence signal')computeVWAP(src, isNewPeriod, stDevMultiplier) =>    var float sumSrcVol = na    var float sumVol = na    var float sumSrcSrcVol = na    sumSrcVol := isNewPeriod ? src * volume : src * volume + sumSrcVol[1]    sumVol := isNewPeriod ? volume : volume + sumVol[1]    // sumSrcSrcVol calculates the dividend of the equation that is later used to calculate the standard deviation    sumSrcSrcVol := isNewPeriod ? volume * math.pow(src, 2) : volume * math.pow(src, 2) + sumSrcSrcVol[1]    _vwap = sumSrcVol / sumVol    variance = sumSrcSrcVol / sumVol - math.pow(_vwap, 2)    variance := variance < 0 ? 0 : variance    stDev = math.sqrt(variance)    lowerBand = _vwap - stDev * stDevMultiplier    upperBand = _vwap + stDev * stDevMultiplier    [_vwap, lowerBand, upperBand]hideonDWM = falsevar anchor = input.string(defval='Session', title='Anchor Period', options=['Session', 'Week', 'Month', 'Quarter', 'Year', 'Decade', 'Century', 'Earnings', 'Dividends', 'Splits'], group='VWAP Settings')vsrc = input.source(title='Source', defval=hlc3, group='VWAP Settings')offset = input.int(0, title='Offset', group='VWAP Settings')stdevMult = input.float(1.0, title='Bands Standard Diviation Multiplier', group='VWAP Settings')timeChange(period) =>    ta.change(time(period))new_earnings = request.earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on)new_dividends = request.dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on)new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on)isNewPeriod = anchor == 'Earnings' ? new_earnings : anchor == 'Dividends' ? new_dividends : anchor == 'Splits' ? new_split : na(vsrc[1]) ? true : anchor == 'Session' ? timeChange('D') : anchor == 'Week' ? timeChange('W') : anchor == 'Month' ? timeChange('M') : anchor == 'Quarter' ? timeChange('3M') : anchor == 'Year' ? timeChange('12M') : anchor == 'Decade' ? timeChange('12M') and year % 10 == 0 : anchor == 'Century' ? timeChange('12M') and year % 100 == 0 : falsefloat vwapValue = nafloat std = nafloat upperBandValue = nafloat lowerBandValue = nashowBands = trueif not(hideonDWM and timeframe.isdwm)    [_vwap, bottom, top] = computeVWAP(vsrc, isNewPeriod, stdevMult)    vwapValue := _vwap    upperBandValue := showBands ? top : na    lowerBandValue := showBands ? bottom : na    // check if inside VWAP RangeisBelowVwap = vwapValue < close or not enableVwapBullHighisAboveVwap = vwapValue > close or not enableVwapBullLowisAboveVwapLowerDivi = lowerBandValue < close or not enableVwapDiviBullLowisBelowVwapUpperDivi = upperBandValue > close or not enableVwapDiviBullHighisWithinVwapRange = isBelowVwap and isAboveVwap and isAboveVwapLowerDivi and isBelowVwapUpperDivi// VWAP END// auto fib ranges// fib fibbull range high                                                                                                                                    enablefibbullHigh = input.bool(title='enable Auto fib as High of the Long Range', defval=false, group='════ auto fib range for divergence signal', inline='Input 0')selectfibbullHigh = input.float(0.5, 'fib Level', options=[0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1], group='══ auto fib range for divergence signal')fibbullHighLookback = input.int(title='Auto Fib Lookback', minval=1, defval=200, group='════ auto fib range for divergence signal', inline='Input 1')//fibbullHighDivi = input.int(title='diviation in %', defval=5, group='══ auto fib range for divergence signal', inline='Input 1')// fib fibbull range lowenablefibbullLow = input.bool(title='enable Auto fib as Low of the Long Range', defval=false, group='════ auto fib range for divergence signal', inline='Input 2')selectfibbullLow = input.float(0.886, 'fib Level', options=[0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1], group='════ auto fib range for divergence signal')fibbullLowhLookback = input.int(title='Auto Fib Lookback', minval=1, defval=200, group='════ auto fib range for divergence signal', inline='Input 3')//fibbullLowhDivi = input.int(title='diviation in %', defval=5, group='══ auto fib range for divergence signal', inline='Input 3')isBelowfibbullHigh = trueisBelowfibbullLow = truefibLowPrice = 0.1fibHighPrice = 0.1fibHighLow = 0.1fibHighHigh = 0.1fibLowHigh = 0.1fibLowLow = 0.1if enablefibbullHigh    fibHighHigh := ta.highest(high, fibbullHighLookback)    fibHighLow := ta.lowest(low, fibbullHighLookback)    fibHighPrice := (fibHighHigh - fibHighLow) * (1 - selectfibbullHigh) + fibHighLow //+ fibbullHighDivi    isBelowfibbullHigh := fibHighPrice > ta.lowest(low, 2) or not enablefibbullHighif enablefibbullLow    fibLowHigh := ta.highest(high, fibbullLowhLookback)    fibLowLow := ta.lowest(low, fibbullLowhLookback)    fibLowPrice := (fibLowHigh - fibLowLow) * (1 - selectfibbullLow) + fibLowLow// + fibbullLowhDivi    isBelowfibbullLow := fibLowPrice < ta.highest(low, 2) or not enablefibbullLow    //plot(fibHighHigh)//plot(fibHighLow)//plot(fibHighPrice, color=color.orange)//plot(fibLowPrice, color=color.orange)isWithinFibRange =  isBelowfibbullHigh and isBelowfibbullLow///////  auto fib END/// Ranges checksisWithinLongRanges = isWithinLongRange and iswithinEmaRange and isWithinVwapRange and isWithinFibRange and isInEMAUptrend// divergence label colorsbullColor = color.purplebullColor1 = color.aquabullColor2 = color.blackbullColor3 = color.bluebullColor4 = color.fuchsiabullColor5 = color.graybullColor6 = color.greenbullColor7 = color.limebullColor8 = color.maroonbullColor9 = color.navybullColor10 = color.olivebullColor11 = color.orangebullColor12 = color.purplebullColor13 = color.redbullColor14 = color.silverbullColor15 = color.tealbullColor16 = color.bluebullColor17 = color.navybullColor18 = color.purplebullColor19 = color.purplebullColor20 = color.redbullColor21 = color.orangebullColor22 = color.purplebullColor23 = color.redbullColor24 = color.silverbullColor25 = color.tealbullColor26 = color.limebullColor27 = color.fuchsiabullColor28 = color.limebullColor29 = color.purplebullColor30 = color.redbullColor31 = color.aquabullColor32 = color.blackbullColor33 = color.bluebullColor34 = color.fuchsiabullColor35 = color.grayhiddenBullColor = color.new(color.purple, 80)textColor = color.whitenoneColor = color.new(color.white, 100)//// Oscillators// set the var to RSI to make it workosc = ta.rsi(src, len)// calculate RSIif selectOsc == "RSI"    osc := ta.rsi(src, len)// calculate RVSIif selectOsc == "RVSI"    nv = ta.cum(ta.change(src) * volume)    av = ta.ema(nv, seclen)    RVSI = ta.rsi(av, len)    osc := RVSI    // getting OBV if selectOsc == "OBV"    osc := ta.obv    // calculate MFIif selectOsc == "MFI"    upper = math.sum(volume * (ta.change(src) <= 0 ? 0 : src), len)    lower = math.sum(volume * (ta.change(src) >= 0 ? 0 : src), len)    osc := 100.0 - 100.0 / (1.0 + upper / lower)    if selectOsc == "TRIX RSI"    trix = 10000 * ta.change(ta.ema(ta.ema(ta.ema(math.log(src), seclen), seclen), seclen))    osc := ta.rsi(trix, len)oscema = ta.ema(osc, emalen)//// Oscillators//////////////// Oscillator Conditions// check if RSI was OS or OB recentlyosLowestRsi = ta.lowest(osc, oslookback)RSIwasBelowOS = osLowestRsi < osvalue or not enableRsiLimit// check if RSI is below maxBullRSI and above minBearRSIisBelowRsiBull = osc < maxBullRSI or not enableRsiLimit/////////////////// plot ob os levelsosLevel = hline(osvalue, title='Oversold', linestyle=hline.style_dotted)maxRSIline = hline(maxBullRSI, title='max RSI for Bull divergence', linestyle=hline.style_dotted)//fill(osLevel, maxRSIline, title='Bull Zone Background', color=color.new(#4caf50, 90))//RSI0line = hline(0, title='RSI 0 Line', linestyle=hline.style_dotted)//RSI100line = hline(100, title='RSI 100 Line', linestyle=hline.style_dotted)//fill(osLevel, RSI0line, title='Oversold Zone Background', color=color.new(#4caf50, 75))////////////////////// plot Oscillator, histogram and Oscillator emaplot(osc, title='Oscillator', linewidth=2, color=color.new(#00bcd4, 0))plot(oscema, color=color.purple, title='Oscillator EMA', style=plot.style_circles)//hist = osc - oscema//plot(hist, title='Oscillator Histogram', style=plot.style_columns, color=hist >= 0 ? hist[1] < hist ? color.lime : color.purple : hist[1] < hist ? color.orange : color.red)//////////////////// plot Oscillator, histogram and Oscillator ema END   //////////////// divergence stuff start////// divergence Lookback period #1// get pivotsplFound1 = na(ta.pivotlow(osc, lbL1, lbR)) ? false : true_inRange1(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL1 = osc[lbR] > ta.valuewhen(plFound1, osc[lbR], 1) and _inRange1(plFound1[1])// Price: Lower LowpriceLL1 = low[lbR] < ta.valuewhen(plFound1, low[lbR], 1)bullCond1 = plotBull and priceLL1 and oscHL1 and plFound1 and RSIwasBelowOS and isWithinLongRanges//plot(plFound1 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond1 ? bullColor : noneColor)plotshape(bullCond1 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 1 Label', text=' B1 ', style=shape.labelup, location=location.absolute, color=bullColor1, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL1 = osc[lbR] < ta.valuewhen(plFound1, osc[lbR], 1) and _inRange1(plFound1[1])// Price: Higher LowpriceHL1 = low[lbR] > ta.valuewhen(plFound1, low[lbR], 1)hiddenBullCond1 = plotHiddenBull and priceHL1 and oscLL1 and plFound1 and RSIwasBelowOS and isWithinLongRanges//plot(plFound1 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond1 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond1 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 1 Label', text=' H B1 ', style=shape.labelup, location=location.absolute, color=bullColor1, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #1 END////// divergence Lookback period #2// get pivotsplFound2 = na(ta.pivotlow(osc, lbL2, lbR)) ? false : true_inRange2(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL2 = osc[lbR] > ta.valuewhen(plFound2, osc[lbR], 1) and _inRange2(plFound2[1])// Price: Lower LowpriceLL2 = low[lbR] < ta.valuewhen(plFound2, low[lbR], 1)bullCond2 = plotBull and priceLL2 and oscHL2 and plFound2 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound2 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond2 ? bullColor : noneColor)plotshape(bullCond2 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 2 Label', text=' B2 ', style=shape.labelup, location=location.absolute, color=bullColor2, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL2 = osc[lbR] < ta.valuewhen(plFound2, osc[lbR], 1) and _inRange2(plFound2[1])// Price: Higher LowpriceHL2 = low[lbR] > ta.valuewhen(plFound2, low[lbR], 1)hiddenBullCond2 = plotHiddenBull and priceHL2 and oscLL2 and plFound2 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound2 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond2 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond2 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 2 Label', text=' H B2 ', style=shape.labelup, location=location.absolute, color=bullColor2, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #3// get pivotsplFound3 = na(ta.pivotlow(osc, lbL3, lbR)) ? false : true_inRange3(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL3 = osc[lbR] > ta.valuewhen(plFound3, osc[lbR], 1) and _inRange3(plFound3[1])// Price: Lower LowpriceLL3 = low[lbR] < ta.valuewhen(plFound3, low[lbR], 1)bullCond3 = plotBull and priceLL3 and oscHL3 and plFound3 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound3 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond3 ? bullColor : noneColor)plotshape(bullCond3 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 3 Label', text=' B3 ', style=shape.labelup, location=location.absolute, color=bullColor3, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL3 = osc[lbR] < ta.valuewhen(plFound3, osc[lbR], 1) and _inRange3(plFound3[1])// Price: Higher LowpriceHL3 = low[lbR] > ta.valuewhen(plFound3, low[lbR], 1)hiddenBullCond3 = plotHiddenBull and priceHL3 and oscLL3 and plFound3 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound3 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond3 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond3 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 3 Label', text=' H B3 ', style=shape.labelup, location=location.absolute, color=bullColor3, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #3 END////// divergence Lookback period #4// get pivotsplFound4 = na(ta.pivotlow(osc, lbL4, lbR)) ? false : true_inRange4(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL4 = osc[lbR] > ta.valuewhen(plFound4, osc[lbR], 1) and _inRange4(plFound4[1])// Price: Lower LowpriceLL4 = low[lbR] < ta.valuewhen(plFound4, low[lbR], 1)bullCond4 = plotBull and priceLL4 and oscHL4 and plFound4 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound4 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond4 ? bullColor : noneColor)plotshape(bullCond4 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 4 Label', text=' B4 ', style=shape.labelup, location=location.absolute, color=bullColor4, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL4 = osc[lbR] < ta.valuewhen(plFound4, osc[lbR], 1) and _inRange4(plFound4[1])// Price: Higher LowpriceHL4 = low[lbR] > ta.valuewhen(plFound4, low[lbR], 1)hiddenBullCond4 = plotHiddenBull and priceHL4 and oscLL4 and plFound4 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound4 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond4 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond4 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 4 Label', text=' H B4 ', style=shape.labelup, location=location.absolute, color=bullColor4, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #4 END////// divergence Lookback period #5// get pivotsplFound5 = na(ta.pivotlow(osc, lbL5, lbR)) ? false : true_inRange5(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL5 = osc[lbR] > ta.valuewhen(plFound5, osc[lbR], 1) and _inRange5(plFound5[1])// Price: Lower LowpriceLL5 = low[lbR] < ta.valuewhen(plFound5, low[lbR], 1)bullCond5 = plotBull and priceLL5 and oscHL5 and plFound5 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound5 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond5 ? bullColor : noneColor)plotshape(bullCond5 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 5 Label', text=' B5 ', style=shape.labelup, location=location.absolute, color=bullColor5, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL5 = osc[lbR] < ta.valuewhen(plFound5, osc[lbR], 1) and _inRange5(plFound5[1])// Price: Higher LowpriceHL5 = low[lbR] > ta.valuewhen(plFound5, low[lbR], 1)hiddenBullCond5 = plotHiddenBull and priceHL5 and oscLL5 and plFound5 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound5 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond5 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond5 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 5 Label', text=' H B5 ', style=shape.labelup, location=location.absolute, color=bullColor5, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #5 END////// divergence Lookback period #6// get pivotsplFound6 = na(ta.pivotlow(osc, lbL6, lbR)) ? false : true_inRange6(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL6 = osc[lbR] > ta.valuewhen(plFound6, osc[lbR], 1) and _inRange6(plFound6[1])// Price: Lower LowpriceLL6 = low[lbR] < ta.valuewhen(plFound6, low[lbR], 1)bullCond6 = plotBull and priceLL6 and oscHL6 and plFound6 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound6 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond6 ? bullColor : noneColor)plotshape(bullCond6 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 6 Label', text=' B6 ', style=shape.labelup, location=location.absolute, color=bullColor6, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL6 = osc[lbR] < ta.valuewhen(plFound6, osc[lbR], 1) and _inRange6(plFound6[1])// Price: Higher LowpriceHL6 = low[lbR] > ta.valuewhen(plFound6, low[lbR], 1)hiddenBullCond6 = plotHiddenBull and priceHL6 and oscLL6 and plFound6 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound6 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond6 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond6 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 6 Label', text=' H B6 ', style=shape.labelup, location=location.absolute, color=bullColor6, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #6 END////// divergence Lookback period #7// get pivotsplFound7 = na(ta.pivotlow(osc, lbL7, lbR)) ? false : true_inRange7(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL7 = osc[lbR] > ta.valuewhen(plFound7, osc[lbR], 1) and _inRange7(plFound7[1])// Price: Lower LowpriceLL7 = low[lbR] < ta.valuewhen(plFound7, low[lbR], 1)bullCond7 = plotBull and priceLL7 and oscHL7 and plFound7 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound7 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond7 ? bullColor : noneColor)plotshape(bullCond7 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 7 Label', text=' B7 ', style=shape.labelup, location=location.absolute, color=bullColor7, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL7 = osc[lbR] < ta.valuewhen(plFound7, osc[lbR], 1) and _inRange7(plFound7[1])// Price: Higher LowpriceHL7 = low[lbR] > ta.valuewhen(plFound7, low[lbR], 1)hiddenBullCond7 = plotHiddenBull and priceHL7 and oscLL7 and plFound7 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound7 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond7 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond7 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 7 Label', text=' H B7 ', style=shape.labelup, location=location.absolute, color=bullColor7, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #7 END////// divergence Lookback period #8// get pivotsplFound8 = na(ta.pivotlow(osc, lbL8, lbR)) ? false : true_inRange8(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL8 = osc[lbR] > ta.valuewhen(plFound8, osc[lbR], 1) and _inRange8(plFound8[1])// Price: Lower LowpriceLL8 = low[lbR] < ta.valuewhen(plFound8, low[lbR], 1)bullCond8 = plotBull and priceLL8 and oscHL8 and plFound8 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound8 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond8 ? bullColor : noneColor)plotshape(bullCond8 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 8 Label', text=' B8 ', style=shape.labelup, location=location.absolute, color=bullColor8, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL8 = osc[lbR] < ta.valuewhen(plFound8, osc[lbR], 1) and _inRange8(plFound8[1])// Price: Higher LowpriceHL8 = low[lbR] > ta.valuewhen(plFound8, low[lbR], 1)hiddenBullCond8 = plotHiddenBull and priceHL8 and oscLL8 and plFound8 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound8 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond8 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond8 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 8 Label', text=' H B8 ', style=shape.labelup, location=location.absolute, color=bullColor8, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #8 END////// divergence Lookback period #9// get pivotsplFound9 = na(ta.pivotlow(osc, lbL9, lbR)) ? false : true_inRange9(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL9 = osc[lbR] > ta.valuewhen(plFound9, osc[lbR], 1) and _inRange9(plFound9[1])// Price: Lower LowpriceLL9 = low[lbR] < ta.valuewhen(plFound9, low[lbR], 1)bullCond9 = plotBull and priceLL9 and oscHL9 and plFound9 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound9 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond9 ? bullColor : noneColor)plotshape(bullCond9 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 9 Label', text=' B9 ', style=shape.labelup, location=location.absolute, color=bullColor9, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL9 = osc[lbR] < ta.valuewhen(plFound9, osc[lbR], 1) and _inRange9(plFound9[1])// Price: Higher LowpriceHL9 = low[lbR] > ta.valuewhen(plFound9, low[lbR], 1)hiddenBullCond9 = plotHiddenBull and priceHL9 and oscLL9 and plFound9 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound9 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond9 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond9 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 9 Label', text=' H B9 ', style=shape.labelup, location=location.absolute, color=bullColor9, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #9 END////// divergence Lookback period #10// get pivotsplFound10 = na(ta.pivotlow(osc, lbL10, lbR)) ? false : true_inRange10(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL10 = osc[lbR] > ta.valuewhen(plFound10, osc[lbR], 1) and _inRange10(plFound10[1])// Price: Lower LowpriceLL10 = low[lbR] < ta.valuewhen(plFound10, low[lbR], 1)bullCond10 = plotBull and priceLL10 and oscHL10 and plFound10 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound10 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond10 ? bullColor : noneColor)plotshape(bullCond10 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 10 Label', text=' B10 ', style=shape.labelup, location=location.absolute, color=bullColor10, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL10 = osc[lbR] < ta.valuewhen(plFound10, osc[lbR], 1) and _inRange10(plFound10[1])// Price: Higher LowpriceHL10 = low[lbR] > ta.valuewhen(plFound10, low[lbR], 1)hiddenBullCond10 = plotHiddenBull and priceHL10 and oscLL10 and plFound10 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound10 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond10 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond10 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 10 Label', text=' H B10 ', style=shape.labelup, location=location.absolute, color=bullColor10, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #10 END////// divergence Lookback period #11// get pivotsplFound11 = na(ta.pivotlow(osc, lbL11, lbR)) ? false : true_inRange11(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL11 = osc[lbR] > ta.valuewhen(plFound11, osc[lbR], 1) and _inRange11(plFound11[1])// Price: Lower LowpriceLL11 = low[lbR] < ta.valuewhen(plFound11, low[lbR], 1)bullCond11 = plotBull and priceLL11 and oscHL11 and plFound11 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound11 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond11 ? bullColor : noneColor)plotshape(bullCond11 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 11 Label', text=' B11 ', style=shape.labelup, location=location.absolute, color=bullColor11, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL11 = osc[lbR] < ta.valuewhen(plFound11, osc[lbR], 1) and _inRange11(plFound11[1])// Price: Higher LowpriceHL11 = low[lbR] > ta.valuewhen(plFound11, low[lbR], 1)hiddenBullCond11 = plotHiddenBull and priceHL11 and oscLL11 and plFound11 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound11 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond11 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond11 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 11 Label', text=' H B11 ', style=shape.labelup, location=location.absolute, color=bullColor11, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #11 END////// divergence Lookback period #12// get pivotsplFound12 = na(ta.pivotlow(osc, lbL12, lbR)) ? false : true_inRange12(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL12 = osc[lbR] > ta.valuewhen(plFound12, osc[lbR], 1) and _inRange12(plFound12[1])// Price: Lower LowpriceLL12 = low[lbR] < ta.valuewhen(plFound12, low[lbR], 1)bullCond12 = plotBull and priceLL12 and oscHL12 and plFound12 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound12 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond12 ? bullColor : noneColor)plotshape(bullCond12 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 12 Label', text=' B12 ', style=shape.labelup, location=location.absolute, color=bullColor12, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL12 = osc[lbR] < ta.valuewhen(plFound12, osc[lbR], 1) and _inRange12(plFound12[1])// Price: Higher LowpriceHL12 = low[lbR] > ta.valuewhen(plFound12, low[lbR], 1)hiddenBullCond12 = plotHiddenBull and priceHL12 and oscLL12 and plFound12 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound12 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond12 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond12 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 12 Label', text=' H B12 ', style=shape.labelup, location=location.absolute, color=bullColor12, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #12 END////// divergence Lookback period #13// get pivotsplFound13 = na(ta.pivotlow(osc, lbL13, lbR)) ? false : true_inRange13(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL13 = osc[lbR] > ta.valuewhen(plFound13, osc[lbR], 1) and _inRange13(plFound13[1])// Price: Lower LowpriceLL13 = low[lbR] < ta.valuewhen(plFound13, low[lbR], 1)bullCond13 = plotBull and priceLL13 and oscHL13 and plFound13 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound13 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond13 ? bullColor : noneColor)plotshape(bullCond13 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 13 Label', text=' B13 ', style=shape.labelup, location=location.absolute, color=bullColor13, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL13 = osc[lbR] < ta.valuewhen(plFound13, osc[lbR], 1) and _inRange13(plFound13[1])// Price: Higher LowpriceHL13 = low[lbR] > ta.valuewhen(plFound13, low[lbR], 1)hiddenBullCond13 = plotHiddenBull and priceHL13 and oscLL13 and plFound13 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound13 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond13 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond13 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 13 Label', text=' H B13 ', style=shape.labelup, location=location.absolute, color=bullColor13, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #13 END////// divergence Lookback period #14// get pivotsplFound14 = na(ta.pivotlow(osc, lbL14, lbR)) ? false : true_inRange14(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL14 = osc[lbR] > ta.valuewhen(plFound14, osc[lbR], 1) and _inRange14(plFound14[1])// Price: Lower LowpriceLL14 = low[lbR] < ta.valuewhen(plFound14, low[lbR], 1)bullCond14 = plotBull and priceLL14 and oscHL14 and plFound14 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound14 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond14 ? bullColor : noneColor)plotshape(bullCond14 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 14 Label', text=' B14 ', style=shape.labelup, location=location.absolute, color=bullColor14, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL14 = osc[lbR] < ta.valuewhen(plFound14, osc[lbR], 1) and _inRange14(plFound14[1])// Price: Higher LowpriceHL14 = low[lbR] > ta.valuewhen(plFound14, low[lbR], 1)hiddenBullCond14 = plotHiddenBull and priceHL14 and oscLL14 and plFound14 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound14 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond14 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond14 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 14 Label', text=' H B14 ', style=shape.labelup, location=location.absolute, color=bullColor14, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #14 END////// divergence Lookback period #15// get pivotsplFound15 = na(ta.pivotlow(osc, lbL15, lbR)) ? false : true_inRange15(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL15 = osc[lbR] > ta.valuewhen(plFound15, osc[lbR], 1) and _inRange15(plFound15[1])// Price: Lower LowpriceLL15 = low[lbR] < ta.valuewhen(plFound15, low[lbR], 1)bullCond15 = plotBull and priceLL15 and oscHL15 and plFound15 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound15 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond15 ? bullColor : noneColor)plotshape(bullCond15 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 15 Label', text=' B15 ', style=shape.labelup, location=location.absolute, color=bullColor15, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL15 = osc[lbR] < ta.valuewhen(plFound15, osc[lbR], 1) and _inRange15(plFound15[1])// Price: Higher LowpriceHL15 = low[lbR] > ta.valuewhen(plFound15, low[lbR], 1)hiddenBullCond15 = plotHiddenBull and priceHL15 and oscLL15 and plFound15 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound15 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond15 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond15 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 15 Label', text=' H B15 ', style=shape.labelup, location=location.absolute, color=bullColor15, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #15 END////// divergence Lookback period #16// get pivotsplFound16 = na(ta.pivotlow(osc, lbL16, lbR)) ? false : true_inRange16(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL16 = osc[lbR] > ta.valuewhen(plFound16, osc[lbR], 1) and _inRange16(plFound16[1])// Price: Lower LowpriceLL16 = low[lbR] < ta.valuewhen(plFound16, low[lbR], 1)bullCond16 = plotBull and priceLL16 and oscHL16 and plFound16 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound16 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond16 ? bullColor : noneColor)plotshape(bullCond16 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 16 Label', text=' B16 ', style=shape.labelup, location=location.absolute, color=bullColor16, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL16 = osc[lbR] < ta.valuewhen(plFound16, osc[lbR], 1) and _inRange16(plFound16[1])// Price: Higher LowpriceHL16 = low[lbR] > ta.valuewhen(plFound16, low[lbR], 1)hiddenBullCond16 = plotHiddenBull and priceHL16 and oscLL16 and plFound16 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound16 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond16 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond16 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 16 Label', text=' H B16 ', style=shape.labelup, location=location.absolute, color=bullColor16, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #16 END////// divergence Lookback period #17// get pivotsplFound17 = na(ta.pivotlow(osc, lbL17, lbR)) ? false : true_inRange17(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL17 = osc[lbR] > ta.valuewhen(plFound17, osc[lbR], 1) and _inRange17(plFound17[1])// Price: Lower LowpriceLL17 = low[lbR] < ta.valuewhen(plFound17, low[lbR], 1)bullCond17 = plotBull and priceLL17 and oscHL17 and plFound17 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound17 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond17 ? bullColor : noneColor)plotshape(bullCond17 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 17 Label', text=' B17 ', style=shape.labelup, location=location.absolute, color=bullColor17, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL17 = osc[lbR] < ta.valuewhen(plFound17, osc[lbR], 1) and _inRange17(plFound17[1])// Price: Higher LowpriceHL17 = low[lbR] > ta.valuewhen(plFound17, low[lbR], 1)hiddenBullCond17 = plotHiddenBull and priceHL17 and oscLL17 and plFound17 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound17 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond17 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond17 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 17 Label', text=' H B17 ', style=shape.labelup, location=location.absolute, color=bullColor17, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #17 END////// divergence Lookback period #18// get pivotsplFound18 = na(ta.pivotlow(osc, lbL18, lbR)) ? false : true_inRange18(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL18 = osc[lbR] > ta.valuewhen(plFound18, osc[lbR], 1) and _inRange18(plFound18[1])// Price: Lower LowpriceLL18 = low[lbR] < ta.valuewhen(plFound18, low[lbR], 1)bullCond18 = plotBull and priceLL18 and oscHL18 and plFound18 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound18 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond18 ? bullColor : noneColor)plotshape(bullCond18 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 18 Label', text=' B18 ', style=shape.labelup, location=location.absolute, color=bullColor18, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL18 = osc[lbR] < ta.valuewhen(plFound18, osc[lbR], 1) and _inRange18(plFound18[1])// Price: Higher LowpriceHL18 = low[lbR] > ta.valuewhen(plFound18, low[lbR], 1)hiddenBullCond18 = plotHiddenBull and priceHL18 and oscLL18 and plFound18 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound18 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond18 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond18 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 18 Label', text=' H B18 ', style=shape.labelup, location=location.absolute, color=bullColor18, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #18 END////// divergence Lookback period #19// get pivotsplFound19 = na(ta.pivotlow(osc, lbL19, lbR)) ? false : true_inRange19(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL19 = osc[lbR] > ta.valuewhen(plFound19, osc[lbR], 1) and _inRange19(plFound19[1])// Price: Lower LowpriceLL19 = low[lbR] < ta.valuewhen(plFound19, low[lbR], 1)bullCond19 = plotBull and priceLL19 and oscHL19 and plFound19 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound19 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond19 ? bullColor : noneColor)plotshape(bullCond19 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 19 Label', text=' B19 ', style=shape.labelup, location=location.absolute, color=bullColor19, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL19 = osc[lbR] < ta.valuewhen(plFound19, osc[lbR], 1) and _inRange19(plFound19[1])// Price: Higher LowpriceHL19 = low[lbR] > ta.valuewhen(plFound19, low[lbR], 1)hiddenBullCond19 = plotHiddenBull and priceHL19 and oscLL19 and plFound19 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound19 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond19 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond19 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 19 Label', text=' H B19 ', style=shape.labelup, location=location.absolute, color=bullColor19, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #19 END////// divergence Lookback period #20// get pivotsplFound20 = na(ta.pivotlow(osc, lbL20, lbR)) ? false : true_inRange20(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL20 = osc[lbR] > ta.valuewhen(plFound20, osc[lbR], 1) and _inRange20(plFound20[1])// Price: Lower LowpriceLL20 = low[lbR] < ta.valuewhen(plFound20, low[lbR], 1)bullCond20 = plotBull and priceLL20 and oscHL20 and plFound20 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound20 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond20 ? bullColor : noneColor)plotshape(bullCond20 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 20 Label', text=' B20 ', style=shape.labelup, location=location.absolute, color=bullColor20, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL20 = osc[lbR] < ta.valuewhen(plFound20, osc[lbR], 1) and _inRange20(plFound20[1])// Price: Higher LowpriceHL20 = low[lbR] > ta.valuewhen(plFound20, low[lbR], 1)hiddenBullCond20 = plotHiddenBull and priceHL20 and oscLL20 and plFound20 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound20 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond20 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond20 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 20 Label', text=' H B20 ', style=shape.labelup, location=location.absolute, color=bullColor20, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #20 END////// divergence Lookback period #21// get pivotsplFound21 = na(ta.pivotlow(osc, lbL21, lbR)) ? false : true_inRange21(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL21 = osc[lbR] > ta.valuewhen(plFound21, osc[lbR], 1) and _inRange21(plFound21[1])// Price: Lower LowpriceLL21 = low[lbR] < ta.valuewhen(plFound21, low[lbR], 1)bullCond21 = plotBull and priceLL21 and oscHL21 and plFound21 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound21 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond21 ? bullColor : noneColor)plotshape(bullCond21 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 21 Label', text=' B21 ', style=shape.labelup, location=location.absolute, color=bullColor21, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL21 = osc[lbR] < ta.valuewhen(plFound21, osc[lbR], 1) and _inRange21(plFound21[1])// Price: Higher LowpriceHL21 = low[lbR] > ta.valuewhen(plFound21, low[lbR], 1)hiddenBullCond21 = plotHiddenBull and priceHL21 and oscLL21 and plFound21 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound21 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond21 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond21 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 21 Label', text=' H B21 ', style=shape.labelup, location=location.absolute, color=bullColor21, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #21 END////// divergence Lookback period #22// get pivotsplFound22 = na(ta.pivotlow(osc, lbL22, lbR)) ? false : true_inRange22(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL22 = osc[lbR] > ta.valuewhen(plFound22, osc[lbR], 1) and _inRange22(plFound22[1])// Price: Lower LowpriceLL22 = low[lbR] < ta.valuewhen(plFound22, low[lbR], 1)bullCond22 = plotBull and priceLL22 and oscHL22 and plFound22 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound22 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond22 ? bullColor : noneColor)plotshape(bullCond22 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 22 Label', text=' B22 ', style=shape.labelup, location=location.absolute, color=bullColor22, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL22 = osc[lbR] < ta.valuewhen(plFound22, osc[lbR], 1) and _inRange22(plFound22[1])// Price: Higher LowpriceHL22 = low[lbR] > ta.valuewhen(plFound22, low[lbR], 1)hiddenBullCond22 = plotHiddenBull and priceHL22 and oscLL22 and plFound22 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound22 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond22 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond22 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 22 Label', text=' H B22 ', style=shape.labelup, location=location.absolute, color=bullColor22, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #22 END////// divergence Lookback period #23// get pivotsplFound23 = na(ta.pivotlow(osc, lbL23, lbR)) ? false : true_inRange23(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL23 = osc[lbR] > ta.valuewhen(plFound23, osc[lbR], 1) and _inRange23(plFound23[1])// Price: Lower LowpriceLL23 = low[lbR] < ta.valuewhen(plFound23, low[lbR], 1)bullCond23 = plotBull and priceLL23 and oscHL23 and plFound23 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound23 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond23 ? bullColor : noneColor)plotshape(bullCond23 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 23 Label', text=' B23 ', style=shape.labelup, location=location.absolute, color=bullColor23, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL23 = osc[lbR] < ta.valuewhen(plFound23, osc[lbR], 1) and _inRange23(plFound23[1])// Price: Higher LowpriceHL23 = low[lbR] > ta.valuewhen(plFound23, low[lbR], 1)hiddenBullCond23 = plotHiddenBull and priceHL23 and oscLL23 and plFound23 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound23 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond23 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond23 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 23 Label', text=' H B23 ', style=shape.labelup, location=location.absolute, color=bullColor23, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #23 END////// divergence Lookback period #24// get pivotsplFound24 = na(ta.pivotlow(osc, lbL24, lbR)) ? false : true_inRange24(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL24 = osc[lbR] > ta.valuewhen(plFound24, osc[lbR], 1) and _inRange24(plFound24[1])// Price: Lower LowpriceLL24 = low[lbR] < ta.valuewhen(plFound24, low[lbR], 1)bullCond24 = plotBull and priceLL24 and oscHL24 and plFound24 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound24 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond24 ? bullColor : noneColor)plotshape(bullCond24 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 24 Label', text=' B24 ', style=shape.labelup, location=location.absolute, color=bullColor24, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL24 = osc[lbR] < ta.valuewhen(plFound24, osc[lbR], 1) and _inRange24(plFound24[1])// Price: Higher LowpriceHL24 = low[lbR] > ta.valuewhen(plFound24, low[lbR], 1)hiddenBullCond24 = plotHiddenBull and priceHL24 and oscLL24 and plFound24 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound24 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond24 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond24 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 24 Label', text=' H B24 ', style=shape.labelup, location=location.absolute, color=bullColor24, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #24 END////// divergence Lookback period #25// get pivotsplFound25 = na(ta.pivotlow(osc, lbL25, lbR)) ? false : true_inRange25(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL25 = osc[lbR] > ta.valuewhen(plFound25, osc[lbR], 1) and _inRange25(plFound25[1])// Price: Lower LowpriceLL25 = low[lbR] < ta.valuewhen(plFound25, low[lbR], 1)bullCond25 = plotBull and priceLL25 and oscHL25 and plFound25 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound25 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond25 ? bullColor : noneColor)plotshape(bullCond25 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 25 Label', text=' B25 ', style=shape.labelup, location=location.absolute, color=bullColor25, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL25 = osc[lbR] < ta.valuewhen(plFound25, osc[lbR], 1) and _inRange25(plFound25[1])// Price: Higher LowpriceHL25 = low[lbR] > ta.valuewhen(plFound25, low[lbR], 1)hiddenBullCond25 = plotHiddenBull and priceHL25 and oscLL25 and plFound25 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound25 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond25 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond25 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 25 Label', text=' H B25 ', style=shape.labelup, location=location.absolute, color=bullColor25, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #25 END////// divergence Lookback period #26// get pivotsplFound26 = na(ta.pivotlow(osc, lbL26, lbR)) ? false : true_inRange26(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL26 = osc[lbR] > ta.valuewhen(plFound26, osc[lbR], 1) and _inRange26(plFound26[1])// Price: Lower LowpriceLL26 = low[lbR] < ta.valuewhen(plFound26, low[lbR], 1)bullCond26 = plotBull and priceLL26 and oscHL26 and plFound26 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound26 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 26', linewidth=2, color=bullCond26 ? bullColor : noneColor)plotshape(bullCond26 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 26 Label', text=' B26 ', style=shape.labelup, location=location.absolute, color=bullColor26, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL26 = osc[lbR] < ta.valuewhen(plFound26, osc[lbR], 1) and _inRange26(plFound26[1])// Price: Higher LowpriceHL26 = low[lbR] > ta.valuewhen(plFound26, low[lbR], 1)hiddenBullCond26 = plotHiddenBull and priceHL26 and oscLL26 and plFound26 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound26 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 26', linewidth=2, color=hiddenBullCond26 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond26 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 26 Label', text=' H B26 ', style=shape.labelup, location=location.absolute, color=bullColor26, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #26 END////// divergence Lookback period #27// get pivotsplFound27 = na(ta.pivotlow(osc, lbL27, lbR)) ? false : true_inRange27(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL27 = osc[lbR] > ta.valuewhen(plFound27, osc[lbR], 1) and _inRange27(plFound27[1])// Price: Lower LowpriceLL27 = low[lbR] < ta.valuewhen(plFound27, low[lbR], 1)bullCond27 = plotBull and priceLL27 and oscHL27 and plFound27 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound27 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 27', linewidth=2, color=bullCond27 ? bullColor : noneColor)plotshape(bullCond27 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 27 Label ', text=' B27 ', style=shape.labelup, location=location.absolute, color=bullColor27, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL27 = osc[lbR] < ta.valuewhen(plFound27, osc[lbR], 1) and _inRange27(plFound27[1])// Price: Higher LowpriceHL27 = low[lbR] > ta.valuewhen(plFound27, low[lbR], 1)hiddenBullCond27 = plotHiddenBull and priceHL27 and oscLL27 and plFound27 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound27 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 27', linewidth=2, color=hiddenBullCond27 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond27 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 27 Label', text=' H B27 ', style=shape.labelup, location=location.absolute, color=bullColor27, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #27 END////// divergence Lookback period #28// get pivotsplFound28 = na(ta.pivotlow(osc, lbL28, lbR)) ? false : true_inRange28(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL28 = osc[lbR] > ta.valuewhen(plFound28, osc[lbR], 1) and _inRange28(plFound28[1])// Price: Lower LowpriceLL28 = low[lbR] < ta.valuewhen(plFound28, low[lbR], 1)bullCond28 = plotBull and priceLL28 and oscHL28 and plFound28 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound28 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 28', linewidth=2, color=bullCond28 ? bullColor : noneColor)plotshape(bullCond28 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 28 Label ', text=' B28 ', style=shape.labelup, location=location.absolute, color=bullColor28, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL28 = osc[lbR] < ta.valuewhen(plFound28, osc[lbR], 1) and _inRange28(plFound28[1])// Price: Higher LowpriceHL28 = low[lbR] > ta.valuewhen(plFound28, low[lbR], 1)hiddenBullCond28 = plotHiddenBull and priceHL28 and oscLL28 and plFound28 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound28 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 28', linewidth=2, color=hiddenBullCond28 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond28 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 28 Label', text=' H B28 ', style=shape.labelup, location=location.absolute, color=bullColor28, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #28 END////// divergence Lookback period #29// get pivotsplFound29 = na(ta.pivotlow(osc, lbL29, lbR)) ? false : true_inRange29(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL29 = osc[lbR] > ta.valuewhen(plFound29, osc[lbR], 1) and _inRange29(plFound29[1])// Price: Lower LowpriceLL29 = low[lbR] < ta.valuewhen(plFound29, low[lbR], 1)bullCond29 = plotBull and priceLL29 and oscHL29 and plFound29 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound29 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 29', linewidth=2, color=bullCond29 ? bullColor : noneColor)plotshape(bullCond29 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 29 Label ', text=' B29 ', style=shape.labelup, location=location.absolute, color=bullColor29, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL29 = osc[lbR] < ta.valuewhen(plFound29, osc[lbR], 1) and _inRange29(plFound29[1])// Price: Higher LowpriceHL29 = low[lbR] > ta.valuewhen(plFound29, low[lbR], 1)hiddenBullCond29 = plotHiddenBull and priceHL29 and oscLL29 and plFound29 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound29 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 29', linewidth=2, color=hiddenBullCond29 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond29 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 29 Label', text=' H B29 ', style=shape.labelup, location=location.absolute, color=bullColor29, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #29 END////// divergence Lookback period #30// get pivotsplFound30 = na(ta.pivotlow(osc, lbL30, lbR)) ? false : true_inRange30(cond) =>    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL30 = osc[lbR] > ta.valuewhen(plFound30, osc[lbR], 1) and _inRange30(plFound30[1])// Price: Lower LowpriceLL30 = low[lbR] < ta.valuewhen(plFound30, low[lbR], 1)bullCond30 = plotBull and priceLL30 and oscHL30 and plFound30 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound30 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 30', linewidth=2, color=bullCond30 ? bullColor : noneColor)plotshape(bullCond30 ? osc[lbR] : na, offset=-lbR, title='Regular Bullish 30 Label ', text=' B30 ', style=shape.labelup, location=location.absolute, color=bullColor30, textcolor=textColor)//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL30 = osc[lbR] < ta.valuewhen(plFound30, osc[lbR], 1) and _inRange30(plFound30[1])// Price: Higher LowpriceHL30 = low[lbR] > ta.valuewhen(plFound30, low[lbR], 1)hiddenBullCond30 = plotHiddenBull and priceHL30 and oscLL30 and plFound30 and RSIwasBelowOS and isWithinLongRanges and not enableonlyOneLB//plot(plFound30 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 30', linewidth=2, color=hiddenBullCond30 ? hiddenBullColor : noneColor)plotshape(hiddenBullCond30 ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish 30 Label', text=' H B30 ', style=shape.labelup, location=location.absolute, color=bullColor30, textcolor=textColor)//------------------------------------------------------------------------------////// divergence Lookback period #30 END// combine divergence alerts intwo bullish and hiddencombibullCond = (bullCond1 or bullCond2 or bullCond3 or bullCond4 or bullCond5 or bullCond6 or bullCond7 or bullCond8 or bullCond9 or bullCond10 or bullCond11 or bullCond12 or bullCond13 or bullCond14 or bullCond15 or bullCond16 or bullCond17 or bullCond18 or bullCond19 or bullCond20 or bullCond21 or bullCond22 or bullCond23 or bullCond24 or bullCond25 or bullCond26 or bullCond27 or bullCond28 or bullCond29 or bullCond30)combihiddenBullCond = (hiddenBullCond1 or hiddenBullCond2 or hiddenBullCond3 or hiddenBullCond4 or hiddenBullCond5 or hiddenBullCond6 or hiddenBullCond7 or hiddenBullCond8 or hiddenBullCond9 or hiddenBullCond10 or hiddenBullCond11 or hiddenBullCond12 or hiddenBullCond13 or hiddenBullCond14 or hiddenBullCond15 or hiddenBullCond16 or hiddenBullCond17 or hiddenBullCond18 or hiddenBullCond19 or hiddenBullCond20 or hiddenBullCond21 or hiddenBullCond22 or hiddenBullCond23 or hiddenBullCond24 or hiddenBullCond25 or hiddenBullCond26 or hiddenBullCond27 or hiddenBullCond28 or hiddenBullCond29 or hiddenBullCond30)///////////////////////// Delays// wait for a Oscillator and Oscillator EMA crossoscCross = ((1 < (osc - oscema)) and (ta.barssince(combihiddenBullCond or combibullCond) <= oscCrosslookback) ) or not enableOscCross// wait for price to go above emaEmaIsBroken = (ta.ema(src, WaitForEmaBreakLen) < close) or not enableWaitForEmaBreak///////////// check if price bounced before the alertpriceBounced = priceBounceNeeded < (ta.highest(high, 1) - ta.lowest(low, priceBounceNeededLbL)) or not enablepriceBounceNeededdelaysEnabled = enablepriceBounceNeeded or enableOscCross or enableWaitForEmaBreakDelayState = oscCross and EmaIsBroken and priceBounced// dirty workaround to dont reprint the final hidden bull alertHiddenBullAndBounce0 = DelayState and (ta.barssince(combihiddenBullCond) == 0) HiddenBullAndBounce1 = DelayState and (ta.barssince(combihiddenBullCond) == 1) and not (ta.barssince(HiddenBullAndBounce0) < 1)HiddenBullAndBounce2 = DelayState and (ta.barssince(combihiddenBullCond) == 2) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0) < 2)HiddenBullAndBounce3 = DelayState and (ta.barssince(combihiddenBullCond) == 3) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2) < 3)HiddenBullAndBounce4 = DelayState and (ta.barssince(combihiddenBullCond) == 4) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2 or HiddenBullAndBounce3) < 5)HiddenBullAndBounce5 = DelayState and (ta.barssince(combihiddenBullCond) == 5) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2 or HiddenBullAndBounce3 or HiddenBullAndBounce4) < 6)HiddenBullAndBounce6 = DelayState and (ta.barssince(combihiddenBullCond) == 6) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2 or HiddenBullAndBounce3 or HiddenBullAndBounce4 or HiddenBullAndBounce5) < 7)HiddenBullAndBounce7 = DelayState and (ta.barssince(combihiddenBullCond) == 7) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2 or HiddenBullAndBounce3 or HiddenBullAndBounce4 or HiddenBullAndBounce5 or HiddenBullAndBounce6) < 8)HiddenBullAndBounce8 = DelayState and (ta.barssince(combihiddenBullCond) == 8) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2 or HiddenBullAndBounce3 or HiddenBullAndBounce4 or HiddenBullAndBounce5 or HiddenBullAndBounce6 or HiddenBullAndBounce7) < 9)HiddenBullAndBounce9 = DelayState and (ta.barssince(combihiddenBullCond) == 9) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2 or HiddenBullAndBounce3 or HiddenBullAndBounce4 or HiddenBullAndBounce5 or HiddenBullAndBounce6 or HiddenBullAndBounce7 or HiddenBullAndBounce8) < 10)HiddenBullAndBounce10 = DelayState and (ta.barssince(combihiddenBullCond) == 10) and not (ta.barssince(HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2 or HiddenBullAndBounce3 or HiddenBullAndBounce4 or HiddenBullAndBounce5 or HiddenBullAndBounce6 or HiddenBullAndBounce7 or HiddenBullAndBounce8 or HiddenBullAndBounce9) < 11)FinalHiddenBullDelayAlert = delaysEnabled and (HiddenBullAndBounce1 or HiddenBullAndBounce0 or HiddenBullAndBounce2 or HiddenBullAndBounce3 or HiddenBullAndBounce4 or HiddenBullAndBounce5 or HiddenBullAndBounce6 or HiddenBullAndBounce7 or HiddenBullAndBounce8 or HiddenBullAndBounce9 or HiddenBullAndBounce10)FinalHiddenBullAlert = falseFinalHiddenBullAlert2 = falseif delaysEnabled    FinalHiddenBullAlert := FinalHiddenBullDelayAlert    FinalHiddenBullAlert2 := falseif not delaysEnabled    FinalHiddenBullAlert := false    FinalHiddenBullAlert2 := combihiddenBullCond// dirty workaround to dont reprint the final bull alertBullAndBounce0 = DelayState and (ta.barssince(combibullCond) == 0) BullAndBounce1 = DelayState and (ta.barssince(combibullCond) == 1) and not (ta.barssince(BullAndBounce0) < 2)BullAndBounce2 = DelayState and (ta.barssince(combibullCond) == 2) and not (ta.barssince(BullAndBounce1 or BullAndBounce0) < 3)BullAndBounce3 = DelayState and (ta.barssince(combibullCond) == 3) and not (ta.barssince(BullAndBounce1 or BullAndBounce0 or BullAndBounce2) < 4)BullAndBounce4 = DelayState and (ta.barssince(combibullCond) == 4) and not (ta.barssince(BullAndBounce1 or BullAndBounce0 or BullAndBounce2 or BullAndBounce3) < 5)BullAndBounce5 = DelayState and (ta.barssince(combibullCond) == 5) and not (ta.barssince(BullAndBounce1 or BullAndBounce0 or BullAndBounce2 or BullAndBounce3 or BullAndBounce4) < 6)BullAndBounce6 = DelayState and (ta.barssince(combibullCond) == 6) and not (ta.barssince(BullAndBounce1 or BullAndBounce0 or BullAndBounce2 or BullAndBounce3 or BullAndBounce4 or BullAndBounce5) < 7)BullAndBounce7 = DelayState and (ta.barssince(combibullCond) == 7) and not (ta.barssince(BullAndBounce1 or BullAndBounce0 or BullAndBounce2 or BullAndBounce3 or BullAndBounce4 or BullAndBounce5 or BullAndBounce6) < 8)BullAndBounce8 = DelayState and (ta.barssince(combibullCond) == 8) and not (ta.barssince(BullAndBounce1 or BullAndBounce0 or BullAndBounce2 or BullAndBounce3 or BullAndBounce4 or BullAndBounce5 or BullAndBounce6 or BullAndBounce7) < 9)BullAndBounce9 = DelayState and (ta.barssince(combibullCond) == 9) and not (ta.barssince(BullAndBounce1 or BullAndBounce0 or BullAndBounce2 or BullAndBounce3 or BullAndBounce4 or BullAndBounce5 or BullAndBounce6 or BullAndBounce7 or BullAndBounce8) < 10)BullAndBounce10 = DelayState and (ta.barssince(combibullCond) == 10) and not (ta.barssince(BullAndBounce1 or BullAndBounce0 or BullAndBounce2 or BullAndBounce3 or BullAndBounce4 or BullAndBounce5 or BullAndBounce6 or BullAndBounce7 or BullAndBounce8 or BullAndBounce9) < 11)FinalBullDelayAlert = delaysEnabled and (BullAndBounce1 or BullAndBounce0 or BullAndBounce2 or BullAndBounce3 or BullAndBounce4 or BullAndBounce5 or BullAndBounce6 or BullAndBounce7 or BullAndBounce8 or BullAndBounce9 or BullAndBounce10)FinalBullAlert = falseFinalBullAlert2 = falseif delaysEnabled    FinalBullAlert := FinalBullDelayAlert    FinalBullAlert2 := falseif not delaysEnabled    FinalBullAlert := false    FinalBullAlert2 := combibullCond///////////// check if price bounced before the alert END// plot delay buyplotshape(FinalBullAlert ? osc : na, offset=0, title='Buy ', text=" buy ", style=shape.labelup, location=location.absolute, color=color.lime, textcolor=textColor)////////////////// Stop Loss// Stop lossenableSL =  input.bool(true, title='enable Stop Loss', group='══════════ Stop Loss Settings ══════════')whichSL =  input.string(defval='use the low as SL', title='SL based on static % or based on the low', options=['use the low as SL', 'use the static % as SL'], group='══════════ Stop Loss Settings ══════════')whichOffset = input.string(defval='use % as offset', title='choose offset from the low', options=['use $ as offset', 'use % as offset'], group='Stop Loss at the low')lowPBuffer = input.float(0.35, title='SL Offset from the Low in %', group='Stop Loss at the low') / 100lowDBuffer = input.float(100, title='SL Offset from the Low in $', group='Stop Loss at the low')SlLowLookback = input.int(title='SL lookback for Low', defval=5, minval=1, maxval=50, group='Stop Loss at the low')longSlLow = float(na)if whichOffset == "use % as offset" and whichSL == "use the low as SL" and enableSL    longSlLow := ta.lowest(low, SlLowLookback) * (1 - lowPBuffer)if whichOffset == "use $ as offset" and whichSL == "use the low as SL" and enableSL    longSlLow := ta.lowest(low, SlLowLookback) - lowDBuffer//plot(longSlLow, title="stoploss", color=color.new(#00bcd4, 0))// long settings - 🔥 uncomment the 6 lines below to disable the alerts and enable the backtester longStopLoss = input.float(0.5, title='Stop Loss in %', group='static % Stop Loss', inline='Input 1') / 100/////// Take profitlongTakeProfit1 = input.float(2, title='Take Profit in %', group='Take Profit', inline='Input 1') / 100//longTakeProfit2 = input.float(2, title='25% Take Profit in %', group='Take Profit', inline='Input 1') / 100//longTakeProfit3 = input.float(2, title='25% Take Profit in %', group='Take Profit', inline='Input 1') / 100//longTakeProfit4 = input.float(2, title='25% Take Profit in %', group='Take Profit', inline='Input 1') / 100////////////////// SL TP END/////////////////// alerts ///////////////ver final alert variableveryFinalAlert = FinalHiddenBullAlert2 or FinalHiddenBullAlert or FinalBullAlert or FinalBullAlert2/////////////////// alerts selectalertFreq = input.string(defval='once per bar close', title='Alert Options', options=['once per bar', 'once per bar close', 'all'], group='═══════════ alert settings ═══════════')BuyAlertMessage = input.string(defval="Bullish Divergence detected, put your SL @", title='Buy Alert Message',  group='═══════════ alert settings ═══════════')enableSlMessage =  input.bool(true, title='enable Stop Loss Value at the end of "buy Alert message"', group='═══════════ alert settings ═══════════')AfterSLMessage = input.string(defval="", title='Buy Alert message after SL Value',  group='═══════════ alert settings ═══════════')alertFreq = selectalertFreq == "once per bar" ? alert.freq_once_per_bar : selectalertFreq == "once per bar close" ? alert.freq_once_per_bar_close : selectalertFreq == "all" ? alert.freq_all : naif not enableSlMessage and veryFinalAlert    alert(str.tostring(BuyAlertMessage), alertFreq)if enableSlMessage and veryFinalAlert    alert(str.tostring(BuyAlertMessage) + str.tostring(longSlLow) + str.tostring(AfterSLMessage), alertFreq)if enableSlMessage     alert(str.tostring(BuyAlertMessage) + str.tostring(longSlLow) + str.tostring(AfterSLMessage), alertFreq)alertcondition(veryFinalAlert, title='Bullish divergence', message='Bull Div {{ticker}}')////////////////// Backtester ////////////////// Backtester input stuff// Backtesting Range settings - 🔥 uncomment the 6 lines below to disable the alerts and enable the backtester //startDate = input.int(title='Start Date', defval=1, minval=1, maxval=31, group='Backtesting range')//startMonth = input.int(title='Start Month', defval=1, minval=1, maxval=12, group='Backtesting range')//startYear = input.int(title='Start Year', defval=2016, minval=1800, maxval=2100, group='Backtesting range')//endDate = input.int(title='End Date', defval=1, minval=1, maxval=31, group='Backtesting range')//endMonth = input.int(title='End Month', defval=1, minval=1, maxval=12, group='Backtesting range')//endYear = input.int(title='End Year', defval=2040, minval=1800, maxval=2100, group='Backtesting range') ////////////////// Backtester // 🔥 uncomment the all lines below for the backtester and revert for alertsshortTrading = falselongTrading = plotBull or plotHiddenBulllongTP1 = strategy.position_size > 0 ? strategy.position_avg_price * (1 + longTakeProfit1) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - longTakeProfit1) : na//longTP2 = strategy.position_size > 0 ? strategy.position_avg_price * (1 + longTakeProfit2) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - longTakeProfit2) : na//longTP3 = strategy.position_size > 0 ? strategy.position_avg_price * (1 + longTakeProfit3) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - longTakeProfit3) : na//longTP4 = strategy.position_size > 0 ? strategy.position_avg_price * (1 + longTakeProfit4) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - longTakeProfit4) : nalongSL = strategy.position_size > 0 ? strategy.position_avg_price * (1 - longStopLoss) : strategy.position_size < 0 ? strategy.position_avg_price * (1 + longStopLoss) : nastrategy.risk.allow_entry_in(longTrading == true and shortTrading == true ? strategy.direction.all : longTrading == true ? strategy.direction.long : shortTrading == true ? strategy.direction.short : na)strategy.entry('Bull', strategy.long, comment='B Long', when=FinalBullAlert or FinalBullAlert2)strategy.entry('Bull', strategy.long, comment='HB Long', when=FinalHiddenBullAlert2 or FinalHiddenBullAlert)// check which SL to useif enableSL and whichSL == 'use the static % as SL'    strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1, stop=longSL)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP2, stop=longSlLow)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP3, stop=longSlLow)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP4, stop=longSlLow)// get bars since last entry for the SL at low to workbarsSinceLastEntry()=>    strategy.opentrades > 0 ? (bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades-1)) : na    if enableSL and whichSL == 'use the low as SL' and ta.barssince(veryFinalAlert) < 2 and barsSinceLastEntry() < 2    strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1, stop=longSlLow)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP2, stop=longSlLow)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP3, stop=longSlLow)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP4, stop=longSlLow)if not enableSL    strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP2)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP3)//    strategy.exit(id='longTP-SL', qty_percent=25, from_entry='Bull', limit=longTP4)