Pine Script v4 · Strategy
Bear & Bull Zone Signal Strategy
A Pine Script v4 strategy built on RSI (0, 14), EMA (rsi_ema, 14) and Highest (high, 9). It has 6 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 0.18% commission. 19 settings; defaults include Strategy Long/Short, Stop Loss % 10.0 and Target Profit % 20.0.
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 Bear & Bull Zone Signal Strategy repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Bear & Bull Zone Signal Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can Bear & Bull Zone Signal Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- Does Bear & Bull Zone Signal Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 161, 167.
- Does Bear & Bull Zone Signal Strategy run in Zeal Terminal?
- Yes
- It compiles in 30 ms and runs 1,000 bars in 136 ms, in the browser.
BTCUSDT · 1D · default settings
- K
- D
- Signal Up
- Signal Down
- Oversold
- Overbought
- RSI
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,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
ema(close, 24) ignores the settings line 126
Line 126 hard-codes 24 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 24)ema(close, length) -
Likely bug
ema(close, 38) ignores the settings line 127
Line 127 hard-codes 38 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 38)ema(close, length) -
Likely bug
ema(close, 50) ignores the settings line 128
Line 128 hard-codes 50 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 50)ema(close, length) -
Likely bug
ema(close, 62) ignores the settings line 129
Line 129 hard-codes 62 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 62)ema(close, length) -
Likely bug
ema(close, 76) ignores the settings line 130
Line 130 hard-codes 76 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 76)ema(close, length) -
Likely bug
ema(close, 100) ignores the settings line 131
Line 131 hard-codes 100 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 100)ema(close, length) -
Likely bug
ema(close, 236) ignores the settings line 132
Line 132 hard-codes 236 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 236)ema(close, length) -
Likely bug
ema(close, 382) ignores the settings line 133
Line 133 hard-codes 382 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 382)ema(close, length) -
Likely bug
ema(close, 500) ignores the settings line 134
Line 134 hard-codes 500 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 500)ema(close, length) -
Likely bug
ema(close, 618) ignores the settings line 135
Line 135 hard-codes 618 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 618)ema(close, length) -
Likely bug
ema(close, 764) ignores the settings line 136
Line 136 hard-codes 764 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 764)ema(close, length) -
Likely bug
ema(close, 1000) ignores the settings line 137
Line 137 hard-codes 1000 where line 41 uses “RSI Length”. Changing those settings moves one band but not this one.
ema(close, 1000)ema(close, length) -
Likely bug
sma(close, 24) ignores the settings line 114
Line 114 hard-codes 24 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 24)sma(close, smoothK) -
Likely bug
sma(close, 38) ignores the settings line 115
Line 115 hard-codes 38 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 38)sma(close, smoothK) -
Likely bug
sma(close, 50) ignores the settings line 116
Line 116 hard-codes 50 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 50)sma(close, smoothK) -
Likely bug
sma(close, 62) ignores the settings line 117
Line 117 hard-codes 62 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 62)sma(close, smoothK) -
Likely bug
sma(close, 76) ignores the settings line 118
Line 118 hard-codes 76 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 76)sma(close, smoothK) -
Likely bug
sma(close, 100) ignores the settings line 119
Line 119 hard-codes 100 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 100)sma(close, smoothK) -
Likely bug
sma(close, 236) ignores the settings line 120
Line 120 hard-codes 236 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 236)sma(close, smoothK) -
Likely bug
sma(close, 382) ignores the settings line 121
Line 121 hard-codes 382 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 382)sma(close, smoothK) -
Likely bug
sma(close, 500) ignores the settings line 122
Line 122 hard-codes 500 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 500)sma(close, smoothK) -
Likely bug
sma(close, 618) ignores the settings line 123
Line 123 hard-codes 618 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 618)sma(close, smoothK) -
Likely bug
sma(close, 764) ignores the settings line 124
Line 124 hard-codes 764 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 764)sma(close, smoothK) -
Likely bug
sma(close, 1000) ignores the settings line 125
Line 125 hard-codes 1000 where line 65 uses “K”. Changing those settings moves one band but not this one.
sma(close, 1000)sma(close, smoothK) -
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses transp =, which v5 removed line 54
transp = on line 54, 73, 74, 75, 78, 79, 95, 100. v5 folds the transparency into the colour with color.new(c, transp).
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 rsi → ta.rsi, ema → ta.ema, highest → ta.highest, lowest → ta.lowest, stoch → ta.stoch, wma → ta.wma, sma → ta.sma, change → ta.change, vwma → ta.vwma, round → math.round.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 2: //@version=4 → //@version=5
- Line 8: input(type = input.time) → input.time()
- Line 9: input(type = input.time) → input.time()
- Line 21: input(type = input.source) → input.source()
- Line 40: rsi → ta.rsi
- Line 41: ema → ta.ema
50 more edits
- Line 42: ema → ta.ema
- Line 43: ema → ta.ema
- Line 44: ema → ta.ema
- Line 45: ema → ta.ema
- Line 46: ema → ta.ema
- Line 54: transp = 95 → color.new(showZones ? ( ruleState==1 ? color.blue : ruleState==-1 ? color.red : color.gray ) : na, 95)
- Line 58: highest → ta.highest
- Line 59: lowest → ta.lowest
- Line 60: rsi → ta.rsi
- Line 61: stoch → ta.stoch
- Line 63: ema → ta.ema
- Line 64: wma → ta.wma
- Line 65: sma → ta.sma
- Line 66: sma → ta.sma
- Line 67: change → ta.change
- Line 68: change → ta.change
- Line 73: transp = 80 → color.new(kcolor, 80)
- Line 74: transp = 80 → color.new(dcolor, 80)
- Line 75: transp = 88 → color.new(signalColor, 88)
- Line 78: transp = 90 → color.new(kcolor, 90)
- Line 79: transp = 90 → color.new(dcolor, 90)
- Line 82: vwma → ta.vwma
- Line 83: vwma → ta.vwma
- Line 95: transp = 75 → color.new(plot_color, 75)
- Line 100: transp = 90 → color.new(#9915FF, 90)
- Line 114: sma → ta.sma
- Line 115: sma → ta.sma
- Line 116: sma → ta.sma
- Line 117: sma → ta.sma
- Line 118: sma → ta.sma
- Line 119: sma → ta.sma
- Line 120: sma → ta.sma
- Line 121: sma → ta.sma
- Line 122: sma → ta.sma
- Line 123: sma → ta.sma
- Line 124: sma → ta.sma
- Line 125: sma → ta.sma
- Line 126: ema → ta.ema
- Line 127: ema → ta.ema
- Line 128: ema → ta.ema
- Line 129: ema → ta.ema
- Line 130: ema → ta.ema
- Line 131: ema → ta.ema
- Line 132: ema → ta.ema
- Line 133: ema → ta.ema
- Line 134: ema → ta.ema
- Line 135: ema → ta.ema
- Line 136: ema → ta.ema
- Line 137: ema → ta.ema
- Line 155: round → math.round
// 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=5strategy(shorttitle='BBZS',title='Bear & Bull Zone Signal Strategy', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value=0.18, calc_on_every_tick=true)⋯//Backtest dates with auto finish date of today-start = input(defval = timestamp("01 April 2021 00:00 -0500"), title = "Start Time", type = input.time)+start = input.time(defval = timestamp("01 April 2021 00:00 -0500"), title = "Start Time")-finish = input(defval = timestamp("31 December 2021 00:00 -0600"), title = "Start Time", type = input.time)+finish = input.time(defval = timestamp("31 December 2021 00:00 -0600"), title = "Start Time")window() => time >= start and time <= finish ? true : false // create function "within window of time"⋯length = input(14, "RSI Length", minval=1)-source = input(title="RSI Source", type=input.source, defval=close)+source = input.source(title="RSI Source", defval=close)overbought= input(62, "Overbought")⋯haClose(gap) => (open[gap] + high[gap] + low[gap] + close[gap]) / 4-rsi_ema = rsi(haClose(0), length)+rsi_ema = ta.rsi(haClose(0), length)-v2 = ema(rsi_ema, length) +v2 = ta.ema(rsi_ema, length) -v3 = 2 * v2 - ema(v2, length) +v3 = 2 * v2 - ta.ema(v2, length) -emaA = ema(rsi_ema, fastLength) +emaA = ta.ema(rsi_ema, fastLength) -emaFast = 2 * emaA - ema(emaA, fastLength)+emaFast = 2 * emaA - ta.ema(emaA, fastLength)-emaB = ema(rsi_ema, slowLength) +emaB = ta.ema(rsi_ema, slowLength) -emaSlow = 2 * emaB - ema(emaB, slowLength) +emaSlow = 2 * emaB - ta.ema(emaB, slowLength) // bullish signal rule: ⋯ruleState := bullishRule ? 1 : bearishRule ? -1 : nz(ruleState[1])-bgcolor(showZones ? ( ruleState==1 ? color.blue : ruleState==-1 ? color.red : color.gray ) : na , title=" Bullish/Bearish Zones", transp=95)+bgcolor(color.new(showZones ? ( ruleState==1 ? color.blue : ruleState==-1 ? color.red : color.gray ) : na, 95) , title=" Bullish/Bearish Zones")// ------------------ Stochastic Indicator Overlay -----------------------------------------------⋯// Use highest highs and lowest lows-h_high = highest(high_source ,look_back)+h_high = ta.highest(high_source ,look_back)-l_low = lowest(low_source ,look_back)+l_low = ta.lowest(low_source ,look_back)-RSI = rsi(source, length)+RSI = ta.rsi(source, length)-stoch = stoch(RSI, RSI, RSI, length)+stoch = ta.stoch(RSI, RSI, RSI, length)k =- k_mode=="EMA" ? ema(stoch, smoothK) :+ k_mode=="EMA" ? ta.ema(stoch, smoothK) :- k_mode=="WMA" ? wma(stoch, smoothK) :+ k_mode=="WMA" ? ta.wma(stoch, smoothK) :- sma(stoch, smoothK)+ ta.sma(stoch, smoothK)-d = sma(k, smoothD)+d = ta.sma(k, smoothD)-k_c = change(k)+k_c = ta.change(k)-d_c = change(d)+d_c = ta.change(d)kd = k - d⋯ k<overbought and d>oversold and k<d and k_c<0 and d_c<0 ? dcolor : na-kp = plot(showStoch ? k : na, "K", transp=80, color=kcolor)+kp = plot(showStoch ? k : na, "K", color=color.new(kcolor, 80))-dp = plot(showStoch ? d : na, "D", transp=80, color=dcolor)+dp = plot(showStoch ? d : na, "D", color=color.new(dcolor, 80))-fill(kp, dp, color = signalColor, title="K-D", transp=88)+fill(kp, dp, color = color.new(signalColor, 88), title="K-D")signalUp = showStoch ? not na(signalColor) and kd>0 : nasignalDown = showStoch ? not na(signalColor) and kd<0 : na-plot(signalUp ? kd : na, "Signal Up", color=kcolor, transp=90, style=plot.style_columns)+plot(signalUp ? kd : na, "Signal Up", color=color.new(kcolor, 90), style=plot.style_columns)-plot(signalDown ? (kd+100) : na , "Signal Down", color=dcolor, transp=90, style=plot.style_columns, histbase=100)+plot(signalDown ? (kd+100) : na , "Signal Down", color=color.new(dcolor, 90), style=plot.style_columns, histbase=100)// -------------- Add Price Movement to Strategy for better visualization -------------------------// Calculations-h1 = vwma(high, length)+h1 = ta.vwma(high, length)-l1 = vwma(low, length)+l1 = ta.vwma(low, length)hp = h_high[1]⋯ plot_color:=color.maroon-bgcolor(plot_color, transp=75)+bgcolor(color.new(plot_color, 75))// --------------------------------------- RSI Plot ----------------------------------------------⋯under = hline(overbought, title="Overbought", color=color.red)-fill(over, under, color=#9915FF, transp=90, title="Band Background")+fill(over, under, color=color.new(#9915FF, 90), title="Band Background")// Plot colored RSI Line⋯//---------------- Fibonacci Sanity Check of Signals ----------------------------------sma24 = sma(close, 24)+sma24 = ta.sma(close, 24)-sma38 = sma(close, 38)+sma38 = ta.sma(close, 38)-sma50 = sma(close, 50)+sma50 = ta.sma(close, 50)-sma62 = sma(close, 62)+sma62 = ta.sma(close, 62)-sma76 = sma(close, 76)+sma76 = ta.sma(close, 76)-sma100 = sma(close, 100)+sma100 = ta.sma(close, 100)-sma236 = sma(close, 236)+sma236 = ta.sma(close, 236)-sma382= sma(close, 382)+sma382= ta.sma(close, 382)-sma500 = sma(close, 500)+sma500 = ta.sma(close, 500)-sma618 = sma(close, 618)+sma618 = ta.sma(close, 618)-sma764 = sma(close, 764)+sma764 = ta.sma(close, 764)-sma1000 = sma(close, 1000)+sma1000 = ta.sma(close, 1000)-ema24 = ema(close, 24)+ema24 = ta.ema(close, 24)-ema38 = ema(close, 38)+ema38 = ta.ema(close, 38)-ema50 = ema(close, 50)+ema50 = ta.ema(close, 50)-ema62 = ema(close, 62)+ema62 = ta.ema(close, 62)-ema76 = ema(close, 76)+ema76 = ta.ema(close, 76)-ema100 = ema(close, 100)+ema100 = ta.ema(close, 100)-ema236 = ema(close, 236)+ema236 = ta.ema(close, 236)-ema382= ema(close, 382)+ema382= ta.ema(close, 382)-ema500 = ema(close, 500)+ema500 = ta.ema(close, 500)-ema618 = ema(close, 618)+ema618 = ta.ema(close, 618)-ema764 = ema(close, 764)+ema764 = ta.ema(close, 764)-ema1000 = ema(close, 1000)+ema1000 = ta.ema(close, 1000)Higher50 = close > sma50 or close > ema50⋯convert_percent_to_points(percent) =>- strategy.position_size != 0 ? round(percent * strategy.position_avg_price / syminfo.mintick) : float(na)+ strategy.position_size != 0 ? math.round(percent * strategy.position_avg_price / syminfo.mintick) : float(na) ⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 12: input() → input.string()
- Line 15: input() → input.float()
- Line 17: input() → input.float()
- Line 20: input() → input.int()
- Line 22: input() → input.int()
- Line 23: input() → input.int()
10 more edits
- Line 24: input() → input.int()
- Line 25: input() → input.source()
- Line 26: input() → input.source()
- Line 28: input() → input.int()
- Line 29: input() → input.int()
- Line 30: input() → input.string()
- Line 32: input() → input.int()
- Line 33: input() → input.int()
- Line 35: input() → input.bool()
- Line 36: input() → input.bool()
⋯// Strategy Selection - Long, Short, or Both-strat = input(title="Strategy", defval="Long/Short", options=["Long Only", "Long/Short", "Short Only"])+strat = input.string(title="Strategy", defval="Long/Short", options=["Long Only", "Long/Short", "Short Only"])strat_val = strat == "Long Only" ? 1 : strat == "Long/Short" ? 0 : -1// Risk Management Inputs-sl= input(10.0, "Stop Loss %", minval = 0, maxval = 100, step = 0.01)+sl= input.float(10.0, "Stop Loss %", minval = 0, maxval = 100, step = 0.01)stoploss = sl/100-tp = input(20.0, "Target Profit %", minval = 0, maxval = 100, step = 0.01)+tp = input.float(20.0, "Target Profit %", minval = 0, maxval = 100, step = 0.01)TargetProfit = tp/100// RSI and Stochastic Inputs-length = input(14, "RSI Length", minval=1)+length = input.int(14, "RSI Length", minval=1)source = input.source(title="RSI Source", defval=close)-overbought= input(62, "Overbought")+overbought= input.int(62, "Overbought")-oversold= input(35, "Oversold")+oversold= input.int(35, "Oversold")-look_back = input(9,"Look Back Bars")+look_back = input.int(9,"Look Back Bars")-high_source = input(high,"High Source")+high_source = input.source(high,"High Source")-low_source= input(low,"Low Source")+low_source= input.source(low,"Low Source")// EMA and SMA Background Inputs-smoothK = input(3, "K", minval=1)+smoothK = input.int(3, "K", minval=1)-smoothD = input(3, "D", minval=1)+smoothD = input.int(3, "D", minval=1)-k_mode = input("SMA", "K Mode", options=["SMA", "EMA", "WMA"])+k_mode = input.string("SMA", "K Mode", options=["SMA", "EMA", "WMA"])// MACD Inputs-fastLength = input(5, minval=1, title="EMA Fast Length")+fastLength = input.int(5, minval=1, title="EMA Fast Length")-slowLength = input(10, minval=1, title="EMA Slow Length")+slowLength = input.int(10, minval=1, title="EMA Slow Length")// Selections to show or hide the overlays-showZones = input(true, title="Show Bullish/Bearish Zones")+showZones = input.bool(true, title="Show Bullish/Bearish Zones")-showStoch = input(true, title="Show Stochastic Overlays")+showStoch = input.bool(true, title="Show Stochastic Overlays")// ------------------ Background Colors based on EMA Indicators -----------------------------------⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version 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=6strategy(shorttitle='BBZS',title='Bear & Bull Zone Signal Strategy', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value=0.18, calc_on_every_tick=true)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Start Time | timestamp("01 April 2021 00:00 -0500") | time | line 10 |
| Start Time | timestamp("31 December 2021 00:00 -0600") | time | line 10 |
| Strategy | Long/Short | string · options ["Long Only", "Long/Short", "Short Only"] | strat_val |
| Stop Loss % | 10.0 | float · min 0 · max 100 · step 0.01 | stoploss |
| Target Profit % | 20.0 | float · min 0 · max 100 · step 0.01 | TargetProfit |
| RSI Length | 14 | int · min 1 | rsi_ema v2 v3 RSI stoch h1 l1 |
| RSI Source | close | source | RSI |
| Overbought | 62 | int | signalColor Overbought |
| Oversold | 35 | int | signalColor Oversold |
| Look Back Bars | 9 | int | h_high l_low |
| High Source | high | source | h_high |
| Low Source | low | source | l_low |
| K | 3 | int · min 1 | k |
| D | 3 | int · min 1 | d |
| K Mode | SMA | string · options ["SMA", "EMA", "WMA"] | k |
| EMA Fast Length | 5 | int · min 1 | emaA emaFast |
| EMA Slow Length | 10 | int · min 1 | emaB emaSlow |
| Show Bullish/Bearish Zones | true | bool | Bullish/Bearish Zones |
| Show Stochastic Overlays | true | bool | K D signalUp signalDown |
What it calculates
- RSI (
rsi,ta.rsiin v5)haClose(0), RSI Length (14)rsi_ema · line 40 - EMA (
ema,ta.emain v5)rsi_ema, RSI Length (14)v2 · line 41 - EMA (
ema,ta.emain v5)v2, RSI Length (14)v3 · line 42 - EMA (
ema,ta.emain v5)rsi_ema, EMA Fast Length (5)emaA · line 43 - EMA (
ema,ta.emain v5)emaA, EMA Fast Length (5)emaFast · line 44 - EMA (
ema,ta.emain v5)rsi_ema, EMA Slow Length (10)emaB · line 45 - EMA (
ema,ta.emain v5)emaB, EMA Slow Length (10)emaSlow · line 46 - Highest (
highest,ta.highestin v5)High Source (high), Look Back Bars (9)h_high · line 58 - Lowest (
lowest,ta.lowestin v5)Low Source (low), Look Back Bars (9)l_low · line 59 - RSI (
rsi,ta.rsiin v5)RSI Source (close), RSI Length (14)RSI · line 60 - Stoch (
stoch,ta.stochin v5)RSI, RSI, RSI, RSI Length (14)stoch · line 61 - EMA / WMA / SMA (
ema,ta.emain v5)stoch, K (3) · chosen by K Modek · line 62 - SMA (
sma,ta.smain v5)k, D (3)d · line 66 - Change (
change,ta.changein v5)kk_c · line 67 - Change (
change,ta.changein v5)dd_c · line 68 - VWMA (
vwma,ta.vwmain v5)high, RSI Length (14)h1 · line 82 - VWMA (
vwma,ta.vwmain v5)low, RSI Length (14)l1 · line 83 - SMA (
sma,ta.smain v5)close, 24sma24 · line 114 - SMA (
sma,ta.smain v5)close, 38sma38 · line 115 - SMA (
sma,ta.smain v5)close, 50sma50 · line 116 - SMA (
sma,ta.smain v5)close, 62sma62 · line 117 - SMA (
sma,ta.smain v5)close, 76sma76 · line 118 - SMA (
sma,ta.smain v5)close, 100sma100 · line 119 - SMA (
sma,ta.smain v5)close, 236sma236 · line 120 - SMA (
sma,ta.smain v5)close, 382sma382 · line 121 - SMA (
sma,ta.smain v5)close, 500sma500 · line 122 - SMA (
sma,ta.smain v5)close, 618sma618 · line 123 - SMA (
sma,ta.smain v5)close, 764sma764 · line 124 - SMA (
sma,ta.smain v5)close, 1000sma1000 · line 125 - EMA (
ema,ta.emain v5)close, 24ema24 · line 126 - EMA (
ema,ta.emain v5)close, 38ema38 · line 127 - EMA (
ema,ta.emain v5)close, 50ema50 · line 128 - EMA (
ema,ta.emain v5)close, 62ema62 · line 129 - EMA (
ema,ta.emain v5)close, 76ema76 · line 130 - EMA (
ema,ta.emain v5)close, 100ema100 · line 131 - EMA (
ema,ta.emain v5)close, 236ema236 · line 132 - EMA (
ema,ta.emain v5)close, 382ema382 · line 133 - EMA (
ema,ta.emain v5)close, 500ema500 · line 134 - EMA (
ema,ta.emain v5)close, 618ema618 · line 135 - EMA (
ema,ta.emain v5)close, 764ema764 · line 136 - EMA (
ema,ta.emain v5)close, 1000ema1000 · 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 95 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open LONG long | (GoLong) | On | 160 |
| Exit Exit Long stop and limit | (GoLong) | On | 161 |
| Close LONG | (CloseLong) | On | 164 |
| Open SHORT short | (GoShort) | On | 166 |
| Exit Exit Short stop and limit | (GoShort) | On | 167 |
| Close SHORT | (CloseShort) | On | 171 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Bear & Bull Zone Signal Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| All in One Strategy no RSI Label - For higher dollar crypto by Solutions1978 | rsi ema highest lowest stoch sma vwma | v4 strategy | No trades on this market | ||
| All in One Strategy by Solutions1978 | rsi ema highest lowest stoch sma vwma | v4 strategy | No trades on this market | ||
| sma RSI & sudden buy and sell Strategy v1 by samwillington | ema rsi highest lowest sma | v5 strategy | +7.6% | 15 | 3.7% |
| Swing Multi Moving Averages Crypto and Stocks Strategy by exlux99 | ema wma highest lowest sma | v5 strategy | +60.2% | 22 | 13.1% |
| VCP pivot buy by perrycc007 | sma ema vwma wma lowest highest | v4 strategy | does not run in Zeal Terminal | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 30 ms | Yes 1,000 bars in 136 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0///@version=4strategy(shorttitle='BBZS',title='Bear & Bull Zone Signal Strategy', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value=0.18, calc_on_every_tick=true)kcolor = #0094FFdcolor = #FF6A00// ----------------- Strategy Inputs -------------------------------------------------------------//Backtest dates with auto finish date of todaystart = input(defval = timestamp("01 April 2021 00:00 -0500"), title = "Start Time", type = input.time)finish = input(defval = timestamp("31 December 2021 00:00 -0600"), title = "Start Time", type = input.time)window() => time >= start and time <= finish ? true : false // create function "within window of time"// Strategy Selection - Long, Short, or Bothstrat = input(title="Strategy", defval="Long/Short", options=["Long Only", "Long/Short", "Short Only"])strat_val = strat == "Long Only" ? 1 : strat == "Long/Short" ? 0 : -1// Risk Management Inputssl= input(10.0, "Stop Loss %", minval = 0, maxval = 100, step = 0.01)stoploss = sl/100tp = input(20.0, "Target Profit %", minval = 0, maxval = 100, step = 0.01)TargetProfit = tp/100// RSI and Stochastic Inputslength = input(14, "RSI Length", minval=1)source = input(title="RSI Source", type=input.source, defval=close)overbought= input(62, "Overbought")oversold= input(35, "Oversold")look_back = input(9,"Look Back Bars")high_source = input(high,"High Source")low_source= input(low,"Low Source")// EMA and SMA Background InputssmoothK = input(3, "K", minval=1)smoothD = input(3, "D", minval=1)k_mode = input("SMA", "K Mode", options=["SMA", "EMA", "WMA"])// MACD InputsfastLength = input(5, minval=1, title="EMA Fast Length")slowLength = input(10, minval=1, title="EMA Slow Length")// Selections to show or hide the overlaysshowZones = input(true, title="Show Bullish/Bearish Zones")showStoch = input(true, title="Show Stochastic Overlays")// ------------------ Background Colors based on EMA Indicators -----------------------------------// Uses standard lengths of 9 and 21, if you want control delete the constant definition and uncomment the inputshaClose(gap) => (open[gap] + high[gap] + low[gap] + close[gap]) / 4rsi_ema = rsi(haClose(0), length)v2 = ema(rsi_ema, length) v3 = 2 * v2 - ema(v2, length) emaA = ema(rsi_ema, fastLength) emaFast = 2 * emaA - ema(emaA, fastLength)emaB = ema(rsi_ema, slowLength) emaSlow = 2 * emaB - ema(emaB, slowLength) // bullish signal rule: bullishRule =emaFast > emaSlow// bearish signal rule: bearishRule =emaFast < emaSlow// current trading StateruleState = 0ruleState := bullishRule ? 1 : bearishRule ? -1 : nz(ruleState[1])bgcolor(showZones ? ( ruleState==1 ? color.blue : ruleState==-1 ? color.red : color.gray ) : na , title=" Bullish/Bearish Zones", transp=95)// ------------------ Stochastic Indicator Overlay -----------------------------------------------// Calculation// Use highest highs and lowest lowsh_high = highest(high_source ,look_back)l_low = lowest(low_source ,look_back)RSI = rsi(source, length)stoch = stoch(RSI, RSI, RSI, length)k = k_mode=="EMA" ? ema(stoch, smoothK) : k_mode=="WMA" ? wma(stoch, smoothK) : sma(stoch, smoothK)d = sma(k, smoothD)k_c = change(k)d_c = change(d)kd = k - d// PlotsignalColor = k>oversold and d<overbought and k>d and k_c>0 and d_c>0 ? kcolor : k<overbought and d>oversold and k<d and k_c<0 and d_c<0 ? dcolor : nakp = plot(showStoch ? k : na, "K", transp=80, color=kcolor)dp = plot(showStoch ? d : na, "D", transp=80, color=dcolor)fill(kp, dp, color = signalColor, title="K-D", transp=88)signalUp = showStoch ? not na(signalColor) and kd>0 : nasignalDown = showStoch ? not na(signalColor) and kd<0 : naplot(signalUp ? kd : na, "Signal Up", color=kcolor, transp=90, style=plot.style_columns)plot(signalDown ? (kd+100) : na , "Signal Down", color=dcolor, transp=90, style=plot.style_columns, histbase=100)// -------------- Add Price Movement to Strategy for better visualization -------------------------// Calculationsh1 = vwma(high, length)l1 = vwma(low, length)hp = h_high[1]lp = l_low[1]// Plotvar plot_color=#353535var sig = 0if (h1 >hp) sig:=1 plot_color:=color.limeelse if (l1 <lp) sig:=-1 plot_color:=color.maroonbgcolor(plot_color, transp=75)// --------------------------------------- RSI Plot ----------------------------------------------// Plot Oversold and Overbought Linesover = hline(oversold, title="Oversold", color=color.green)under = hline(overbought, title="Overbought", color=color.red)fill(over, under, color=#9915FF, transp=90, title="Band Background")// Plot colored RSI Lineplot(RSI, title="RSI", linewidth=3, color=color.yellow)//---------------- Signal Trigger Definitions -----------------------------------------SignalA = bearishRule and signalDown and window()SignalB = bullishRule and signalDown and window()SignalC = bearishRule and signalUp and window()SignalD = bullishRule and signalUp and window()//---------------- Signal Alerts ------------------------------------------------------//alertcondition(SignalA, title='Bear & Signal Down', message='Bearish Down')//alertcondition(SignalB, title='Bull & Signal Down', message='Bullish Down')//alertcondition(SignalC, title='Bear & Signal Up', message='Bearish Up')//alertcondition(SignalD, title='Bull & Signal Up', message='Bullish Up')//---------------- Fibonacci Sanity Check of Signals ---------------------------------sma24 = sma(close, 24)sma38 = sma(close, 38)sma50 = sma(close, 50)sma62 = sma(close, 62)sma76 = sma(close, 76)sma100 = sma(close, 100)sma236 = sma(close, 236)sma382= sma(close, 382)sma500 = sma(close, 500)sma618 = sma(close, 618)sma764 = sma(close, 764)sma1000 = sma(close, 1000)ema24 = ema(close, 24)ema38 = ema(close, 38)ema50 = ema(close, 50)ema62 = ema(close, 62)ema76 = ema(close, 76)ema100 = ema(close, 100)ema236 = ema(close, 236)ema382= ema(close, 382)ema500 = ema(close, 500)ema618 = ema(close, 618)ema764 = ema(close, 764)ema1000 = ema(close, 1000)Higher50 = close > sma50 or close > ema50Lower50 = close < sma50 or close < ema50Higher100 = close > sma100 or close > ema100Lower100 = close < sma100 or close < ema100Higher236 = close > sma236 or close > ema236Lower236 = close < sma236 or close < ema236Higher500 = close > sma500 or close > ema500Lower500 = close < sma500 or close < ema500Higher1000 = close > sma1000 or close > ema1000Lower1000 = close < sma1000 or close < ema1000// ------------------------------------- Alerts and Entry Strategy ----------------------------GoLong = strat_val > -1 ? (SignalC or SignalD and ((Higher50 or Higher100 or Higher236 or Higher500 or Higher1000) and not (Higher50[1] or Higher100[1] or Higher236[1] or Higher500[1] or Higher1000[1]))) : false//alertcondition(GoLong, title='True Long Signal', message='Go Long')GoShort = strat_val < 1 ? (SignalA or SignalB and ((Lower50 or Lower100 or Lower236 or Lower500 or Lower1000) and not (Lower50[1] or Lower100[1] or Lower236[1] or Lower500[1] or Lower1000[1]))) : false//alertcondition(GoShort, title='True Short Signal', message='Go Short')// ------------------------------------- Backtesting of Strategy --------------------------------convert_percent_to_points(percent) => strategy.position_size != 0 ? round(percent * strategy.position_avg_price / syminfo.mintick) : float(na) setup_percent(percent) => convert_percent_to_points(percent)if (GoLong) strategy.entry("LONG", strategy.long) strategy.exit(id="Exit Long", from_entry = "LONG", loss=setup_percent(stoploss), profit=setup_percent(TargetProfit))CloseLong = strat_val > -1 ? strategy.position_size > 0 and GoShort : falseif(CloseLong) strategy.close("LONG")if (GoShort) strategy.entry("SHORT", strategy.short) strategy.exit(id="Exit Short", from_entry = "SHORT", loss=setup_percent(stoploss), profit=setup_percent(TargetProfit)) CloseShort = strat_val < 1 ? strategy.position_size < 0 and GoLong : falseif(CloseShort) strategy.close("SHORT")