Pine Script v4 · Strategy
BTC Volatility Band Strategy
A Pine Script v4 strategy built on SMA (CandleChange, 7) and Stdev (CandleChange, 7). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 9 settings; defaults include MA Length 7, Inner Band 1.0 and Outer Band 2.00.
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 BTC Volatility Band Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 24 of 24 trades.
- How did BTC Volatility Band Strategy do on BTCUSDT 1D with default settings?
- −33.51%
- From 26 Jan 2024 to 21 Oct 2026, over 80 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can BTC Volatility Band Strategy 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 BTC Volatility Band Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 63, 69.
- Does BTC Volatility Band Strategy run in Zeal Terminal?
- Yes
- It compiles in 22 ms and runs 1,000 bars in 59 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Upper Inner
- Lower Inner
- Upper Outer
- Lower Outer
- Upper Band
- Lower Band
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −33.51%
- −$33,505.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 80
- 27 won · 37 lost
- Profitable
- 33.8%
- of closed trades
- Profit factor
- 0.72
- gross profit ÷ gross loss
- Max drawdown
- 45.05%
- −$45,047.50
One run with the author's default settings, $100,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
sma(close[1], 50) ignores the settings line 32
Line 32 hard-codes 50 where line 12 uses “ MA Length”. Changing those settings moves one band but not this one.
sma(close[1], 50)sma(close[1], MAlen) -
Likely bug
sma(close[1], 50) ignores the settings line 38
Line 38 hard-codes 50 where line 12 uses “ MA Length”. Changing those settings moves one band but not this one.
sma(close[1], 50)sma(close[1], MAlen) -
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
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 59, 65. 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, stdev → ta.stdev, lowest → ta.lowest, highest → ta.highest, tostring → str.tostring.
- 2 strategy calls use the when = argument (line 59, 65). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 80 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: //@version=4 → //@version=5
- Line 12: sma → ta.sma
- Line 16: stdev → ta.stdev
- Line 17: stdev → ta.stdev
- Line 32: sma → ta.sma
- Line 33: lowest → ta.lowest
3 more edits
- Line 38: sma → ta.sma
- Line 39: highest → ta.highest
- Line 57: tostring → str.tostring
⋯//It takes both long and short trades and the main indicator settings can be changed by the use so they can test for ideal settings for ticker of interest.-//@version=4+//@version=5strategy("BTC Volatility Band Strategy", shorttitle="Vol Band Strategy", overlay=false, margin_long=100, margin_short=100)⋯MAlen = input(7, minval=3, maxval=30, title=" MA Length")-MAout = sma(CandleChange, MAlen)+MAout = ta.sma(CandleChange, MAlen)plot(MAout, color=color.black, display=display.none)⋯OuterBand = input(2.00, minval=0.5, maxval=10, title="Outer Band")-devInner = InnerBand * stdev(CandleChange, MAlen)+devInner = InnerBand * ta.stdev(CandleChange, MAlen)-devOuter = OuterBand * stdev(CandleChange, MAlen)+devOuter = OuterBand * ta.stdev(CandleChange, MAlen)upper1 = MAout + devInner⋯VolFilterL = CandleChange <= lower1 and CandleChange > lower2-SMAFilterL = close[1] > sma(close[1], 50)+SMAFilterL = close[1] > ta.sma(close[1], 50)-PriceFilterL = close > lowest(close,7)+PriceFilterL = close > ta.lowest(close,7)LongFilter = VolFilterL and SMAFilterL and PriceFilterL⋯VolFilterS = CandleChange >= upper1 and CandleChange < upper2-SMAFilterS = close[1] < sma(close[1], 50)+SMAFilterS = close[1] < ta.sma(close[1], 50)-PriceFilterS = close < highest(close,7)+PriceFilterS = close < ta.highest(close,7)ShortFilter = VolFilterS and SMAFilterS and PriceFilterS⋯Loss = Risk*0.65-AlertMSG = "New stategy position" + tostring(strategy.position_size)+AlertMSG = "New stategy position" + str.tostring(strategy.position_size)if (time_condition) ⋯Same 80 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 11: input() → input.int()
- Line 14: input() → input.float()
- Line 15: input() → input.float()
- Line 43: input() → input.int()
- Line 44: input() → input.int()
- Line 45: input() → input.int()
5 more edits
- Line 47: input() → input.int()
- Line 48: input() → input.int()
- Line 49: input() → input.int()
- Line 59: when = LongFilter → if block
- Line 65: when = ShortFilter → if block
⋯//VOLATILITY BANDS -MAlen = input(7, minval=3, maxval=30, title=" MA Length")+MAlen = input.int(7, minval=3, maxval=30, title=" MA Length")MAout = ta.sma(CandleChange, MAlen)plot(MAout, color=color.black, display=display.none)-InnerBand = input(1.0, minval=0.5, maxval=5, title="Inner Band")+InnerBand = input.float(1.0, minval=0.5, maxval=5, title="Inner Band")-OuterBand = input(2.00, minval=0.5, maxval=10, title="Outer Band")+OuterBand = input.float(2.00, minval=0.5, maxval=10, title="Outer Band")devInner = InnerBand * ta.stdev(CandleChange, MAlen)⋯//SETTING BACK TEST INPUTS-fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-fromYear = input(defval = 2000, title = "From Year", minval = 1970)+fromYear = input.int(defval = 2000, title = "From Year", minval = 1970) -toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+toDay = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)+toMonth = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-toYear = input(defval = 2100, title = "To Year", minval = 1970)+toYear = input.int(defval = 2100, title = "To Year", minval = 1970)startDate = timestamp("America/New_York", fromYear, fromMonth, fromDay, 00, 00)⋯if (time_condition) - strategy.entry("Long", strategy.long, when = LongFilter, alert_message=AlertMSG)+ if LongFilter+ strategy.entry("Long", strategy.long, alert_message=AlertMSG) if (LongFilter)⋯if (time_condition)- strategy.entry("Short", strategy.short, when = ShortFilter, alert_message=AlertMSG)+ if ShortFilter+ strategy.entry("Short", strategy.short, alert_message=AlertMSG) if (ShortFilter)⋯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: 80 before, 81 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.
⋯//It takes both long and short trades and the main indicator settings can be changed by the use so they can test for ideal settings for ticker of interest.-//@version=5+//@version=6strategy("BTC Volatility Band Strategy", shorttitle="Vol Band Strategy", overlay=false, margin_long=100, margin_short=100)⋯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 |
|---|---|---|---|
| MA Length | 7 | int · min 3 · max 30 | MAout devInner devOuter |
| Inner Band | 1.0 | float · min 0.5 · max 5 | devInner |
| Outer Band | 2.00 | float · min 0.5 · max 10 | devOuter |
| From Day | 1 | int · min 1 · max 31 | startDate |
| From Month | 1 | int · min 1 · max 12 | startDate |
| From Year | 2000 | int · min 1970 | startDate |
| To Day | 1 | int · min 1 · max 31 | finishDate |
| To Month | 1 | int · min 1 · max 12 | finishDate |
| To Year | 2100 | int · min 1970 | finishDate |
What it calculates
- SMA (
sma,ta.smain v5)CandleChange, MA Length (7)MAout · line 12 - Stdev (
stdev,ta.stdevin v5)CandleChange, MA Length (7)devInner · line 16 - Stdev (
stdev,ta.stdevin v5)CandleChange, MA Length (7)devOuter · line 17
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | LongFilterVolFilterL and SMAFilterL and PriceFilterL | On | 59 |
| Exit TP/SL stop and limit | (LongFilter) | On | 63 |
| Open Short short | ShortFilterVolFilterS and SMAFilterS and PriceFilterS | On | 65 |
| Exit TP/SL stop and limit | (ShortFilter) | On | 69 |
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.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −33.5% | +102.5% | 80 | 34% | 0.72 | 45.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.0% | +5.5% | 69 | 38% | 1.04 | 7.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.9% | +9.8% | 67 | 36% | 1.39 | 2.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.2% | +8.4% | 64 | 41% | 1.17 | 0.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 74 | 35% | 1.19 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 77 | 44% | 1.95 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.2% | +148.3% | 86 | 33% | 0.82 | 0.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 78 | 33% | 1.01 | 0.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 23 | 26% | −$9,498.67 |
| Sideways market | 40 | 38% | −$13,341.40 |
| Falling market | 17 | 35% | −$10,665.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
58.7%
The 95th percentile of the worst drawdown when the same 80 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 37.3% to 58.7%; the tick is what actually happened, 42.1%. Order luck alone moves it this much.
All 80 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 30 Mar 2024 69,850.50 | 2 Apr 2024 69,408.10 | 3 | −$442.46 |
| long | 10 Apr 2024 69,146.00 | 15 Apr 2024 65,661.90 | 5 | −$3,484.15 |
| short | 15 Apr 2024 65,661.90 | 15 Apr 2024 65,661.90 | 0 | $0.00 |
| short | 19 Apr 2024 63,470.10 | 30 Apr 2024 63,866.00 | 11 | −$395.91 |
| short | 3 May 2024 59,060.60 | 4 May 2024 62,882.00 | 1 | −$3,821.41 |
| short | 14 May 2024 62,940.10 | 8 Jun 2024 69,355.60 | 25 | −$6,415.51 |
| long | 8 Jun 2024 69,355.60 | 8 Jun 2024 69,355.60 | 0 | $0.00 |
| short | 26 Jun 2024 61,806.00 | 7 Jul 2024 58,230.10 | 11 | $3,575.88 |
| short | 9 Jul 2024 56,714.60 | 10 Jul 2024 58,050.00 | 1 | −$1,335.39 |
| long | 18 Jul 2024 64,088.00 | 24 Jul 2024 65,936.00 | 6 | $1,848.01 |
| long | 30 Jul 2024 66,784.70 | 7 Aug 2024 56,022.00 | 8 | −$10,762.70 |
| short | 7 Aug 2024 56,022.00 | 7 Aug 2024 56,022.00 | 0 | $0.00 |
| short | 17 Aug 2024 58,874.60 | 27 Aug 2024 62,834.00 | 10 | −$3,959.41 |
| long | 27 Aug 2024 62,834.00 | 27 Aug 2024 62,834.00 | 0 | $0.00 |
| short | 3 Sep 2024 59,132.10 | 10 Sep 2024 57,042.00 | 7 | $2,090.11 |
| long | 15 Sep 2024 59,993.00 | 16 Sep 2024 59,132.00 | 1 | −$861.02 |
| short | 18 Sep 2024 60,314.00 | 24 Sep 2024 63,340.00 | 6 | −$3,026.00 |
| long | 24 Sep 2024 63,340.00 | 24 Sep 2024 63,340.00 | 0 | $0.00 |
| long | 26 Sep 2024 63,152.00 | 1 Oct 2024 63,514.60 | 5 | $362.60 |
| short | 12 Oct 2024 62,540.00 | 18 Oct 2024 67,421.80 | 6 | −$4,881.79 |
| long | 18 Oct 2024 67,421.80 | 18 Oct 2024 67,421.80 | 0 | $0.00 |
| long | 26 Oct 2024 66,698.30 | 1 Nov 2024 70,292.00 | 6 | $3,593.69 |
| long | 13 Nov 2024 87,952.00 | 15 Nov 2024 87,325.60 | 2 | −$626.41 |
| long | 24 Nov 2024 97,672.40 | 6 Dec 2024 96,945.60 | 12 | −$726.77 |
| long | 10 Dec 2024 97,276.50 | 27 Dec 2024 95,791.60 | 17 | −$1,484.88 |
| short | 2 Jan 2025 94,591.80 | 17 Jan 2025 99,987.30 | 15 | −$5,395.52 |
| long | 17 Jan 2025 99,987.30 | 17 Jan 2025 99,987.30 | 0 | $0.00 |
| long | 20 Jan 2025 101,332.00 | 23 Jan 2025 103,707.00 | 3 | $2,375.09 |
| long | 27 Jan 2025 102,620.00 | 1 Feb 2025 102,214.00 | 5 | −$405.79 |
| short | 4 Feb 2025 101,329.00 | 5 Feb 2025 97,763.10 | 1 | $3,565.37 |
| long | 5 Feb 2025 97,763.10 | 5 Feb 2025 97,763.10 | 0 | $0.00 |
| short | 11 Feb 2025 97,430.80 | 20 Feb 2025 96,644.40 | 9 | $786.45 |
| short | 28 Feb 2025 84,708.60 | 2 Mar 2025 86,064.50 | 2 | −$1,355.97 |
| short | 12 Mar 2025 82,933.00 | 15 Mar 2025 83,983.20 | 3 | −$1,050.20 |
| short | 2 Apr 2025 85,158.40 | 10 Apr 2025 82,615.20 | 8 | $2,543.13 |
| short | 12 Apr 2025 83,423.80 | 30 Apr 2025 94,256.80 | 18 | −$10,833.00 |
| long | 30 Apr 2025 94,256.80 | 30 Apr 2025 94,256.80 | 0 | $0.00 |
| long | 4 May 2025 95,856.40 | 5 May 2025 94,277.60 | 1 | −$1,578.81 |
| long | 13 May 2025 102,791.00 | 24 May 2025 107,318.00 | 11 | $4,526.98 |
| long | 13 Jun 2025 105,672.00 | 1 Jul 2025 107,147.00 | 18 | $1,474.77 |
| long | 5 Jul 2025 107,984.00 | 16 Jul 2025 117,758.00 | 11 | $9,773.83 |
| long | 19 Jul 2025 117,925.00 | 24 Jul 2025 118,756.00 | 5 | $831.16 |
| long | 29 Jul 2025 118,062.00 | 9 Aug 2025 116,675.00 | 11 | −$1,387.58 |
| short | 21 Aug 2025 114,271.00 | 23 Aug 2025 116,936.00 | 2 | −$2,664.77 |
| short | 3 Sep 2025 111,240.00 | 14 Sep 2025 115,918.00 | 11 | −$4,678.28 |
| long | 14 Sep 2025 115,918.00 | 14 Sep 2025 115,918.00 | 0 | $0.00 |
| long | 15 Sep 2025 115,268.00 | 20 Sep 2025 115,632.00 | 5 | $364.38 |
| short | 25 Sep 2025 113,307.00 | 29 Sep 2025 112,164.00 | 4 | $1,143.05 |
| long | 5 Oct 2025 122,391.00 | 8 Oct 2025 121,333.00 | 3 | −$1,058.03 |
| short | 13 Oct 2025 114,959.00 | 20 Oct 2025 108,643.00 | 7 | $6,316.04 |
| short | 21 Oct 2025 110,532.00 | 24 Oct 2025 109,784.00 | 3 | $748.40 |
| short | 6 Nov 2025 103,885.00 | 8 Nov 2025 103,339.00 | 2 | $546.07 |
| short | 10 Nov 2025 104,723.00 | 19 Nov 2025 92,960.80 | 9 | $11,762.10 |
| short | 24 Nov 2025 86,830.00 | 3 Dec 2025 91,277.90 | 9 | −$4,447.88 |
| short | 10 Dec 2025 92,678.80 | 17 Dec 2025 87,863.40 | 7 | $4,815.38 |
| short | 20 Dec 2025 88,136.90 | 28 Dec 2025 87,877.00 | 8 | $259.95 |
| long | 16 Jan 2026 95,604.80 | 19 Jan 2026 93,673.10 | 3 | −$1,931.67 |
| short | 22 Jan 2026 89,454.70 | 27 Jan 2026 88,347.10 | 5 | $1,107.65 |
| short | 3 Feb 2026 78,738.60 | 7 Feb 2026 70,580.30 | 4 | $8,158.34 |
| short | 14 Feb 2026 68,854.00 | 21 Feb 2026 68,020.00 | 7 | $833.97 |
| short | 26 Feb 2026 67,988.00 | 10 Mar 2026 68,437.20 | 12 | −$449.14 |
| long | 18 Mar 2026 73,909.40 | 19 Mar 2026 71,246.60 | 1 | −$2,662.82 |
| long | 27 Mar 2026 68,820.30 | 31 Mar 2026 66,797.40 | 4 | −$2,022.93 |
| short | 31 Mar 2026 66,797.40 | 31 Mar 2026 66,797.40 | 0 | $0.00 |
| short | 1 Apr 2026 68,284.50 | 13 Apr 2026 70,741.60 | 12 | −$2,457.07 |
| long | 13 Apr 2026 70,741.60 | 13 Apr 2026 70,741.60 | 0 | $0.00 |
| long | 28 Apr 2026 77,371.30 | 8 May 2026 80,006.00 | 10 | $2,634.68 |
| long | 13 May 2026 80,504.50 | 24 May 2026 76,752.00 | 11 | −$3,752.47 |
| short | 24 May 2026 76,752.00 | 24 May 2026 76,752.00 | 0 | $0.00 |
| long | 27 May 2026 75,930.00 | 31 May 2026 73,884.40 | 4 | −$2,045.63 |
| short | 31 May 2026 73,884.40 | 31 May 2026 73,884.40 | 0 | $0.00 |
| short | 7 Jun 2026 60,884.60 | 8 Jun 2026 63,332.00 | 1 | −$2,447.39 |
| short | 23 Jun 2026 64,020.00 | 30 Jun 2026 60,260.20 | 7 | $3,759.81 |
| short | 2 Jul 2026 60,024.00 | 24 Jul 2026 65,099.00 | 22 | −$5,074.98 |
| long | 24 Jul 2026 65,099.00 | 24 Jul 2026 65,099.00 | 0 | $0.00 |
| short | 3 Aug 2026 63,570.00 | 23 Aug 2026 77,074.90 | 20 | −$13,504.90 |
| long | 23 Aug 2026 77,074.90 | 23 Aug 2026 77,074.90 | 0 | $0.00 |
| long | 26 Aug 2026 78,539.10 | 29 Aug 2026 77,845.90 | 3 | −$693.25 |
| long | 5 Sep 2026 79,660.80 | 24 Sep 2026 84,397.60 | 19 | $4,736.83 |
| long | 6 Oct 2026 85,766.90 | 13 Oct 2026 81,850.00 | 7 | −$3,916.86 |
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 |
|---|---|---|---|---|---|
| BTC Volatility Band Strategy this page | — | v4 strategy | −33.5% | 80 | 45.0% |
| Lawyers Trend Pro Strategy by ErdemDemir | sma stdev lowest highest | v4 strategy | +12.1% | 102 | 41.7% |
| MACandles-LinearRegression-Strategy by Trendoscope | stdev sma highest lowest | v5 strategy | +26.7% | 3 | 46.7% |
| VixFixLinReg-Strategy by Trendoscope | highest stdev sma lowest | v4 strategy | −49.3% | 12 | 51.1% |
| Chandelier + BB + EMAS by juanchez | highest lowest sma stdev | v4 strategy | −20.6% | 10 | 38.6% |
| Crunchster's Turtle and Trend System by Crunchster1 | lowest highest stdev sma | v5 strategy | +18.0% | 31 | 16.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 22 ms | With a workaround 1,000 bars in 59 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not 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. 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/// © gary_trades//This script is designed to be used on volatile securities/tickers so is best suited for day charts on Crypto (particularly good for BTC).//It takes both long and short trades and the main indicator settings can be changed by the use so they can test for ideal settings for ticker of interest.//@version=4strategy("BTC Volatility Band Strategy", shorttitle="Vol Band Strategy", overlay=false, margin_long=100, margin_short=100)//VOLATILTYCandleChange = ((close - close[1])/close)*100 //OR CandleChange = ((close[2] - close[1])/close)*100plot(CandleChange, color=color.red, linewidth = 1)//VOLATILITY BANDS MAlen = input(7, minval=3, maxval=30, title=" MA Length")MAout = sma(CandleChange, MAlen)plot(MAout, color=color.black, display=display.none)InnerBand = input(1.0, minval=0.5, maxval=5, title="Inner Band")OuterBand = input(2.00, minval=0.5, maxval=10, title="Outer Band")devInner = InnerBand * stdev(CandleChange, MAlen)devOuter = OuterBand * stdev(CandleChange, MAlen)upper1 = MAout + devInnerlower1 = MAout - devInnerb1 = plot(upper1, "Upper Inner", color=color.gray)b2 = plot(lower1, "Lower Inner", color=color.gray)upper2 = MAout + devOuterlower2 = MAout - devOuterb3 = plot(upper2, "Upper Outer", color=color.gray)b4 = plot(lower2, "Lower Outer", color=color.gray)fill(b1, b3, color.rgb(250,145,175,70), title="Background")fill(b2, b4, color.rgb(250,145,175,70), title="Background")band1 = hline(25, "Upper Band", color=color.gray, linestyle=hline.style_dotted, linewidth=2)band0 = hline(-25, "Lower Band", color=color.gray, linestyle=hline.style_dotted, linewidth=2)//LONG FILTERVolFilterL = CandleChange <= lower1 and CandleChange > lower2SMAFilterL = close[1] > sma(close[1], 50)PriceFilterL = close > lowest(close,7)LongFilter = VolFilterL and SMAFilterL and PriceFilterLbgcolor(LongFilter ? color.new(color.green, 80) : na)//SHORT FILTERVolFilterS = CandleChange >= upper1 and CandleChange < upper2SMAFilterS = close[1] < sma(close[1], 50)PriceFilterS = close < highest(close,7)ShortFilter = VolFilterS and SMAFilterS and PriceFilterSbgcolor(ShortFilter ? color.new(color.red, 80) : na)//SETTING BACK TEST INPUTSfromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)fromYear = input(defval = 2000, title = "From Year", minval = 1970) toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)toYear = input(defval = 2100, title = "To Year", minval = 1970)startDate = timestamp("America/New_York", fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp("America/New_York", toYear, toMonth, toDay, 00, 00)time_condition = time >= startDate and time <= finishDate//ORDER DETAILSRisk = (high[7] - low[7])/ 7Profit = Risk*1.15Loss = Risk*0.65AlertMSG = "New stategy position" + tostring(strategy.position_size)if (time_condition) strategy.entry("Long", strategy.long, when = LongFilter, alert_message=AlertMSG) if (LongFilter) LongStop = strategy.position_avg_price - Loss LongProfit = strategy.position_avg_price + Profit strategy.exit("TP/SL", "Long", stop=LongStop, limit=LongProfit)if (time_condition) strategy.entry("Short", strategy.short, when = ShortFilter, alert_message=AlertMSG) if (ShortFilter) ShortStop = strategy.position_avg_price + Loss ShortProfit = strategy.position_avg_price - Profit strategy.exit("TP/SL", "Short", stop=ShortStop, limit=ShortProfit)