Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Auto Fib Golden Pocket Band - Strategy with Buy Signals

A Pine Script v5 strategy built on Lowest (low, 400), Highest (high, 400) and EMA (120). It has 12 order rules, 6 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.05% commission. 32 settings; defaults include 0.236, Select Strong Band Fib Bear 0.382 and Pivot Look Back 400.

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 Auto Fib Golden Pocket Band - Strategy with Buy Signals repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did Auto Fib Golden Pocket Band - Strategy with Buy Signals do on BTCUSDT 1D with default settings?
−8.56%
From 26 Jan 2024 to 21 Oct 2026, over 1 closed trade, against +102.5% for buy and hold. A backtest, not investment advice.
Does Auto Fib Golden Pocket Band - Strategy with Buy Signals run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 1 before, 1 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does Auto Fib Golden Pocket Band - Strategy with Buy Signals use a stop loss?
Yes
strategy.exit sets a stop on line 238, 239, 245, 247.
Does Auto Fib Golden Pocket Band - Strategy with Buy Signals run in Zeal Terminal?
Yes
It compiles in 110 ms and runs 1,000 bars in 177 ms, in the browser.

BTCUSDT · 1D · default settings

  • Strong Trend
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (32)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$9,144$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Zeal Terminal's engine currently merges fill() calls that share a title, so it would draw 1 of this script's 2 fills; this page gives each call its own title to draw all of them.
Net profit
−8.56%
−$855.81
Buy and hold
+102.5%
same period
Closed trades
1
0 won · 1 lost
Profitable
0.0%
of closed trades
Profit factor
0.00
gross profit ÷ gross loss
Max drawdown
8.56%
−$855.81

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

Review

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

  • Likely bug

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

    Line 60 hard-codes 2 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

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

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

    Line 70 hard-codes 2 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

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

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

    Line 80 hard-codes 2 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

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

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

    Line 170 hard-codes 1 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

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

    ta.highest(high, 15) ignores the settings line 173

    Line 173 hard-codes 15 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.highest(high, 15)ta.highest(high, StrongBand_Lookback)
  • Likely bug

    ta.highest(StrongBand_current_Trend_EMA, 15) ignores the settings line 173

    Line 173 hard-codes 15 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.highest(StrongBand_current_Trend_EMA, 15)ta.highest(StrongBand_current_Trend_EMA, StrongBand_Lookback)
  • Likely bug

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

    Line 175 hard-codes 1 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

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

    ta.highest(high, 10) ignores the settings line 178

    Line 178 hard-codes 10 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.highest(high, 10)ta.highest(high, StrongBand_Lookback)
  • Likely bug

    ta.highest(MiddleBand_current_Trend_EMA, 10) ignores the settings line 178

    Line 178 hard-codes 10 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.highest(MiddleBand_current_Trend_EMA, 10)ta.highest(MiddleBand_current_Trend_EMA, StrongBand_Lookback)
  • Likely bug

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

    Line 180 hard-codes 1 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

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

    ta.highest(high, 20) ignores the settings line 183

    Line 183 hard-codes 20 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.highest(high, 20)ta.highest(high, StrongBand_Lookback)
  • Likely bug

    ta.highest(SidewaysBand_current_Trend_EMA, 15) ignores the settings line 183

    Line 183 hard-codes 15 where line 52 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.highest(SidewaysBand_current_Trend_EMA, 15)ta.highest(SidewaysBand_current_Trend_EMA, StrongBand_Lookback)
  • Likely bug

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

    Line 55 hard-codes 2 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 2)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

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

    Line 65 hard-codes 2 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 2)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

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

    Line 75 hard-codes 2 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 2)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

    ta.lowest(low, 1) ignores the settings line 151

    Line 151 hard-codes 1 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 1)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

    ta.lowest(StrongBand_current_Trend_EMA, 15) ignores the settings line 154

    Line 154 hard-codes 15 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(StrongBand_current_Trend_EMA, 15)ta.lowest(StrongBand_current_Trend_EMA, StrongBand_Lookback)
  • Likely bug

    ta.lowest(low, 15) ignores the settings line 154

    Line 154 hard-codes 15 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 15)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

    ta.lowest(low, 1) ignores the settings line 156

    Line 156 hard-codes 1 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 1)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

    ta.lowest(MiddleBand_current_Trend_EMA, 10) ignores the settings line 159

    Line 159 hard-codes 10 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(MiddleBand_current_Trend_EMA, 10)ta.lowest(MiddleBand_current_Trend_EMA, StrongBand_Lookback)
  • Likely bug

    ta.lowest(low, 10) ignores the settings line 159

    Line 159 hard-codes 10 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 10)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

    ta.lowest(low, 1) ignores the settings line 161

    Line 161 hard-codes 1 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 1)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

    ta.lowest(SidewaysBand_current_Trend_EMA, 150) ignores the settings line 164

    Line 164 hard-codes 150 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(SidewaysBand_current_Trend_EMA, 150)ta.lowest(SidewaysBand_current_Trend_EMA, StrongBand_Lookback)
  • Likely bug

    ta.lowest(low, 150) ignores the settings line 164

    Line 164 hard-codes 150 where line 53 uses “Pivot Look Back”. Changing those settings moves one band but not this one.

    ta.lowest(low, 150)ta.lowest(low, StrongBand_Lookback)
  • Likely bug

    ta.ema(low, 10) ignores the settings line 153

    Line 153 hard-codes 10 where line 84 uses “Fib EMA Length”. Changing those settings moves one band but not this one.

    ta.ema(low, 10)ta.ema(low, StrongBand_EmaLen)
  • Likely bug

    ta.ema(close, 20) ignores the settings line 158

    Line 158 hard-codes 20 where line 84 uses “Fib EMA Length”. Changing those settings moves one band but not this one.

    ta.ema(close, 20)ta.ema(close, StrongBand_EmaLen)
  • Likely bug

    ta.ema(low, 80) ignores the settings line 163

    Line 163 hard-codes 80 where line 84 uses “Fib EMA Length”. Changing those settings moves one band but not this one.

    ta.ema(low, 80)ta.ema(low, StrongBand_EmaLen)
  • Check

    4 settings do nothing

    “Alert Options”, “Buy Alert Message”, “enable Stop Loss Value at the end of "buy Alert message"”, “Buy Alert message after SL Value” are declared but never read.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    5 settings have no label

    In the settings dialog select_StrongBand_Fib_Bear (line 12), select_MiddleBand_Fib_Bull (line 17), select_MiddleBand_Fib_Bear (line 19), select_SidewaysBand_Fib_Bull (line 24), select_SidewaysBand_Fib_Bear (line 26) show an empty name. The labels on this page come from the variable names.

  • Note

    Uses an argument v6 removed

    when = on line 230, 231, 232, 233, 234, 235. 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
Strong Trend Levels
enable Upper Bullish Band . . . Fib LeveltrueboolisBelow_StrongBand_Bull longTrading line 51
0.236float · options [-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272]StrongBand_Bull_Fib_Price
enable Lower Bearish Band . . . Fib LevelfalseboolisBelow_StrongBand_Bear shortTrading line 56
Select Strong Band Fib Bear (no label in the script)0.382float · options [-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272]StrongBand_Bear_Fib_Price
Pivot Look Back400int · min 1StrongBand_Price_of_Low StrongBand_Price_of_High
Fib EMA Length120int · min 1StrongBand_Bull_EMA StrongBand_Bear_EMA
Regular Trend Levels
enable Middle Bullish Band . . . Fib LeveltrueboolisBelow_MiddleBand_Bull longTrading line 61
Select Middle Band Fib Bull (no label in the script)0.618float · options [-0.272, 0, 0.236, 0.382, 0.5, 0.6, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272]MiddleBand_Bull_Fib_Price
enable Middle Bearish Band . . . Fib LeveltrueboolisBelow_MiddleBand_Bear shortTrading line 66
Select Middle Band Fib Bear (no label in the script)0.382float · options [-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272]MiddleBand_Bear_Fib_Price
Pivot Look Back900int · min 1MiddleBand_Price_of_Low MiddleBand_Price_of_High
Fib EMA Length400int · min 1MiddleBand_Bull_EMA MiddleBand_Bear_EMA
Sideways Trend Levels
enable Lower Bullish Band . . . Fib LeveltrueboolisBelow_SidewaysBand_Bull longTrading line 71
Select Sideways Band Fib Bull (no label in the script)0.6float · options [-0.272, 0, 0.236, 0.382, 0.5, 0.6, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272]SidewaysBand_Bull_Fib_Price
enable Upper Bearish Band . . . Fib LeveltrueboolisBelow_SidewaysBand_Bear shortTrading line 76
Select Sideways Band Fib Bear (no label in the script)0.5float · options [-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272]SidewaysBand_Bear_Fib_Price
Pivot Look Back4000int · min 1SidewaysBand_Price_of_Low SidewaysBand_Price_of_High
Fib EMA Length150int · min 1SidewaysBand_Bull_EMA SidewaysBand_Bear_EMA
Stop Loss Settings
enable Stop Losstrueboolexit longTP-SL exit shortTP-SL exit longTP-SL exit shortTP-SL exit longTP-SL exit shortTP-SL line 199 line 202 line 237 line 244 line 246 line 248
SL based on static % or based on the low/highlow/high as SLstring · options ['low/high as SL', 'static % as SL']exit longTP-SL exit shortTP-SL exit longTP-SL exit shortTP-SL line 199 line 202 line 237 line 244 line 246
Stop Loss at the low/high
choose offset from the low/high% as offsetstring · options ['$ as offset', '% as offset']line 199 line 202
SL Offset from the Low/high in %1.4floatlongSlLow shortSlLow
SL Offset from the Low/high in $100floatlongSlLow shortSlLow
SL lookback for Low/high5int · min 1 · max 50longSlLow shortSlLow
static % Stop Loss
Long Stop Loss in %0.5floatlongSL
Short Stop Loss in %0.5floatshortSL
Take Profit
Long Take Profit in %4floatlongTP1
Short Take Profit in %1.6floatshortTP
alert settings
Alert Optionsonce per bar closestring · options ['once per bar', 'once per bar close', 'all']unused
Buy Alert MessageBullish Divergence detected, put your SL @stringunused
enable Stop Loss Value at the end of "buy Alert message"trueboolunused
Buy Alert message after SL Valuestringunused

What it calculates

  • Lowestlow, Pivot Look Back (400)StrongBand_Price_of_Low · line 32
  • Highesthigh, Pivot Look Back (400)StrongBand_Price_of_High · line 33
  • Lowestlow, Pivot Look Back (900)MiddleBand_Price_of_Low · line 39
  • Highesthigh, Pivot Look Back (900)MiddleBand_Price_of_High · line 40
  • Lowestlow, Pivot Look Back (4000)SidewaysBand_Price_of_Low · line 46
  • Highesthigh, Pivot Look Back (4000)SidewaysBand_Price_of_High · line 47
  • EMAStrongBand_Bull_Fib_Price, Fib EMA Length (120)StrongBand_Bull_EMA · line 84
  • EMAStrongBand_Bear_Fib_Price, Fib EMA Length (120)StrongBand_Bear_EMA · line 85
  • EMAMiddleBand_Bull_Fib_Price, Fib EMA Length (400)MiddleBand_Bull_EMA · line 95
  • EMAMiddleBand_Bear_Fib_Price, Fib EMA Length (400)MiddleBand_Bear_EMA · line 96
  • EMASidewaysBand_Bull_Fib_Price, Fib EMA Length (150)SidewaysBand_Bull_EMA · line 106
  • EMASidewaysBand_Bear_Fib_Price, Fib EMA Length (150)SidewaysBand_Bear_EMA · line 107
  • Lowestlow, SL lookback for Low/high (5)longSlLow · line 197
  • Highesthigh, SL lookback for Low/high (5)shortSlLow · line 198

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

Order rules

OrderFires whenBy defaultLine
Open Bull longStrongBand_Buy_AlertStronBand_Trend_isnt_fresh and StrongBand_Low_isnt_toLow and StronBand_Price_Average_above_Bull_Level and StrongBand_Price_was_below_Bull_level and StrongBand_Price_is_above_Bull_level and all_Fib_Emas_Trend_or_SidewaysOn230
Open Bull longMiddleBand_Buy_AlertMiddleBand_Trend_isnt_fresh and MiddleBand_Low_isnt_toLow and MiddleBand_Price_Average_above_Bull_Level and MiddleBand_Price_was_below_Bull_level and MiddleBand_Price_is_above_Bull_level and Middle_and_Sideways_Fib_Emas_Trend_or_SidewaysOn231
Open Bull longSidewaysBand_Buy_AlertSidewaysBand_Trend_isnt_fresh and SidewaysBand_Low_isnt_toLow and SidewaysBand_Price_Average_above_Bull_Level and SidewaysBand_Price_was_below_Bull_level and SidewaysBand_Price_is_above_Bull_level and (SidewaysBand_Ema_Sideways or SidewaysBand_Ema_in_Uptrend and ( not SidewaysBand_Ema_in_Downtrend))On232
Open Bear shortStrongBand_Sell_AlertStronBand_Price_Average_below_Bear_Level and StrongBand_High_isnt_to_High and StrongBand_Bear_Trend_isnt_fresh and StrongBand_Price_was_above_Bear_level and StrongBand_Price_is_below_Bear_level and all_Fib_Emas_Downtrend and not all_Fib_Emas_Trend_or_SidewaysOn233
Open Bear shortMiddleBand_Sell_AlertMiddleBand_Price_Average_below_Bear_Level and MiddleBand_High_isnt_to_High and MiddleBand_Bear_Trend_isnt_fresh and MiddleBand_Price_was_above_Bear_level and MiddleBand_Price_is_below_Bear_level and Middle_and_Sideways_Fib_Emas_Downtrend and not Middle_and_Sideways_Fib_Emas_Trend_or_SidewaysOn234
Open Bear shortSidewaysBand_Sell_AlertSidewaysBand_Price_Average_below_Bear_Level and SidewaysBand_High_isnt_to_High and SidewaysBand_Bear_Trend_isnt_fresh and SidewaysBand_Price_was_above_Bear_level and SidewaysBand_Price_is_below_Bear_level and SidewaysBand_Ema_in_Downtrend and not (SidewaysBand_Ema_Sideways or SidewaysBand_Ema_in_Uptrend and ( not SidewaysBand_Ema_in_Downtrend))On235
Exit longTP-SL stop and limitenableSL and whichSL == 'static % as SL'On238
Exit shortTP-SL stop and limitenableSL and whichSL == 'static % as SL'On239
Exit longTP-SL stop and limitenableSL and whichSL == 'low/high as SL' and ta.barssince(StrongBand_Buy_Alert or MiddleBand_Buy_Alert or SidewaysBand_Buy_Alert) < 2 and barsSinceLastEntry() < 2On245
Exit shortTP-SL stop and limitenableSL and whichSL == 'low/high as SL' and ta.barssince(StrongBand_Sell_Alert or MiddleBand_Sell_Alert or SidewaysBand_Sell_Alert) < 2 and barsSinceLastEntry() < 2On247
Exit longTP-SL limitnot enableSLOn249
Exit shortTP-SL limitnot enableSLOn250

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

Does it repaint?

Yes

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

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

Other markets

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

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−8.6%+102.5%10%0.008.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+3.8%+5.5%1100%75.042.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−2.8%+8.4%10%0.002.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+3.9%+21.5%1100%—3.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+15.6%+17.1%4100%—2.8%8 May 2026 – 21 Oct 2026

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

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market0—$0.00
Sideways market10%−$855.81
Falling market0—$0.00

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

How bad could the drawdown be?

8.6%

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

0%10%
All 1 trades
SideEntryExitBarsP&L
long3 Nov 2025 106,583.0014 Nov 2025 97,559.1011−$855.81

Similar scripts

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

ScriptSharesTypeNetTradesMax drawdown
Auto Fib Golden Pocket Band - Strategy with Buy Signals this page—v5 strategy−8.6%18.6%
CC Trend strategy 2- Downtrend Short by CheatCode1ema highest lowestv5 strategyNo trades on this market
TrianglePoint strategy by mohaneehighest lowest emav4 strategy+45.4%11101.9%
Lagged Donchian Channel + EMA by Mysteriownema highest lowestv4 strategy−12.3%412.3%
Backtest Custom HiLo Strategy by luyikaibrema highest lowestv4 strategyNo trades on this market
CM_SlingShotSystem+_CassicEMA+Willams21EMA13 htc1977 edition by Arivadisema highest lowestv5 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.

  • 6 strategy calls use the when = argument (line 230, 231, 232, 233, 234, 235). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 1 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 230: when = StrongBand_Buy_Alert → if block
  • Line 231: when = MiddleBand_Buy_Alert → if block
  • Line 232: when = SidewaysBand_Buy_Alert → if block
  • Line 233: when = StrongBand_Sell_Alert → if block
  • Line 234: when = MiddleBand_Sell_Alert → if block
  • Line 235: when = SidewaysBand_Sell_Alert → if block
⋯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='Upper Band Long', when=StrongBand_Buy_Alert)+if StrongBand_Buy_Alert+    strategy.entry('Bull', strategy.long, comment='Upper Band Long')-strategy.entry('Bull', strategy.long, comment='Lower Band Long', when=MiddleBand_Buy_Alert)+if MiddleBand_Buy_Alert+    strategy.entry('Bull', strategy.long, comment='Lower Band Long')-strategy.entry('Bull', strategy.long, comment='Lower Band Long', when=SidewaysBand_Buy_Alert)+if SidewaysBand_Buy_Alert+    strategy.entry('Bull', strategy.long, comment='Lower Band Long')-strategy.entry('Bear', strategy.short, comment='Upper Band Short', when=StrongBand_Sell_Alert)+if StrongBand_Sell_Alert+    strategy.entry('Bear', strategy.short, comment='Upper Band Short')-strategy.entry('Bear', strategy.short, comment='Lower Band Short', when=MiddleBand_Sell_Alert)+if MiddleBand_Sell_Alert+    strategy.entry('Bear', strategy.short, comment='Lower Band Short')-strategy.entry('Bear', strategy.short, comment='Lower Band Short', when=SidewaysBand_Sell_Alert)+if SidewaysBand_Sell_Alert+    strategy.entry('Bear', strategy.short, comment='Lower Band Short')// check which SL to use⋯

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 1 before, 1 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © imal_max reeee-//@version=5+//@version=6strategy(title="Auto Fib Golden Pocket Band - Autofib Moving Average", shorttitle="Auto Fib Golden Pocket Band", overlay=true, pyramiding=15, process_orders_on_close=true, calc_on_every_tick=true, initial_capital=10000, 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)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 110 msWith a workaround 1,000 bars in 177 msNot measured
PineTSNot testedNot testedNot measured

Zeal Terminal's engine currently merges fill() calls that share a title, so it would draw 1 of this script's 2 fills; this page gives each call its own title to draw all of them.

“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/// © imal_max reeee//@version=5strategy(title="Auto Fib Golden Pocket Band - Autofib Moving Average", shorttitle="Auto Fib Golden Pocket Band", overlay=true, pyramiding=15, process_orders_on_close=true, calc_on_every_tick=true, initial_capital=10000, 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)//indicator("Auto Fib Golden Pocket Band - Autofib Moving Average", overlay=true, shorttitle="Auto Fib Golden Pocket Band", timeframe""")// Fibs// auto fib ranges// fib band Strong Trend                                                                                                                                           enable_StrongBand_Bull = input.bool(title='enable Upper Bullish Band . . . Fib Level', defval=true, group='══════ Strong Trend Levels ══════', inline="0")select_StrongBand_Fib_Bull = input.float(0.236, title="     ", options=[-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Strong Trend Levels ══════', inline="0")enable_StrongBand_Bear = input.bool(title='enable Lower Bearish Band . . . Fib Level', defval=false, group='══════ Strong Trend Levels ══════', inline="1")select_StrongBand_Fib_Bear = input.float(0.382, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Strong Trend Levels ══════', inline="1")StrongBand_Lookback = input.int(title='Pivot Look Back', minval=1, defval=400, group='══════ Strong Trend Levels ══════', inline="2")StrongBand_EmaLen = input.int(title='Fib EMA Length', minval=1, defval=120, group='══════ Strong Trend Levels ══════', inline="2")// fib middle Band regular Trendenable_MiddleBand_Bull = input.bool(title='enable Middle Bullish Band . . . Fib Level', defval=true, group='══════ Regular Trend Levels ══════', inline="0")select_MiddleBand_Fib_Bull = input.float(0.618, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.6, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Regular Trend Levels ══════', inline="0")enable_MiddleBand_Bear = input.bool(title='enable Middle Bearish Band . . . Fib Level', defval=true, group='══════ Regular Trend Levels ══════', inline="1")select_MiddleBand_Fib_Bear = input.float(0.382, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Regular Trend Levels ══════', inline="1")MiddleBand_Lookback = input.int(title='Pivot Look Back', minval=1, defval=900, group='══════ Regular Trend Levels ══════', inline="2")MiddleBand_EmaLen = input.int(title='Fib EMA Length', minval=1, defval=400, group='══════ Regular Trend Levels ══════', inline="2")// fib Sideways Bandenable_SidewaysBand_Bull = input.bool(title='enable Lower Bullish Band . . . Fib Level', defval=true, group='══════ Sideways Trend Levels ══════', inline="0")select_SidewaysBand_Fib_Bull = input.float(0.6, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.6, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Sideways Trend Levels ══════', inline="0")enable_SidewaysBand_Bear = input.bool(title='enable Upper Bearish Band . . . Fib Level', defval=true, group='══════ Sideways Trend Levels ══════', inline="1")select_SidewaysBand_Fib_Bear = input.float(0.5, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Sideways Trend Levels ══════', inline="1")SidewaysBand_Lookback = input.int(title='Pivot Look Back', minval=1, defval=4000, group='══════ Sideways Trend Levels ══════', inline="2")SidewaysBand_EmaLen = input.int(title='Fib EMA Length', minval=1, defval=150, group='══════ Sideways Trend Levels ══════', inline="2")// Strong BandisBelow_StrongBand_Bull = trueisBelow_StrongBand_Bear = trueStrongBand_Price_of_Low = float(na)StrongBand_Price_of_High = float(na)StrongBand_Bear_Fib_Price = float(na)StrongBand_Bull_Fib_Price = float(na)/// Middle BandisBelow_MiddleBand_Bull = trueisBelow_MiddleBand_Bear = trueMiddleBand_Price_of_Low = float(na)MiddleBand_Price_of_High = float(na)MiddleBand_Bear_Fib_Price = float(na)MiddleBand_Bull_Fib_Price = float(na)// Sideways BandisBelow_SidewaysBand_Bull = trueisBelow_SidewaysBand_Bear = trueSidewaysBand_Price_of_Low = float(na)SidewaysBand_Price_of_High = float(na)SidewaysBand_Bear_Fib_Price = float(na)SidewaysBand_Bull_Fib_Price = float(na)// get Fib Levelsif enable_StrongBand_Bull    StrongBand_Price_of_High := ta.highest(high, StrongBand_Lookback)    StrongBand_Price_of_Low := ta.lowest(low, StrongBand_Lookback)    StrongBand_Bull_Fib_Price := (StrongBand_Price_of_High - StrongBand_Price_of_Low) * (1 - select_StrongBand_Fib_Bull) + StrongBand_Price_of_Low //+ fibbullHighDivi    isBelow_StrongBand_Bull := StrongBand_Bull_Fib_Price > ta.lowest(low, 2) or not enable_StrongBand_Bullif enable_StrongBand_Bear    StrongBand_Price_of_High := ta.highest(high, StrongBand_Lookback)    StrongBand_Price_of_Low := ta.lowest(low, StrongBand_Lookback)    StrongBand_Bear_Fib_Price := (StrongBand_Price_of_High - StrongBand_Price_of_Low) * (1 - select_StrongBand_Fib_Bear) + StrongBand_Price_of_Low// + fibbullLowhDivi    isBelow_StrongBand_Bear := StrongBand_Bear_Fib_Price < ta.highest(low, 2) or not enable_StrongBand_Bearif enable_MiddleBand_Bull    MiddleBand_Price_of_High := ta.highest(high, MiddleBand_Lookback)    MiddleBand_Price_of_Low := ta.lowest(low, MiddleBand_Lookback)    MiddleBand_Bull_Fib_Price := (MiddleBand_Price_of_High - MiddleBand_Price_of_Low) * (1 - select_MiddleBand_Fib_Bull) + MiddleBand_Price_of_Low //+ fibbullHighDivi    isBelow_MiddleBand_Bull := MiddleBand_Bull_Fib_Price > ta.lowest(low, 2) or not enable_MiddleBand_Bullif enable_MiddleBand_Bear    MiddleBand_Price_of_High := ta.highest(high, MiddleBand_Lookback)    MiddleBand_Price_of_Low := ta.lowest(low, MiddleBand_Lookback)    MiddleBand_Bear_Fib_Price := (MiddleBand_Price_of_High - MiddleBand_Price_of_Low) * (1 - select_MiddleBand_Fib_Bear) + MiddleBand_Price_of_Low// + fibbullLowhDivi    isBelow_MiddleBand_Bear := MiddleBand_Bear_Fib_Price < ta.highest(low, 2) or not enable_MiddleBand_Bearif enable_SidewaysBand_Bull    SidewaysBand_Price_of_High := ta.highest(high, SidewaysBand_Lookback)    SidewaysBand_Price_of_Low := ta.lowest(low, SidewaysBand_Lookback)    SidewaysBand_Bull_Fib_Price := (SidewaysBand_Price_of_High - SidewaysBand_Price_of_Low) * (1 - select_SidewaysBand_Fib_Bull) + SidewaysBand_Price_of_Low //+ fibbullHighDivi    isBelow_SidewaysBand_Bull := SidewaysBand_Bull_Fib_Price > ta.lowest(low, 2) or not enable_SidewaysBand_Bullif enable_SidewaysBand_Bear    SidewaysBand_Price_of_High := ta.highest(high, SidewaysBand_Lookback)    SidewaysBand_Price_of_Low := ta.lowest(low, SidewaysBand_Lookback)    SidewaysBand_Bear_Fib_Price := (SidewaysBand_Price_of_High - SidewaysBand_Price_of_Low) * (1 - select_SidewaysBand_Fib_Bear) + SidewaysBand_Price_of_Low// + fibbullLowhDivi    isBelow_SidewaysBand_Bear := SidewaysBand_Bear_Fib_Price < ta.highest(low, 2) or not enable_SidewaysBand_Bear// Fib EMAs// fib ema Strong TrendStrongBand_current_Trend_EMA = float(na)StrongBand_Bull_EMA = ta.ema(StrongBand_Bull_Fib_Price, StrongBand_EmaLen)StrongBand_Bear_EMA = ta.ema(StrongBand_Bear_Fib_Price, StrongBand_EmaLen)StrongBand_Ema_in_Uptrend = ta.change(StrongBand_Bull_EMA) > 0 or ta.change(StrongBand_Bear_EMA) > 0StrongBand_Ema_Sideways = ta.change(StrongBand_Bull_EMA) == 0 or ta.change(StrongBand_Bear_EMA) == 0StrongBand_Ema_in_Downtrend = ta.change(StrongBand_Bull_EMA) < 0 or ta.change(StrongBand_Bear_EMA) < 0if StrongBand_Ema_in_Uptrend or StrongBand_Ema_Sideways    StrongBand_current_Trend_EMA := StrongBand_Bull_EMAif StrongBand_Ema_in_Downtrend     StrongBand_current_Trend_EMA := StrongBand_Bear_EMA// fib ema Normal TrendMiddleBand_current_Trend_EMA = float(na)MiddleBand_Bull_EMA = ta.ema(MiddleBand_Bull_Fib_Price, MiddleBand_EmaLen)MiddleBand_Bear_EMA = ta.ema(MiddleBand_Bear_Fib_Price, MiddleBand_EmaLen)MiddleBand_Ema_in_Uptrend = ta.change(MiddleBand_Bull_EMA) > 0 or ta.change(MiddleBand_Bear_EMA) > 0MiddleBand_Ema_Sideways = ta.change(MiddleBand_Bull_EMA) == 0 or ta.change(MiddleBand_Bear_EMA) == 0MiddleBand_Ema_in_Downtrend = ta.change(MiddleBand_Bull_EMA) < 0 or ta.change(MiddleBand_Bear_EMA) < 0if MiddleBand_Ema_in_Uptrend or MiddleBand_Ema_Sideways    MiddleBand_current_Trend_EMA := MiddleBand_Bull_EMAif MiddleBand_Ema_in_Downtrend     MiddleBand_current_Trend_EMA := MiddleBand_Bear_EMA// fib ema Sideways TrendSidewaysBand_current_Trend_EMA = float(na)SidewaysBand_Bull_EMA = ta.ema(SidewaysBand_Bull_Fib_Price, SidewaysBand_EmaLen)SidewaysBand_Bear_EMA = ta.ema(SidewaysBand_Bear_Fib_Price, SidewaysBand_EmaLen)SidewaysBand_Ema_in_Uptrend = ta.change(SidewaysBand_Bull_EMA) > 0 or ta.change(SidewaysBand_Bear_EMA) > 0SidewaysBand_Ema_Sideways = ta.change(SidewaysBand_Bull_EMA) == 0 or ta.change(SidewaysBand_Bear_EMA) == 0SidewaysBand_Ema_in_Downtrend = ta.change(SidewaysBand_Bull_EMA) < 0 or ta.change(SidewaysBand_Bear_EMA) < 0if SidewaysBand_Ema_in_Uptrend or SidewaysBand_Ema_Sideways    SidewaysBand_current_Trend_EMA := SidewaysBand_Bull_EMAif SidewaysBand_Ema_in_Downtrend     SidewaysBand_current_Trend_EMA := SidewaysBand_Bear_EMA// trend states and colorsall_Fib_Emas_Trending = StrongBand_Ema_in_Uptrend and MiddleBand_Ema_in_Uptrend and SidewaysBand_Ema_in_Uptrendall_Fib_Emas_Downtrend = MiddleBand_Ema_in_Downtrend and StrongBand_Ema_in_Downtrend and SidewaysBand_Ema_in_Downtrendall_Fib_Emas_Sideways = MiddleBand_Ema_Sideways and StrongBand_Ema_Sideways and SidewaysBand_Ema_Sidewaysall_Fib_Emas_Trend_or_Sideways = (MiddleBand_Ema_Sideways or StrongBand_Ema_Sideways or SidewaysBand_Ema_Sideways) or (StrongBand_Ema_in_Uptrend or MiddleBand_Ema_in_Uptrend or SidewaysBand_Ema_in_Uptrend) and not (MiddleBand_Ema_in_Downtrend or StrongBand_Ema_in_Downtrend or SidewaysBand_Ema_in_Downtrend)allFibsUpAndDownTrend = (MiddleBand_Ema_in_Downtrend or StrongBand_Ema_in_Downtrend or SidewaysBand_Ema_in_Downtrend) and (MiddleBand_Ema_Sideways or SidewaysBand_Ema_Sideways or StrongBand_Ema_Sideways or StrongBand_Ema_in_Uptrend or MiddleBand_Ema_in_Uptrend or SidewaysBand_Ema_in_Uptrend)Middle_and_Sideways_Emas_Trending = MiddleBand_Ema_in_Uptrend and SidewaysBand_Ema_in_UptrendMiddle_and_Sideways_Fib_Emas_Downtrend = MiddleBand_Ema_in_Downtrend and SidewaysBand_Ema_in_DowntrendMiddle_and_Sideways_Fib_Emas_Sideways = MiddleBand_Ema_Sideways and SidewaysBand_Ema_SidewaysMiddle_and_Sideways_Fib_Emas_Trend_or_Sideways = (MiddleBand_Ema_Sideways or SidewaysBand_Ema_Sideways) or (MiddleBand_Ema_in_Uptrend or SidewaysBand_Ema_in_Uptrend) and not (MiddleBand_Ema_in_Downtrend or SidewaysBand_Ema_in_Downtrend)Middle_and_Sideways_UpAndDownTrend = (MiddleBand_Ema_in_Downtrend or SidewaysBand_Ema_in_Downtrend) and (MiddleBand_Ema_Sideways or SidewaysBand_Ema_Sideways or MiddleBand_Ema_in_Uptrend or SidewaysBand_Ema_in_Uptrend)UpperBand_Ema_Color = all_Fib_Emas_Trend_or_Sideways ? color.lime : all_Fib_Emas_Downtrend ? color.red : allFibsUpAndDownTrend ? color.white : naMiddleBand_Ema_Color = Middle_and_Sideways_Fib_Emas_Trend_or_Sideways ? color.lime : Middle_and_Sideways_Fib_Emas_Downtrend ? color.red : Middle_and_Sideways_UpAndDownTrend ? color.white : naSidewaysBand_Ema_Color = SidewaysBand_Ema_in_Uptrend ? color.lime : SidewaysBand_Ema_in_Downtrend ? color.red : (SidewaysBand_Ema_in_Downtrend and (SidewaysBand_Ema_Sideways or SidewaysBand_Ema_in_Uptrend)) ? color.white : naplotStrong_Ema = plot(StrongBand_current_Trend_EMA, color=UpperBand_Ema_Color, title="Strong Trend")plotMiddle_Ema = plot(MiddleBand_current_Trend_EMA, color=MiddleBand_Ema_Color, title="Normal Trend")plotSideways_Ema = plot(SidewaysBand_current_Trend_EMA, color=SidewaysBand_Ema_Color, title="Sidewaysd")Strong_Middle_fillcolor = color.new(color.green, 90)if all_Fib_Emas_Trend_or_Sideways    Strong_Middle_fillcolor := color.new(color.green, 90)if all_Fib_Emas_Downtrend    Strong_Middle_fillcolor := color.new(color.red, 90)    if allFibsUpAndDownTrend    Strong_Middle_fillcolor := color.new(color.white, 90)Middle_Sideways_fillcolor = color.new(color.green, 90)if Middle_and_Sideways_Fib_Emas_Trend_or_Sideways    Middle_Sideways_fillcolor := color.new(color.green, 90)if Middle_and_Sideways_Fib_Emas_Downtrend    Middle_Sideways_fillcolor := color.new(color.red, 90)    if Middle_and_Sideways_UpAndDownTrend    Middle_Sideways_fillcolor := color.new(color.white, 90)fill(plotStrong_Ema, plotMiddle_Ema, color=Strong_Middle_fillcolor, title="fib band background")fill(plotMiddle_Ema, plotSideways_Ema, color=Middle_Sideways_fillcolor, title="fib band background")// buy conditionStrongBand_Price_was_below_Bull_level = ta.lowest(low, 1) < StrongBand_current_Trend_EMAStrongBand_Price_is_above_Bull_level =  close > StrongBand_current_Trend_EMAStronBand_Price_Average_above_Bull_Level = ta.ema(low, 10) > StrongBand_current_Trend_EMAStrongBand_Low_isnt_toLow = (ta.lowest(StrongBand_current_Trend_EMA, 15) - ta.lowest(low, 15)) < close * 0.005StronBand_Trend_isnt_fresh = ta.barssince(StrongBand_Ema_in_Downtrend) > 50 or na(ta.barssince(StrongBand_Ema_in_Downtrend))MiddleBand_Price_was_below_Bull_level = ta.lowest(low, 1) < MiddleBand_current_Trend_EMAMiddleBand_Price_is_above_Bull_level = close > MiddleBand_current_Trend_EMAMiddleBand_Price_Average_above_Bull_Level = ta.ema(close, 20) > MiddleBand_current_Trend_EMAMiddleBand_Low_isnt_toLow = (ta.lowest(MiddleBand_current_Trend_EMA, 10) - ta.lowest(low, 10)) < close * 0.0065MiddleBand_Trend_isnt_fresh = ta.barssince(MiddleBand_Ema_in_Downtrend) > 50 or na(ta.barssince(MiddleBand_Ema_in_Downtrend))SidewaysBand_Price_was_below_Bull_level = ta.lowest(low, 1) < SidewaysBand_current_Trend_EMASidewaysBand_Price_is_above_Bull_level =  close > SidewaysBand_current_Trend_EMASidewaysBand_Price_Average_above_Bull_Level = ta.ema(low, 80) > SidewaysBand_current_Trend_EMASidewaysBand_Low_isnt_toLow = (ta.lowest(SidewaysBand_current_Trend_EMA, 150) - ta.lowest(low, 150)) < close * 0.0065SidewaysBand_Trend_isnt_fresh = ta.barssince(SidewaysBand_Ema_in_Downtrend) > 50 or na(ta.barssince(SidewaysBand_Ema_in_Downtrend))StrongBand_Buy_Alert = StronBand_Trend_isnt_fresh and StrongBand_Low_isnt_toLow and StronBand_Price_Average_above_Bull_Level and StrongBand_Price_was_below_Bull_level and StrongBand_Price_is_above_Bull_level and all_Fib_Emas_Trend_or_SidewaysMiddleBand_Buy_Alert = MiddleBand_Trend_isnt_fresh and MiddleBand_Low_isnt_toLow and MiddleBand_Price_Average_above_Bull_Level and MiddleBand_Price_was_below_Bull_level and MiddleBand_Price_is_above_Bull_level and Middle_and_Sideways_Fib_Emas_Trend_or_SidewaysSidewaysBand_Buy_Alert = SidewaysBand_Trend_isnt_fresh and SidewaysBand_Low_isnt_toLow and SidewaysBand_Price_Average_above_Bull_Level and SidewaysBand_Price_was_below_Bull_level and SidewaysBand_Price_is_above_Bull_level and (SidewaysBand_Ema_Sideways or SidewaysBand_Ema_in_Uptrend and ( not SidewaysBand_Ema_in_Downtrend))// Sell conditionStrongBand_Price_was_above_Bear_level = ta.highest(high, 1) > StrongBand_current_Trend_EMAStrongBand_Price_is_below_Bear_level =  close < StrongBand_current_Trend_EMAStronBand_Price_Average_below_Bear_Level = ta.sma(high, 10) < StrongBand_current_Trend_EMAStrongBand_High_isnt_to_High = (ta.highest(high, 15) - ta.highest(StrongBand_current_Trend_EMA, 15)) < close * 0.005StrongBand_Bear_Trend_isnt_fresh = ta.barssince(StrongBand_Ema_in_Uptrend) > 50MiddleBand_Price_was_above_Bear_level = ta.highest(high, 1) > MiddleBand_current_Trend_EMAMiddleBand_Price_is_below_Bear_level =  close < MiddleBand_current_Trend_EMAMiddleBand_Price_Average_below_Bear_Level = ta.sma(high, 9) < MiddleBand_current_Trend_EMAMiddleBand_High_isnt_to_High = (ta.highest(high, 10) - ta.highest(MiddleBand_current_Trend_EMA, 10)) < close * 0.0065MiddleBand_Bear_Trend_isnt_fresh = ta.barssince(MiddleBand_Ema_in_Uptrend) > 50SidewaysBand_Price_was_above_Bear_level = ta.highest(high, 1) > SidewaysBand_current_Trend_EMASidewaysBand_Price_is_below_Bear_level =  close < SidewaysBand_current_Trend_EMASidewaysBand_Price_Average_below_Bear_Level = ta.sma(high, 20) < SidewaysBand_current_Trend_EMASidewaysBand_High_isnt_to_High = (ta.highest(high, 20) - ta.highest(SidewaysBand_current_Trend_EMA, 15)) < close * 0.0065SidewaysBand_Bear_Trend_isnt_fresh = ta.barssince(SidewaysBand_Ema_in_Uptrend) > 50StrongBand_Sell_Alert = StronBand_Price_Average_below_Bear_Level and StrongBand_High_isnt_to_High and StrongBand_Bear_Trend_isnt_fresh and StrongBand_Price_was_above_Bear_level and StrongBand_Price_is_below_Bear_level and all_Fib_Emas_Downtrend and not all_Fib_Emas_Trend_or_SidewaysMiddleBand_Sell_Alert = MiddleBand_Price_Average_below_Bear_Level and MiddleBand_High_isnt_to_High and MiddleBand_Bear_Trend_isnt_fresh and MiddleBand_Price_was_above_Bear_level and MiddleBand_Price_is_below_Bear_level and Middle_and_Sideways_Fib_Emas_Downtrend and not Middle_and_Sideways_Fib_Emas_Trend_or_SidewaysSidewaysBand_Sell_Alert = SidewaysBand_Price_Average_below_Bear_Level and SidewaysBand_High_isnt_to_High and SidewaysBand_Bear_Trend_isnt_fresh and SidewaysBand_Price_was_above_Bear_level and SidewaysBand_Price_is_below_Bear_level and SidewaysBand_Ema_in_Downtrend and not (SidewaysBand_Ema_Sideways or SidewaysBand_Ema_in_Uptrend and ( not SidewaysBand_Ema_in_Downtrend))// Backtester////////////////// Stop Loss// Stop lossenableSL =  input.bool(true, title='enable Stop Loss', group='══════════ Stop Loss Settings ══════════')whichSL =  input.string(defval='low/high as SL', title='SL based on static % or based on the low/high', options=['low/high as SL', 'static % as SL'], group='══════════ Stop Loss Settings ══════════')whichOffset = input.string(defval='% as offset', title='choose offset from the low/high', options=['$ as offset', '% as offset'], group='Stop Loss at the low/high')lowPBuffer = input.float(1.4, title='SL Offset from the Low/high in %', group='Stop Loss at the low/high') / 100lowDBuffer = input.float(100, title='SL Offset from the Low/high in $', group='Stop Loss at the low/high')SlLowLookback = input.int(title='SL lookback for Low/high', defval=5, minval=1, maxval=50, group='Stop Loss at the low/high')longSlLow = float(na)shortSlLow = float(na)if whichOffset == "% as offset" and whichSL == "low/high as SL" and enableSL    longSlLow := ta.lowest(low, SlLowLookback) * (1 - lowPBuffer)    shortSlLow := ta.highest(high, SlLowLookback) * (1 + lowPBuffer)if whichOffset == "$ as offset" and whichSL == "low/high as SL" and enableSL    longSlLow := ta.lowest(low, SlLowLookback) - lowDBuffer    shortSlLow := ta.highest(high, SlLowLookback) + lowDBuffer//plot(shortSlLow, 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='Long Stop Loss in %', group='static % Stop Loss', inline='Input 1') / 100// short settings - 🔥 uncomment the 6 lines below to disable the alerts and enable the backtester shortStopLoss = input.float(0.5, title='Short Stop Loss in %', group='static % Stop Loss', inline='Input 1') / 100/////// Take profitlongTakeProfit1 = input.float(4, title='Long Take Profit in %', group='Take Profit', inline='Input 1') / 100/////// Take profitshortTakeProfit1 = input.float(1.6, title='Short Take Profit in %', group='Take Profit', inline='Input 1') / 100////////////////// SL TP END/////////////////// 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 ═══════════') ////////////////// Backtester // 🔥 uncomment the all lines below for the backtester and revert for alertsshortTrading = enable_MiddleBand_Bear or enable_StrongBand_Bear or enable_SidewaysBand_BearlongTrading = enable_StrongBand_Bull or enable_MiddleBand_Bull or enable_SidewaysBand_BulllongTP1 = strategy.position_size > 0 ? strategy.position_avg_price * (1 + longTakeProfit1) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - longTakeProfit1) : nalongSL = strategy.position_size > 0 ? strategy.position_avg_price * (1 - longStopLoss) : strategy.position_size < 0 ? strategy.position_avg_price * (1 + longStopLoss) : nashortTP = strategy.position_size > 0 ? strategy.position_avg_price * (1 + shortTakeProfit1) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - shortTakeProfit1) : nashortSL = strategy.position_size > 0 ? strategy.position_avg_price * (1 - shortStopLoss) : strategy.position_size < 0 ? strategy.position_avg_price * (1 + shortStopLoss) : 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='Upper Band Long', when=StrongBand_Buy_Alert)strategy.entry('Bull', strategy.long, comment='Lower Band Long', when=MiddleBand_Buy_Alert)strategy.entry('Bull', strategy.long, comment='Lower Band Long', when=SidewaysBand_Buy_Alert)strategy.entry('Bear', strategy.short, comment='Upper Band Short', when=StrongBand_Sell_Alert)strategy.entry('Bear', strategy.short, comment='Lower Band Short', when=MiddleBand_Sell_Alert)strategy.entry('Bear', strategy.short, comment='Lower Band Short', when=SidewaysBand_Sell_Alert)// check which SL to useif enableSL and whichSL == 'static % as SL'    strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1, stop=longSL)    strategy.exit(id='shortTP-SL', from_entry='Bear', limit=shortTP, stop=shortSL)// 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 == 'low/high as SL' and ta.barssince(StrongBand_Buy_Alert or MiddleBand_Buy_Alert or SidewaysBand_Buy_Alert) < 2 and barsSinceLastEntry() < 2    strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1, stop=longSlLow)if enableSL and whichSL == 'low/high as SL' and ta.barssince(StrongBand_Sell_Alert or MiddleBand_Sell_Alert or SidewaysBand_Sell_Alert) < 2 and barsSinceLastEntry() < 2    strategy.exit(id='shortTP-SL', from_entry='Bear', limit=shortTP, stop=shortSlLow)if not enableSL    strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1)    strategy.exit(id='shortTP-SL', from_entry='Bear', limit=shortTP)