Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Triple Threat

A Pine Script v4 strategy built on Stdev (price, bbwLen), RSI (close, 14) and SMA (rsi, 7). It has 10 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays no commission. 38 settings; defaults include Price Source close, Basis Type SMA and Length 21.

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 Triple Threat repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did Triple Threat do on BTCUSDT 1D with default settings?
−25.39%
From 26 Jan 2024 to 21 Oct 2026, over 21 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Triple Threat be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Triple Threat use a stop loss?
Yes
strategy.exit sets a stop on line 222, 223, 225, 226.
Does Triple Threat run in Zeal Terminal?
Yes
It compiles in 116 ms and runs 1,000 bars in 331 ms, in the browser.

BTCUSDT · 1D · default settings

  • Oversold
  • Overbought
  • RSI Buy Signal
  • RSI Sell Signal
  • RSI Confirmed Buy Signal
  • RSI Confirmed Sell Signal
  • Fully Confirmed Buy Signal
  • Fully Confirmed Sell Signal
  • BBWP
  • MA 1
  • RSI
  • RSI MA
  • 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 (38)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctOversold$96,845$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
−25.39%
−$25,385.20
Buy and hold
+102.5%
same period
Closed trades
21
7 won · 14 lost
Profitable
33.3%
of closed trades
Profit factor
0.70
gross profit ÷ gross loss
Max drawdown
57.45%
−$57,445.10

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

Review

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

  • Check

    1 setting does nothing

    “Line Width” is declared but never read.

  • Check

    No commission

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

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    2 settings have no label

    In the settings dialog i_ma1On (line 31), i_c_ma1 (line 33) show an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

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

  • Note

    Uses an argument v6 removed

    when = on line 213, 215, 217, 219, 222, 223, 225, 226, 228, 229. The upgraded version below moves each call inside an if block.

Upgrade and export

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

  • Upgrading to v5 renames sma → ta.sma, ema → ta.ema, vwma → ta.vwma, stdev → ta.stdev, round → math.round, rsi → ta.rsi.
  • 10 strategy calls use the when = argument (line 213, 215, 217, 219, 222, 223, 225, 226, 228, 229). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 7: //@version=4 → //@version=5
  • Line 16: input(type = input.source) → input.source()
  • Line 17: input(type = input.bool) → input.bool()
  • Line 18: input(type = input.bool) → input.bool()
  • Line 19: input(type = input.bool) → input.bool()
  • Line 20: input(type = input.bool) → input.bool()
40 more edits
  • Line 24: input(type = input.string) → input.string()
  • Line 25: input(type = input.integer) → input.int()
  • Line 26: input(type = input.integer) → input.int()
  • Line 27: input(type = input.string) → input.string()
  • Line 28: input(type = input.string) → input.string()
  • Line 29: input(type = input.color) → input.color()
  • Line 30: input(type = input.integer) → input.int()
  • Line 31: input(type = input.bool) → input.bool()
  • Line 32: input(type = input.string) → input.string()
  • Line 33: input(type = input.color) → input.color()
  • Line 34: input(type = input.integer) → input.int()
  • Line 85: type is reserved in v5: renamed type_
  • Line 85: sma → ta.sma
  • Line 85: ema → ta.ema
  • Line 85: vwma → ta.vwma
  • Line 89: stdev → ta.stdev
  • Line 94: return is reserved in v5: renamed return_
  • Line 95: round → math.round
  • Line 106: input(type = input.float) → input.float()
  • Line 107: input(type = input.float) → input.float()
  • Line 108: input(type = input.float) → input.float()
  • Line 109: input(type = input.string) → input.string()
  • Line 110: input(type = input.integer) → input.int()
  • Line 111: input(type = input.float) → input.float()
  • Line 112: input(type = input.float) → input.float()
  • Line 113: input(type = input.float) → input.float()
  • Line 114: input(type = input.bool) → input.bool()
  • Line 115: input(type = input.float) → input.float()
  • Line 116: input(type = input.bool) → input.bool()
  • Line 117: input(type = input.float) → input.float()
  • Line 118: input(type = input.bool) → input.bool()
  • Line 119: input(type = input.bool) → input.bool()
  • Line 121: input(type = input.integer) → input.int()
  • Line 122: input(type = input.integer) → input.int()
  • Line 123: input(type = input.integer) → input.int()
  • Line 124: input(type = input.integer) → input.int()
  • Line 125: input(type = input.integer) → input.int()
  • Line 126: input(type = input.integer) → input.int()
  • Line 136: rsi → ta.rsi
  • Line 137: sma → ta.sma
⋯// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version = 4+// @version = 5// @author  = The_Caretaker⋯strategy("Triple Threat", overlay=false, precision=2, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100000, pyramiding=0)-i_priceSrc      = input ( close,            "Price Source", input.source,       group = "General Properties" )+i_priceSrc      = input.source ( close,            "Price Source",       group = "General Properties" )-show_rsi = input(true, 'Show RSI?', type=input.bool, group="General Properties")+show_rsi = input.bool(true, 'Show RSI?', group="General Properties")-show_bbwp = input(true, 'Show BBWP?', type=input.bool, group="General Properties")+show_bbwp = input.bool(true, 'Show BBWP?', group="General Properties")-show_signals = input(true, 'Show Signals?', type=input.bool, group="General Properties")+show_signals = input.bool(true, 'Show Signals?', group="General Properties")-show_unconfirmed = input(true, 'Show Unconfirmed Signals?', type=input.bool, group="General Properties")+show_unconfirmed = input.bool(true, 'Show Unconfirmed Signals?', group="General Properties")///////////////////////////////////////////////////////////////////////////////⋯                                                              -i_basisType     = input ( "SMA",            "Basis Type",   input.string,  options = [ "SMA", "EMA", "VWMA" ],                          group = "BBWP Properties" )+i_basisType     = input.string ( "SMA",            "Basis Type",  options = [ "SMA", "EMA", "VWMA" ],                          group = "BBWP Properties" )-i_bbwpLen       = input ( 21,               "Length",       input.integer, minval  = 1,                                                 group = "BBWP Properties" )+i_bbwpLen       = input.int ( 21,               "Length", minval  = 1,                                                 group = "BBWP Properties" )-i_bbwpLkbk      = input ( 255,              "Lookback",     input.integer, minval  = 1,                                                 group = "BBWP Properties" )+i_bbwpLkbk      = input.int ( 255,              "Lookback", minval  = 1,                                                 group = "BBWP Properties" )-i_c_bbwpTyped   = input ( "Spectrum",       "Color Type",   input.string,  options = [ "Spectrum", "Solid" ],           inline = "1",   group = "BBWP Plot Settings" )+i_c_bbwpTyped   = input.string ( "Spectrum",       "Color Type",  options = [ "Spectrum", "Solid" ],           inline = "1",   group = "BBWP Plot Settings" )-i_c_spctrmType  = input ( "Blue Green Red", "Spectrum",     input.string,  options = [ "Blue Red", "Blue Green Red"],   inline = "1",   group = "BBWP Plot Settings" )+i_c_spctrmType  = input.string ( "Blue Green Red", "Spectrum",  options = [ "Blue Red", "Blue Green Red"],   inline = "1",   group = "BBWP Plot Settings" )-i_c_bbwpsolid   = input ( #FFFF00,          "Solid",        input.color,                                                inline = "1",   group = "BBWP Plot Settings" )+i_c_bbwpsolid   = input.color ( #FFFF00,          "Solid",                                                inline = "1",   group = "BBWP Plot Settings" )-i_bbwpWidth     = input ( 2,                "Line Width",   input.integer, minval  = 1, maxval = 4,                     inline = "2",   group = "BBWP Plot Settings" )+i_bbwpWidth     = input.int ( 2,                "Line Width", minval  = 1, maxval = 4,                     inline = "2",   group = "BBWP Plot Settings" )-i_ma1On         = input ( true,             "",             input.bool,                                                 inline = "1",   group = "Moving Average Settings" )+i_ma1On         = input.bool ( true,             "",                                                 inline = "1",   group = "Moving Average Settings" )-i_ma1Type       = input ( "SMA",            "MA 1 Type",    input.string,  options = [ "SMA", "EMA", "VWMA" ],          inline = "1",   group = "Moving Average Settings" )+i_ma1Type       = input.string ( "SMA",            "MA 1 Type",  options = [ "SMA", "EMA", "VWMA" ],          inline = "1",   group = "Moving Average Settings" )-i_c_ma1         = input ( #FFFFFF,          "",             input.color,                                                inline = "1",   group = "Moving Average Settings" )+i_c_ma1         = input.color ( #FFFFFF,          "",                                                inline = "1",   group = "Moving Average Settings" )-i_ma1Len        = input ( 8,                "Length",       input.integer, minval  = 1,                                 inline = "1",   group = "Moving Average Settings" )+i_ma1Len        = input.int ( 8,                "Length", minval  = 1,                                 inline = "1",   group = "Moving Average Settings" )///////////////////////////////////////////////////////////////////////////////⋯// function declarations-f_maType ( price, len, type ) => type == "SMA" ? sma ( price, len ) : type == "EMA" ? ema ( price, len ) : vwma ( price, len )+f_maType ( price, len, type_ ) => type_ == "SMA" ? ta.sma ( price, len ) : type_ == "EMA" ? ta.ema ( price, len ) : ta.vwma ( price, len )    -f_bbwp ( price, bbwLen, bbwpLen, type ) =>+f_bbwp ( price, bbwLen, bbwpLen, type_ ) =>-    float basis = f_maType ( price, bbwLen, type )+    float basis = f_maType ( price, bbwLen, type_ )-    float dev = stdev ( price, bbwLen )+    float dev = ta.stdev ( price, bbwLen )    _bbw = (( basis + dev ) - ( basis - dev )) / basis⋯        _bbwSum := _bbwSum + ( _bbw [i] > _bbw ? 0 : 1 )-    return = ( _bbwSum / i_bbwpLkbk ) * 100+    return_ = ( _bbwSum / i_bbwpLkbk ) * 100-f_clrSlct ( percent, select, type, solid, array1, array2 ) => select == "Solid" ? solid : array.get ( type == "Blue Green Red" ? array1 : array2, round ( percent ) )+f_clrSlct ( percent, select, type_, solid, array1, array2 ) => select == "Solid" ? solid : array.get ( type_ == "Blue Green Red" ? array1 : array2, math.round ( percent ) )/////////////////////////////////////////////////////////////////////////////// ⋯rsi_ma_length = input (7, 'RSI MA Length', group='RSI Settings')-crossover_threshold = input (5, 'Crossover Threshold', type=input.float, group='RSI Strategy Settings')+crossover_threshold = input.float (5, 'Crossover Threshold', group='RSI Strategy Settings')-retest_threshold = input (3, 'Retest Threshold',  type=input.float, group='RSI Strategy Settings')+retest_threshold = input.float (3, 'Retest Threshold', group='RSI Strategy Settings')-instant_threshold = input (12, 'Instant Signal Threshold',  type=input.float, group='RSI Strategy Settings')+instant_threshold = input.float (12, 'Instant Signal Threshold', group='RSI Strategy Settings')-confirmation_ma_basisType     = input ( "EMA", "Moving Average Type", input.string,  options = [ "SMA", "EMA", "VWMA" ], group = "Confirmation Moving Average Properties")+confirmation_ma_basisType     = input.string ( "EMA", "Moving Average Type",  options = [ "SMA", "EMA", "VWMA" ], group = "Confirmation Moving Average Properties")-confirmation_ma_length    = input (50, "Moving Average Length", input.integer, group = "Confirmation Moving Average Properties")+confirmation_ma_length    = input.int (50, "Moving Average Length", group = "Confirmation Moving Average Properties")-oversold_level = input (35, 'Oversold Level',  type=input.float, group='RSI Strategy Settings')+oversold_level = input.float (35, 'Oversold Level', group='RSI Strategy Settings')-overbought_level = input (65, 'Overbought Level',  type=input.float, group='RSI Strategy Settings')+overbought_level = input.float (65, 'Overbought Level', group='RSI Strategy Settings')-bbwp_threshold = input (4, 'BBWP Confirmation Threshold', type=input.float, group='RSI Strategy Settings')+bbwp_threshold = input.float (4, 'BBWP Confirmation Threshold', group='RSI Strategy Settings')-enable_stoploss = input(false, 'Enable Stoploss?', type=input.bool, group="Other Strategy Settings")+enable_stoploss = input.bool(false, 'Enable Stoploss?', group="Other Strategy Settings")-stoploss = input(0.07, 'Stop Loss %', type=input.float, group="Other Strategy Settings")+stoploss = input.float(0.07, 'Stop Loss %', group="Other Strategy Settings")-enable_takeprofit = input(false, 'Enable Takeprofit?', type=input.bool, group="Other Strategy Settings")+enable_takeprofit = input.bool(false, 'Enable Takeprofit?', group="Other Strategy Settings")-takeprofit = input(0.55, 'Take Profit %', type=input.float, group="Other Strategy Settings")+takeprofit = input.float(0.55, 'Take Profit %', group="Other Strategy Settings")-enable_long = input(true, 'Enable Long Positions?', type=input.bool, group="Other Strategy Settings")+enable_long = input.bool(true, 'Enable Long Positions?', group="Other Strategy Settings")-enable_short = input(true, 'Enable Short Positions?', type=input.bool, group="Other Strategy Settings")+enable_short = input.bool(true, 'Enable Short Positions?', group="Other Strategy Settings")// allow start and end dates-startDate = input(title="Start Date (set any start time to 0 for furthest date)", type=input.integer, defval=1, minval=0, maxval=31, group="Timeframe")+startDate = input.int(title="Start Date (set any start time to 0 for furthest date)", defval=1, minval=0, maxval=31, group="Timeframe")-startMonth = input(title="Start Month (set any start time to 0 for furthest date)", type=input.integer, defval=1, minval=0, maxval=12, group="Timeframe")+startMonth = input.int(title="Start Month (set any start time to 0 for furthest date)", defval=1, minval=0, maxval=12, group="Timeframe")-startYear = input(title="Start Year (set any start time to 0 for furthest date)", type=input.integer, defval=2019, minval=0, maxval=2100, group="Timeframe")+startYear = input.int(title="Start Year (set any start time to 0 for furthest date)", defval=2019, minval=0, maxval=2100, group="Timeframe")-endDate = input(title="End Date (set any end time to 0 for today's date)", type=input.integer, defval=0, minval=0, maxval=31, group="Timeframe")+endDate = input.int(title="End Date (set any end time to 0 for today's date)", defval=0, minval=0, maxval=31, group="Timeframe")-endMonth = input(title="End Month (set any end time to 0 for today's date)", type=input.integer, defval=0, minval=0, maxval=12, group="Timeframe")+endMonth = input.int(title="End Month (set any end time to 0 for today's date)", defval=0, minval=0, maxval=12, group="Timeframe")-endYear = input(title="End Year (set any end time to 0 for today's date)", type=input.integer, defval=0, minval=0, maxval=2100, group="Timeframe")+endYear = input.int(title="End Year (set any end time to 0 for today's date)", defval=0, minval=0, maxval=2100, group="Timeframe")inDateRange = false⋯    inDateRange := (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))-rsi = rsi(i_priceSrc, rsi_length)+rsi = ta.rsi(i_priceSrc, rsi_length)-rsi_ma = sma(rsi, rsi_ma_length)+rsi_ma = ta.sma(rsi, rsi_ma_length)rsi_crossed_up = false⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 104: input() → input.int()
  • Line 105: input() → input.int()
  • Line 213: when = ma_buy_signal → if block
  • Line 215: when = ma_buy_signal → if block
  • Line 217: when = ma_sell_signal → if block
  • Line 219: when = ma_sell_signal → if block
6 more edits
  • Line 222: when = strategy.position_size > 0 → if block
  • Line 223: when = strategy.position_size < 0 → if block
  • Line 225: when = strategy.position_size > 0 → if block
  • Line 226: when = strategy.position_size < 0 → if block
  • Line 228: when = strategy.position_size > 0 → if block
  • Line 229: when = strategy.position_size < 0 → if block
⋯//////////////////////////////////////////////////////////////////////////////-rsi_length = input (14, 'RSI Length', group='RSI Settings')+rsi_length = input.int (14, 'RSI Length', group='RSI Settings')-rsi_ma_length = input (7, 'RSI MA Length', group='RSI Settings')+rsi_ma_length = input.int (7, 'RSI MA Length', group='RSI Settings')crossover_threshold = input.float (5, 'Crossover Threshold', group='RSI Strategy Settings')⋯    if enable_long-        strategy.entry('Long', strategy.long, when=ma_buy_signal, alert_message="BUY signal on BTCUSD")+        if ma_buy_signal+            strategy.entry('Long', strategy.long, alert_message="BUY signal on BTCUSD")    else-        strategy.close('Short', when=ma_buy_signal, alert_message="BUY signal on BTCUSD")+        if ma_buy_signal+            strategy.close('Short', alert_message="BUY signal on BTCUSD")    if enable_short-        strategy.entry('Short', strategy.short, when=ma_sell_signal, alert_message="SELL signal on BTCUSD")+        if ma_sell_signal+            strategy.entry('Short', strategy.short, alert_message="SELL signal on BTCUSD")    else-        strategy.close('Long', when=ma_sell_signal, alert_message="SELL signal on BTCUSD")+        if ma_sell_signal+            strategy.close('Long', alert_message="SELL signal on BTCUSD")        if enable_stoploss and enable_takeprofit-        strategy.exit('SL/TP Long', 'Long', stop=strategy.position_avg_price * (1 - stoploss), limit=strategy.position_avg_price * (1 + takeprofit), when=strategy.position_size > 0, alert_message="SL/TP reached on BTCUSD")+        if strategy.position_size > 0+            strategy.exit('SL/TP Long', 'Long', stop=strategy.position_avg_price * (1 - stoploss), limit=strategy.position_avg_price * (1 + takeprofit), alert_message="SL/TP reached on BTCUSD")-        strategy.exit('SL/TP Short', 'Short', stop=strategy.position_avg_price * (1 + stoploss), limit=strategy.position_avg_price * (1 - takeprofit), when=strategy.position_size < 0, alert_message="SL/TP reached on BTCUSD")+        if strategy.position_size < 0+            strategy.exit('SL/TP Short', 'Short', stop=strategy.position_avg_price * (1 + stoploss), limit=strategy.position_avg_price * (1 - takeprofit), alert_message="SL/TP reached on BTCUSD")    else if enable_stoploss-        strategy.exit('SL Long', 'Long', stop=strategy.position_avg_price * (1 - stoploss), when=strategy.position_size > 0, alert_message="SL/TP reached on BTCUSD")+        if strategy.position_size > 0+            strategy.exit('SL Long', 'Long', stop=strategy.position_avg_price * (1 - stoploss), alert_message="SL/TP reached on BTCUSD")-        strategy.exit('SL Short', 'Short', stop=strategy.position_avg_price * (1 + stoploss), when=strategy.position_size < 0, alert_message="SL/TP reached on BTCUSD")+        if strategy.position_size < 0+            strategy.exit('SL Short', 'Short', stop=strategy.position_avg_price * (1 + stoploss), alert_message="SL/TP reached on BTCUSD")    else if enable_takeprofit-        strategy.exit('TP Long', 'Long', limit=strategy.position_avg_price * (1 + takeprofit), when=strategy.position_size > 0, alert_message="SL/TP reached on BTCUSD")+        if strategy.position_size > 0+            strategy.exit('TP Long', 'Long', limit=strategy.position_avg_price * (1 + takeprofit), alert_message="SL/TP reached on BTCUSD")-        strategy.exit('TP Short', 'Short', limit=strategy.position_avg_price * (1 - takeprofit), when=strategy.position_size < 0, alert_message="SL/TP reached on BTCUSD")+        if strategy.position_size < 0+            strategy.exit('TP Short', 'Short', limit=strategy.position_avg_price * (1 - takeprofit), alert_message="SL/TP reached on BTCUSD")

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: 21 before, 19 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.

⋯// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version = 5+// @version = 6// @author  = The_Caretaker⋯

Settings

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

SettingDefaultType and rangeFeeds
General Properties
Price Sourceclosesourcebbwp rsi confirmation_ma ma_buy_zone ma_sell_zone
Show RSI?trueboolp_oversold p_overbought RSI RSI MA hline
Show BBWP?trueboolBBWP MA 1
Show Signals?trueboolRSI Buy Signal RSI Sell Signal RSI Confirmed Buy Signal RSI Confirmed Sell Signal Fully Confirmed Buy Signal Fully Confirmed Sell Signal
Show Unconfirmed Signals?trueboolRSI Buy Signal RSI Sell Signal RSI Confirmed Buy Signal RSI Confirmed Sell Signal
BBWP Properties
Basis TypeSMAstring · options [ "SMA", "EMA", "VWMA" ]bbwp
Length21int · min 1bbwp
Lookback255int · min 1return bbwp
BBWP Plot Settings
Color TypeSpectrumstring · options [ "Spectrum", "Solid" ]c_bbwp
SpectrumBlue Green Redstring · options [ "Blue Red", "Blue Green Red"]c_bbwp
Solid#FFFF00valuec_bbwp
Line Width2int · min 1 · max 4unused
Moving Average Settings
I ma1On (no label in the script)trueboolbbwpMA1
MA 1 TypeSMAstring · options [ "SMA", "EMA", "VWMA" ]bbwpMA1
I c ma1 (no label in the script)#FFFFFFvalueMA 1
Length8int · min 1bbwpMA1
RSI Settings
RSI Length14intrsi
RSI MA Length7intrsi_ma
RSI Strategy Settings
Crossover Threshold5floatrsi_crossed_up rsi_retest_buy rsi_crossed_down rsi_retest_sell
Retest Threshold3floatrsi_crossed_up rsi_retested_up rsi_crossed_down rsi_retested_down
Instant Signal Threshold12floatrsi_retest_buy rsi_retest_sell
Oversold Level35floatforward_buy_confirmation allow_buy p_oversold hline
Overbought Level65floatforward_sell_confirmation allow_sell p_overbought hline
BBWP Confirmation Threshold4floatbbwp_confirmation
Confirmation Moving Average Properties
Moving Average TypeEMAstring · options [ "SMA", "EMA", "VWMA" ]confirmation_ma
Moving Average Length50intconfirmation_ma
Other Strategy Settings
Enable Stoploss?falseboolexit SL/TP Long exit SL/TP Short exit SL Long exit SL Short line 221 line 224
Stop Loss %0.07floatexit SL/TP Long exit SL/TP Short exit SL Long exit SL Short
Enable Takeprofit?falseboolexit SL/TP Long exit SL/TP Short exit TP Long exit TP Short line 221 line 227
Take Profit %0.55floatexit SL/TP Long exit SL/TP Short exit TP Long exit TP Short
Enable Long Positions?trueboolentry Long close Short line 212
Enable Short Positions?trueboolentry Short close Long line 216
Timeframe
Start Date (set any start time to 0 for furthest date)1int (written input.integer) · min 0 · max 31inDateRange line 128 line 132
Start Month (set any start time to 0 for furthest date)1int (written input.integer) · min 0 · max 12inDateRange line 128 line 132
Start Year (set any start time to 0 for furthest date)2019int (written input.integer) · min 0 · max 2100inDateRange line 128 line 132
End Date (set any end time to 0 for today's date)0int (written input.integer) · min 0 · max 31inDateRange line 128 line 130
End Month (set any end time to 0 for today's date)0int (written input.integer) · min 0 · max 12inDateRange line 128 line 130
End Year (set any end time to 0 for today's date)0int (written input.integer) · min 0 · max 2100inDateRange line 128 line 130

What it calculates

  • Stdev (stdev, ta.stdev in v5)price, bbwLendev · line 89
  • RSI (rsi, ta.rsi in v5)Price Source (close), RSI Length (14)rsi · line 136
  • SMA (sma, ta.sma in v5)rsi, RSI MA Length (7)rsi_ma · line 137

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

Order rules

OrderFires whenBy defaultLine
Open Long longma_buy_signalma_full_buy_zone and not ma_full_buy_zone[1]On “Enable Long Positions?”213
Close Shortma_buy_signalma_full_buy_zone and not ma_full_buy_zone[1]On “Enable Long Positions?”215
Open Short shortma_sell_signalma_full_sell_zone and not ma_full_sell_zone[1]On “Enable Short Positions?”217
Close Longma_sell_signalma_full_sell_zone and not ma_full_sell_zone[1]On “Enable Short Positions?”219
Exit SL/TP Long stop and limitstrategy.position_size > 0On222
Exit SL/TP Short stop and limitstrategy.position_size < 0On223
Exit SL Long stopstrategy.position_size > 0Off “Enable Stoploss?”225
Exit SL Short stopstrategy.position_size < 0Off “Enable Stoploss?”226
Exit TP Long limitstrategy.position_size > 0Off “Enable Takeprofit?”228
Exit TP Short limitstrategy.position_size < 0Off “Enable Takeprofit?”229

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

Does it repaint?

No

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

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

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

Other markets

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

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−25.4%+102.5%2133%0.7057.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+14.1%+5.5%2642%1.3414.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+75.7%+9.8%2045%1.5646.8%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+27.9%+8.4%2133%1.5317.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−20.8%+16.7%2040%0.8579.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−4.4%+21.5%2133%0.9331.5%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−61.9%+148.3%2133%0.3083.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−9.6%+17.1%2737%0.7721.4%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 market617%−$37,339.30
Sideways market1338%$10,819.80
Falling market250%$1,134.25

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

How bad could the drawdown be?

61.7%

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

0%71%
All 21 trades
SideEntryExitBarsP&L
short16 Apr 2024 63,420.0021 May 2024 71,446.6035−$12,656.30
long21 May 2024 71,446.6024 Jun 2024 63,210.0034−$10,069.30
short24 Jun 2024 63,210.0016 Jul 2024 64,724.1022−$1,850.93
long16 Jul 2024 64,724.103 Aug 2024 61,498.3018−$3,758.95
short3 Aug 2024 61,498.3024 Aug 2024 64,037.2021−$2,958.60
long24 Aug 2024 64,037.207 Sep 2024 53,963.0014−$10,808.70
short7 Sep 2024 53,963.0019 Sep 2024 61,760.0012−$8,365.46
long19 Sep 2024 61,760.002 Oct 2024 60,804.9013−$765.96
short2 Oct 2024 60,804.9016 Oct 2024 67,074.1014−$5,027.94
long16 Oct 2024 67,074.1031 Dec 2024 92,792.1076$16,770.20
short31 Dec 2024 92,792.1022 Apr 2025 87,516.20112$3,440.27
long22 Apr 2025 87,516.2022 Jun 2025 102,120.0061$10,671.00
short22 Jun 2025 102,120.0011 Jul 2025 116,010.0019−$10,149.40
long11 Jul 2025 116,010.003 Aug 2025 112,546.0023−$1,924.85
short3 Aug 2025 112,546.0014 Aug 2025 123,306.0011−$5,979.67
long14 Aug 2025 123,306.0011 Oct 2025 112,774.0058−$4,831.41
short11 Oct 2025 112,774.0015 Jan 2026 96,951.8096$7,258.48
long15 Jan 2026 96,951.8021 Jan 2026 88,427.706−$5,186.69
short21 Jan 2026 88,427.7016 Mar 2026 72,815.3054$9,499.71
long16 Mar 2026 72,815.3023 May 2026 75,539.5068$2,368.46
short23 May 2026 75,539.5021 Jul 2026 65,255.5059$8,940.88

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
Triple Threat this page—v4 strategy−25.4%2157.4%
Bottom catch strategy by footlzsma stdev rsiv4 strategy+3.9%37.1%
Madri by Mdemoiorsi sma stdevv4 strategy+25.0%436.4%
Bollinger Bands and RSI Short Selling (by Coinrule) by Coinrulesma stdev rsiv5 strategy+7.6%34.3%
Shorting when Bollinger Band Above Price with RSI (by Coinrule) by Coinrulesma stdev rsiv5 strategyNo trades on this market
RSI_Boll-TP-SL by BigCoinHuntersma stdev rsiv5 strategyNo trades on this market

Where it runs

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

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

Source

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

//////////////////////////////////////////////////////////////////////////////// The following is code by The_Caretaker used to create the BBWP indicator. // Shoutout to The_Caretaker as well as the rest of the Krown Crypto team.// Past this section is original code.//// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// @version = 4// @author  = The_Caretaker// © The_Caretaker//// Much respect to John A Bollinger the creator of Bollinger Bands® and Bollinger Band Width indicators.// // Feel free to reuse or develop this script further, please drop me a note below if you find it useful.//strategy("Triple Threat", overlay=false, precision=2, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100000, pyramiding=0)i_priceSrc      = input ( close,            "Price Source", input.source,       group = "General Properties" )show_rsi = input(true, 'Show RSI?', type=input.bool, group="General Properties")show_bbwp = input(true, 'Show BBWP?', type=input.bool, group="General Properties")show_signals = input(true, 'Show Signals?', type=input.bool, group="General Properties")show_unconfirmed = input(true, 'Show Unconfirmed Signals?', type=input.bool, group="General Properties")///////////////////////////////////////////////////////////////////////////////// inputs                                                              i_basisType     = input ( "SMA",            "Basis Type",   input.string,  options = [ "SMA", "EMA", "VWMA" ],                          group = "BBWP Properties" )i_bbwpLen       = input ( 21,               "Length",       input.integer, minval  = 1,                                                 group = "BBWP Properties" )i_bbwpLkbk      = input ( 255,              "Lookback",     input.integer, minval  = 1,                                                 group = "BBWP Properties" )i_c_bbwpTyped   = input ( "Spectrum",       "Color Type",   input.string,  options = [ "Spectrum", "Solid" ],           inline = "1",   group = "BBWP Plot Settings" )i_c_spctrmType  = input ( "Blue Green Red", "Spectrum",     input.string,  options = [ "Blue Red", "Blue Green Red"],   inline = "1",   group = "BBWP Plot Settings" )i_c_bbwpsolid   = input ( #FFFF00,          "Solid",        input.color,                                                inline = "1",   group = "BBWP Plot Settings" )i_bbwpWidth     = input ( 2,                "Line Width",   input.integer, minval  = 1, maxval = 4,                     inline = "2",   group = "BBWP Plot Settings" )i_ma1On         = input ( true,             "",             input.bool,                                                 inline = "1",   group = "Moving Average Settings" )i_ma1Type       = input ( "SMA",            "MA 1 Type",    input.string,  options = [ "SMA", "EMA", "VWMA" ],          inline = "1",   group = "Moving Average Settings" )i_c_ma1         = input ( #FFFFFF,          "",             input.color,                                                inline = "1",   group = "Moving Average Settings" )i_ma1Len        = input ( 8,                "Length",       input.integer, minval  = 1,                                 inline = "1",   group = "Moving Average Settings" )///////////////////////////////////////////////////////////////////////////////// variable declarationsvar c_prcntSpctrm1 = array.new_color ( na )if barstate.isfirst    array.push ( c_prcntSpctrm1, #0000FF ),    array.push ( c_prcntSpctrm1, #000AFF ), array.push ( c_prcntSpctrm1, #0014FF ), array.push ( c_prcntSpctrm1, #001FFF ), array.push ( c_prcntSpctrm1, #0029FF ), array.push ( c_prcntSpctrm1, #0033FF ),    array.push ( c_prcntSpctrm1, #003DFF ), array.push ( c_prcntSpctrm1, #0047FF ), array.push ( c_prcntSpctrm1, #0052FF ), array.push ( c_prcntSpctrm1, #005CFF ), array.push ( c_prcntSpctrm1, #0066FF ),    array.push ( c_prcntSpctrm1, #0070FF ), array.push ( c_prcntSpctrm1, #007AFF ), array.push ( c_prcntSpctrm1, #0085FF ), array.push ( c_prcntSpctrm1, #008FFF ), array.push ( c_prcntSpctrm1, #0099FF ),     array.push ( c_prcntSpctrm1, #00A3FF ), array.push ( c_prcntSpctrm1, #00ADFF ), array.push ( c_prcntSpctrm1, #00B8FF ), array.push ( c_prcntSpctrm1, #00C2FF ), array.push ( c_prcntSpctrm1, #00CCFF ),     array.push ( c_prcntSpctrm1, #00D6FF ), array.push ( c_prcntSpctrm1, #00E0FF ), array.push ( c_prcntSpctrm1, #00EBFF ), array.push ( c_prcntSpctrm1, #00F5FF ), array.push ( c_prcntSpctrm1, #00FFFF ),     array.push ( c_prcntSpctrm1, #00FFF5 ), array.push ( c_prcntSpctrm1, #00FFEB ), array.push ( c_prcntSpctrm1, #00FFE0 ), array.push ( c_prcntSpctrm1, #00FFD6 ), array.push ( c_prcntSpctrm1, #00FFCC ),     array.push ( c_prcntSpctrm1, #00FFC2 ), array.push ( c_prcntSpctrm1, #00FFB8 ), array.push ( c_prcntSpctrm1, #00FFAD ), array.push ( c_prcntSpctrm1, #00FFA3 ), array.push ( c_prcntSpctrm1, #00FF99 ),     array.push ( c_prcntSpctrm1, #00FF8F ), array.push ( c_prcntSpctrm1, #00FF85 ), array.push ( c_prcntSpctrm1, #00FF7A ), array.push ( c_prcntSpctrm1, #00FF70 ), array.push ( c_prcntSpctrm1, #00FF66 ),     array.push ( c_prcntSpctrm1, #00FF5C ), array.push ( c_prcntSpctrm1, #00FF52 ), array.push ( c_prcntSpctrm1, #00FF47 ), array.push ( c_prcntSpctrm1, #00FF3D ), array.push ( c_prcntSpctrm1, #00FF33 ),     array.push ( c_prcntSpctrm1, #00FF29 ), array.push ( c_prcntSpctrm1, #00FF1F ), array.push ( c_prcntSpctrm1, #00FF14 ), array.push ( c_prcntSpctrm1, #00FF0A ), array.push ( c_prcntSpctrm1, #00FF00 ),     array.push ( c_prcntSpctrm1, #0AFF00 ), array.push ( c_prcntSpctrm1, #14FF00 ), array.push ( c_prcntSpctrm1, #1FFF00 ), array.push ( c_prcntSpctrm1, #29FF00 ), array.push ( c_prcntSpctrm1, #33FF00 ),     array.push ( c_prcntSpctrm1, #3DFF00 ), array.push ( c_prcntSpctrm1, #47FF00 ), array.push ( c_prcntSpctrm1, #52FF00 ), array.push ( c_prcntSpctrm1, #5CFF00 ), array.push ( c_prcntSpctrm1, #66FF00 ),     array.push ( c_prcntSpctrm1, #70FF00 ), array.push ( c_prcntSpctrm1, #7AFF00 ), array.push ( c_prcntSpctrm1, #85FF00 ), array.push ( c_prcntSpctrm1, #8FFF00 ), array.push ( c_prcntSpctrm1, #99FF00 ),     array.push ( c_prcntSpctrm1, #A3FF00 ), array.push ( c_prcntSpctrm1, #ADFF00 ), array.push ( c_prcntSpctrm1, #B8FF00 ), array.push ( c_prcntSpctrm1, #C2FF00 ), array.push ( c_prcntSpctrm1, #CCFF00 ),     array.push ( c_prcntSpctrm1, #D6FF00 ), array.push ( c_prcntSpctrm1, #E0FF00 ), array.push ( c_prcntSpctrm1, #EBFF00 ), array.push ( c_prcntSpctrm1, #F5FF00 ), array.push ( c_prcntSpctrm1, #FFFF00 ),     array.push ( c_prcntSpctrm1, #FFF500 ), array.push ( c_prcntSpctrm1, #FFEB00 ), array.push ( c_prcntSpctrm1, #FFE000 ), array.push ( c_prcntSpctrm1, #FFD600 ), array.push ( c_prcntSpctrm1, #FFCC00 ),     array.push ( c_prcntSpctrm1, #FFC200 ), array.push ( c_prcntSpctrm1, #FFB800 ), array.push ( c_prcntSpctrm1, #FFAD00 ), array.push ( c_prcntSpctrm1, #FFA300 ), array.push ( c_prcntSpctrm1, #FF9900 ),     array.push ( c_prcntSpctrm1, #FF8F00 ), array.push ( c_prcntSpctrm1, #FF8500 ), array.push ( c_prcntSpctrm1, #FF7A00 ), array.push ( c_prcntSpctrm1, #FF7000 ), array.push ( c_prcntSpctrm1, #FF6600 ),     array.push ( c_prcntSpctrm1, #FF5C00 ), array.push ( c_prcntSpctrm1, #FF5200 ), array.push ( c_prcntSpctrm1, #FF4700 ), array.push ( c_prcntSpctrm1, #FF3D00 ), array.push ( c_prcntSpctrm1, #FF3300 ),     array.push ( c_prcntSpctrm1, #FF2900 ), array.push ( c_prcntSpctrm1, #FF1F00 ), array.push ( c_prcntSpctrm1, #FF1400 ), array.push ( c_prcntSpctrm1, #FF0000 ), array.push ( c_prcntSpctrm1, #FF0000 )var c_prcntSpctrm2 = array.new_color ( na )if barstate.isfirst    array.push ( c_prcntSpctrm2, #0000FF ),    array.push ( c_prcntSpctrm2, #0200FC ), array.push ( c_prcntSpctrm2, #0500F9 ), array.push ( c_prcntSpctrm2, #0700F7 ), array.push ( c_prcntSpctrm2, #0A00F4 ), array.push ( c_prcntSpctrm2, #0C00F2 ),     array.push ( c_prcntSpctrm2, #0F00EF ), array.push ( c_prcntSpctrm2, #1100ED ), array.push ( c_prcntSpctrm2, #1400EA ), array.push ( c_prcntSpctrm2, #1600E8 ), array.push ( c_prcntSpctrm2, #1900E5 ),     array.push ( c_prcntSpctrm2, #1C00E2 ), array.push ( c_prcntSpctrm2, #1E00E0 ), array.push ( c_prcntSpctrm2, #2100DD ), array.push ( c_prcntSpctrm2, #2300DB ), array.push ( c_prcntSpctrm2, #2600D8 ),    array.push ( c_prcntSpctrm2, #2800D6 ), array.push ( c_prcntSpctrm2, #2B00D3 ), array.push ( c_prcntSpctrm2, #2D00D1 ), array.push ( c_prcntSpctrm2, #3000CE ), array.push ( c_prcntSpctrm2, #3300CC ),    array.push ( c_prcntSpctrm2, #3500C9 ), array.push ( c_prcntSpctrm2, #3800C6 ), array.push ( c_prcntSpctrm2, #3A00C4 ), array.push ( c_prcntSpctrm2, #3D00C1 ), array.push ( c_prcntSpctrm2, #3F00BF ),     array.push ( c_prcntSpctrm2, #4200BC ), array.push ( c_prcntSpctrm2, #4400BA ), array.push ( c_prcntSpctrm2, #4700B7 ), array.push ( c_prcntSpctrm2, #4900B5 ), array.push ( c_prcntSpctrm2, #4C00B2 ),    array.push ( c_prcntSpctrm2, #4F00AF ), array.push ( c_prcntSpctrm2, #5100AD ), array.push ( c_prcntSpctrm2, #5400AA ), array.push ( c_prcntSpctrm2, #5600A8 ), array.push ( c_prcntSpctrm2, #5900A5 ),     array.push ( c_prcntSpctrm2, #5B00A3 ), array.push ( c_prcntSpctrm2, #5E00A0 ), array.push ( c_prcntSpctrm2, #60009E ), array.push ( c_prcntSpctrm2, #63009B ), array.push ( c_prcntSpctrm2, #660099 ),    array.push ( c_prcntSpctrm2, #680096 ), array.push ( c_prcntSpctrm2, #6B0093 ), array.push ( c_prcntSpctrm2, #6D0091 ), array.push ( c_prcntSpctrm2, #70008E ), array.push ( c_prcntSpctrm2, #72008C ),     array.push ( c_prcntSpctrm2, #750089 ), array.push ( c_prcntSpctrm2, #770087 ), array.push ( c_prcntSpctrm2, #7A0084 ), array.push ( c_prcntSpctrm2, #7C0082 ), array.push ( c_prcntSpctrm2, #7F007F ),    array.push ( c_prcntSpctrm2, #82007C ), array.push ( c_prcntSpctrm2, #84007A ), array.push ( c_prcntSpctrm2, #870077 ), array.push ( c_prcntSpctrm2, #890075 ), array.push ( c_prcntSpctrm2, #8C0072 ),     array.push ( c_prcntSpctrm2, #8E0070 ), array.push ( c_prcntSpctrm2, #91006D ), array.push ( c_prcntSpctrm2, #93006B ), array.push ( c_prcntSpctrm2, #960068 ), array.push ( c_prcntSpctrm2, #990066 ),    array.push ( c_prcntSpctrm2, #9B0063 ), array.push ( c_prcntSpctrm2, #9E0060 ), array.push ( c_prcntSpctrm2, #A0005E ), array.push ( c_prcntSpctrm2, #A3005B ), array.push ( c_prcntSpctrm2, #A50059 ),     array.push ( c_prcntSpctrm2, #A80056 ), array.push ( c_prcntSpctrm2, #AA0054 ), array.push ( c_prcntSpctrm2, #AD0051 ), array.push ( c_prcntSpctrm2, #AF004F ), array.push ( c_prcntSpctrm2, #B2004C ),     array.push ( c_prcntSpctrm2, #B50049 ), array.push ( c_prcntSpctrm2, #B70047 ), array.push ( c_prcntSpctrm2, #BA0044 ), array.push ( c_prcntSpctrm2, #BC0042 ), array.push ( c_prcntSpctrm2, #BF003F ),     array.push ( c_prcntSpctrm2, #C1003D ), array.push ( c_prcntSpctrm2, #C4003A ), array.push ( c_prcntSpctrm2, #C60038 ), array.push ( c_prcntSpctrm2, #C90035 ), array.push ( c_prcntSpctrm2, #CC0033 ),    array.push ( c_prcntSpctrm2, #CE0030 ), array.push ( c_prcntSpctrm2, #D1002D ), array.push ( c_prcntSpctrm2, #D3002B ), array.push ( c_prcntSpctrm2, #D60028 ), array.push ( c_prcntSpctrm2, #D80026 ),     array.push ( c_prcntSpctrm2, #DB0023 ), array.push ( c_prcntSpctrm2, #DD0021 ), array.push ( c_prcntSpctrm2, #E0001E ), array.push ( c_prcntSpctrm2, #E2001C ), array.push ( c_prcntSpctrm2, #E50019 ),    array.push ( c_prcntSpctrm2, #E80016 ), array.push ( c_prcntSpctrm2, #EA0014 ), array.push ( c_prcntSpctrm2, #ED0011 ), array.push ( c_prcntSpctrm2, #EF000F ), array.push ( c_prcntSpctrm2, #F2000C ),     array.push ( c_prcntSpctrm2, #F4000A ), array.push ( c_prcntSpctrm2, #F70007 ), array.push ( c_prcntSpctrm2, #F90005 ), array.push ( c_prcntSpctrm2, #FC0002 ), array.push ( c_prcntSpctrm2, #FF0000 )///////////////////////////////////////////////////////////////////////////////// function declarationsf_maType ( price, len, type ) => type == "SMA" ? sma ( price, len ) : type == "EMA" ? ema ( price, len ) : vwma ( price, len )    f_bbwp ( price, bbwLen, bbwpLen, type ) =>    float basis = f_maType ( price, bbwLen, type )    float dev = stdev ( price, bbwLen )    _bbw = (( basis + dev ) - ( basis - dev )) / basis    _bbwSum = 0    for i = 1 to bbwpLen        _bbwSum := _bbwSum + ( _bbw [i] > _bbw ? 0 : 1 )    return = ( _bbwSum / i_bbwpLkbk ) * 100f_clrSlct ( percent, select, type, solid, array1, array2 ) => select == "Solid" ? solid : array.get ( type == "Blue Green Red" ? array1 : array2, round ( percent ) )/////////////////////////////////////////////////////////////////////////////// // calculationsbbwp        = f_bbwp ( i_priceSrc, i_bbwpLen, i_bbwpLkbk, i_basisType )c_bbwp      = f_clrSlct ( bbwp, i_c_bbwpTyped, i_c_spctrmType, i_c_bbwpsolid, c_prcntSpctrm1, c_prcntSpctrm2 )bbwpMA1     = i_ma1On ? f_maType ( bbwp, i_ma1Len, i_ma1Type ) : na/////////////////////////////// end of code created by The_Caretaker//////////////////////////////////////////////////////////////////////////////rsi_length = input (14, 'RSI Length', group='RSI Settings')rsi_ma_length = input (7, 'RSI MA Length', group='RSI Settings')crossover_threshold = input (5, 'Crossover Threshold', type=input.float, group='RSI Strategy Settings')retest_threshold = input (3, 'Retest Threshold',  type=input.float, group='RSI Strategy Settings')instant_threshold = input (12, 'Instant Signal Threshold',  type=input.float, group='RSI Strategy Settings')confirmation_ma_basisType     = input ( "EMA", "Moving Average Type", input.string,  options = [ "SMA", "EMA", "VWMA" ], group = "Confirmation Moving Average Properties")confirmation_ma_length    = input (50, "Moving Average Length", input.integer, group = "Confirmation Moving Average Properties")oversold_level = input (35, 'Oversold Level',  type=input.float, group='RSI Strategy Settings')overbought_level = input (65, 'Overbought Level',  type=input.float, group='RSI Strategy Settings')bbwp_threshold = input (4, 'BBWP Confirmation Threshold', type=input.float, group='RSI Strategy Settings')enable_stoploss = input(false, 'Enable Stoploss?', type=input.bool, group="Other Strategy Settings")stoploss = input(0.07, 'Stop Loss %', type=input.float, group="Other Strategy Settings")enable_takeprofit = input(false, 'Enable Takeprofit?', type=input.bool, group="Other Strategy Settings")takeprofit = input(0.55, 'Take Profit %', type=input.float, group="Other Strategy Settings")enable_long = input(true, 'Enable Long Positions?', type=input.bool, group="Other Strategy Settings")enable_short = input(true, 'Enable Short Positions?', type=input.bool, group="Other Strategy Settings")// allow start and end datesstartDate = input(title="Start Date (set any start time to 0 for furthest date)", type=input.integer, defval=1, minval=0, maxval=31, group="Timeframe")startMonth = input(title="Start Month (set any start time to 0 for furthest date)", type=input.integer, defval=1, minval=0, maxval=12, group="Timeframe")startYear = input(title="Start Year (set any start time to 0 for furthest date)", type=input.integer, defval=2019, minval=0, maxval=2100, group="Timeframe")endDate = input(title="End Date (set any end time to 0 for today's date)", type=input.integer, defval=0, minval=0, maxval=31, group="Timeframe")endMonth = input(title="End Month (set any end time to 0 for today's date)", type=input.integer, defval=0, minval=0, maxval=12, group="Timeframe")endYear = input(title="End Year (set any end time to 0 for today's date)", type=input.integer, defval=0, minval=0, maxval=2100, group="Timeframe")inDateRange = falseif (endDate == 0 or endMonth == 0 or endYear == 0) and (startDate == 0 or startMonth == 0 or startYear == 0)    inDateRange := trueelse if endDate == 0 or endMonth == 0 or endYear == 0    inDateRange := time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)else if startDate == 0 or startMonth == 0 or startYear == 0    inDateRange := time <= timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0)else    inDateRange := (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))rsi = rsi(i_priceSrc, rsi_length)rsi_ma = sma(rsi, rsi_ma_length)rsi_crossed_up = falsersi_retested_up = false// start checking for upwards retests when the RSI has crossed above the MA by at least 3 pts (or the crossover_threshold) and has not fallen to 2 pts below the MA (or the retest_threshold)rsi_crossed_up := (rsi_crossed_up[1] and not (rsi_ma - rsi > retest_threshold)) or (rsi - rsi_ma > crossover_threshold)// keep of track of when a retest occured (rsi exceeds MA by less than the retest threshold), until the RSI falls below the MA by the threshold// rsi_crossed_up must be true, because this already checks if the rsi has fallen below the MA by the threshold to cancel the signalrsi_retested_up := rsi_crossed_up and (rsi_retested_up[1] or (rsi - rsi_ma < retest_threshold))// if there has been a retest and the rsi exceeds the MA by the crossover threshold again, trigger a buy signal// also trigger a buy signal if the RSI exceeds the MA by the "instant signal threshold"rsi_retest_buy = (rsi_retested_up and (rsi - rsi_ma > crossover_threshold)) or (rsi - rsi_ma > instant_threshold)// do the same thing to the downsidersi_crossed_down = falsersi_retested_down = falsersi_crossed_down := (rsi_crossed_down[1] and not (rsi - rsi_ma > retest_threshold)) or (rsi_ma - rsi > crossover_threshold)rsi_retested_down := rsi_crossed_down and (rsi_retested_down[1] or (rsi_ma - rsi < retest_threshold))rsi_retest_sell = (rsi_retested_down and (rsi_ma - rsi > crossover_threshold)) or (rsi_ma - rsi > instant_threshold)rsi_buy_zone = falsersi_buy_zone := (rsi_retest_buy or rsi_buy_zone[1]) and not rsi_retest_sellrsi_sell_zone = falsersi_sell_zone := (rsi_retest_sell or rsi_sell_zone[1]) and not rsi_retest_buy// when the sell zone switches to a buy zone or vice versarsi_buy_signal = rsi_buy_zone and rsi_sell_zone[1]rsi_sell_signal = rsi_sell_zone and rsi_buy_zone[1]// if RSI is oversold in a Buy zone, confirm the most recent Buy signal. if RSI is oversold in a Sell zone, confirm the next Buy signal.forward_buy_confirmation = false// carry over the previous confirmation unless entering a sell zone for the first timeforward_buy_confirmation := (forward_buy_confirmation[1] and not rsi_sell_signal) or rsi <= oversold_level// if RSI is overbought in a Sell zone, confirm the most recent Sell signal. if RSI is overbought in a Buy zone, confirm the next Sell signal.forward_sell_confirmation = false// carry over the previous confirmation unless entering a buy zone for the first timeforward_sell_confirmation := (forward_sell_confirmation[1] and not rsi_buy_signal) or rsi >= overbought_level// a long position may only be entered if the RSI MA is no longer below the oversold level, and RSI is now above the MAallow_buy = rsi > rsi_ma and rsi_ma > oversold_level// a short position may only be entered if the RSI MA is no longer above the overbought level, and RSI is now below the MAallow_sell = rsi < rsi_ma and rsi_ma < overbought_level// confirm any signal if BBWP > the BBWP confirmation thresholdbbwp_confirmation = bbwp - bbwpMA1 > bbwp_threshold// trade on confirmed signalsfull_buy_signal = rsi_buy_zone and (forward_buy_confirmation or bbwp_confirmation) and allow_buyfull_sell_signal = rsi_sell_zone and (forward_sell_confirmation or bbwp_confirmation) and allow_sellconfirmed_buy_zone = falseconfirmed_sell_zone = false// only enter a buy or sell zone if there was confirmation with either the RSI or BBWP, and a position is allowed based on the relative placement of the RSI and its MA (allow_buy or allow_sell)confirmed_buy_zone := (confirmed_buy_zone[1] or full_buy_signal) and not full_sell_signalconfirmed_sell_zone := (confirmed_sell_zone[1] or full_sell_signal) and not full_buy_signalconfirmed_buy_signal = confirmed_buy_zone and confirmed_sell_zone[1]confirmed_sell_signal = confirmed_sell_zone and confirmed_buy_zone[1]// EMAs and EMA signalsconfirmation_ma = f_maType ( i_priceSrc, confirmation_ma_length, confirmation_ma_basisType )ma_buy_zone = confirmed_buy_zone and (i_priceSrc > confirmation_ma)ma_sell_zone = confirmed_sell_zone and (i_priceSrc < confirmation_ma)ma_buy_confirmation = ma_buy_zone and not ma_buy_zone[1]ma_sell_confirmation = ma_sell_zone and not ma_sell_zone[1]ma_full_buy_zone = falsema_full_sell_zone = falsema_full_buy_zone := (ma_full_buy_zone[1] or ma_buy_confirmation) and not ma_sell_confirmationma_full_sell_zone := (ma_full_sell_zone[1] or ma_sell_confirmation) and not ma_buy_confirmationma_buy_signal = ma_full_buy_zone and not ma_full_buy_zone[1]ma_sell_signal = ma_full_sell_zone and not ma_full_sell_zone[1]// plotsp_oversold   = hline ( show_rsi ? oversold_level : na, "Oversold", #990000, hline.style_dashed, 1)p_overbought   = hline ( show_rsi ? overbought_level : na, "Overbought", #009900,  hline.style_dashed, 1)p_rsi_buy    = plot ( show_signals and show_unconfirmed and rsi_buy_signal ? 25 : na,    "RSI Buy Signal",   #009900,         1,      plot.style_columns,     editable = false,       histbase = 0)p_rsi_sell    = plot ( show_signals and show_unconfirmed and rsi_sell_signal ? 25 : na,   "RSI Sell Signal",  #990000,         1,      plot.style_columns,     editable = false,      histbase = 0)p_rsi_confirmed_buy    = plot ( show_signals and show_unconfirmed and confirmed_buy_signal ? 50 : na,    "RSI Confirmed Buy Signal",   #009900,         1,      plot.style_columns,     editable = false,       histbase = 0)p_rsi_confirmed_sell    = plot ( show_signals and show_unconfirmed and confirmed_sell_signal ? 50 : na,   "RSI Confirmed Sell Signal",  #990000,         1,      plot.style_columns,     editable = false,      histbase = 0)p_confirmed_buy    = plot ( show_signals and ma_buy_signal ? 100 : na,   "Fully Confirmed Buy Signal",  #00ff00,         1,      plot.style_columns,     editable = false,      histbase = 0)p_confirmed_sell    = plot ( show_signals and ma_sell_signal ? 100 : na,   "Fully Confirmed Sell Signal",  #ff0000,         1,      plot.style_columns,     editable = false,      histbase = 0)p_bbwp      = plot ( show_bbwp ? bbwp : na,      "BBWP",         c_bbwp,         1,      plot.style_line,        editable = false )p_ma1       = plot ( show_bbwp ? bbwpMA1 : na,   "MA 1",         i_c_ma1,        1,      plot.style_circles,    0 )p_rsi       = plot ( show_rsi ? rsi : na,       "RSI",          color.purple,   2)p_rsi_ma    = plot( show_rsi ? rsi_ma : na,     "RSI MA",       color.orange,   1)// position entries and exitsif inDateRange and strategy.equity > 0    if enable_long        strategy.entry('Long', strategy.long, when=ma_buy_signal, alert_message="BUY signal on BTCUSD")    else        strategy.close('Short', when=ma_buy_signal, alert_message="BUY signal on BTCUSD")    if enable_short        strategy.entry('Short', strategy.short, when=ma_sell_signal, alert_message="SELL signal on BTCUSD")    else        strategy.close('Long', when=ma_sell_signal, alert_message="SELL signal on BTCUSD")        if enable_stoploss and enable_takeprofit        strategy.exit('SL/TP Long', 'Long', stop=strategy.position_avg_price * (1 - stoploss), limit=strategy.position_avg_price * (1 + takeprofit), when=strategy.position_size > 0, alert_message="SL/TP reached on BTCUSD")        strategy.exit('SL/TP Short', 'Short', stop=strategy.position_avg_price * (1 + stoploss), limit=strategy.position_avg_price * (1 - takeprofit), when=strategy.position_size < 0, alert_message="SL/TP reached on BTCUSD")    else if enable_stoploss        strategy.exit('SL Long', 'Long', stop=strategy.position_avg_price * (1 - stoploss), when=strategy.position_size > 0, alert_message="SL/TP reached on BTCUSD")        strategy.exit('SL Short', 'Short', stop=strategy.position_avg_price * (1 + stoploss), when=strategy.position_size < 0, alert_message="SL/TP reached on BTCUSD")    else if enable_takeprofit        strategy.exit('TP Long', 'Long', limit=strategy.position_avg_price * (1 + takeprofit), when=strategy.position_size > 0, alert_message="SL/TP reached on BTCUSD")        strategy.exit('TP Short', 'Short', limit=strategy.position_avg_price * (1 - takeprofit), when=strategy.position_size < 0, alert_message="SL/TP reached on BTCUSD")