Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (9)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$66,491$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. Zeal Terminal's engine currently merges fill() calls that share a title, so it would draw 1 of this script's 2 fills; this page gives each call its own title to draw all of them.
Net profit
−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

Verified

Same 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) ⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
MA Length7int · min 3 · max 30MAout devInner devOuter
Inner Band1.0float · min 0.5 · max 5devInner
Outer Band2.00float · min 0.5 · max 10devOuter
From Day1int · min 1 · max 31startDate
From Month1int · min 1 · max 12startDate
From Year2000int · min 1970startDate
To Day1int · min 1 · max 31finishDate
To Month1int · min 1 · max 12finishDate
To Year2100int · min 1970finishDate

What it calculates

  • SMA (sma, ta.sma in v5)CandleChange, MA Length (7)MAout · line 12
  • Stdev (stdev, ta.stdev in v5)CandleChange, MA Length (7)devInner · line 16
  • Stdev (stdev, ta.stdev in 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.

MAlen MA Lengthsetting · 7InnerBandInner Bandsetting · 1.0OuterBandOuter Bandsetting · 2.00closecloseprice datafromYearFrom Yearsetting · 2000fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 1toYearTo Yearsetting · 2100toMonthTo Monthsetting · 1toDayTo Daysetting · 1lowlowprice datahighhighprice datatimetimeprice dataMAoutSMA→ MAoutdevInnerStdev→ devInnerdevOuterStdev→ devOuterCandleChangeCandleChangevalueupper1, lower1upper1 · lower12 valuesupper2, lower2upper2 · lower22 valuesstartDatestartDatevaluefinishDatefinishDatevalueRiskRiskvalueProfit, LossProfit · Loss2 valuesAlertMSGAlertMSGvalueLongStop, ShortStopLongStop · ShortStop2 valuesLongProfit, ShortProfitLongProfit · ShortProfit2 valuesLongFilterLongFilterconditionShortFilterShortFilterconditiontime_conditiontime_conditionconditionVolFilterL, VolFilterSVolFilterL · VolFilterS2 conditionsSMAFilterL, PriceFilterL, SMAFilterS, PriceFilterSSMAFilterL · PriceFilte…4 conditionsentry:LongOpen Longstrategy.entryexit:TP/SLexit TP/SLstrategy.exitentry:ShortOpen Shortstrategy.entryplot:9plotplotplot:13plotplotplot:20Upper Innerplotplot:21Lower Innerplotplot:24Upper Outerplotplot:25Lower Outerplotfill:BackgroundBackgroundfill × 2hline:28hlinehlinehline:29hlinehlinebgcolor:35bgcolorbgcolorbgcolor:41bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open Long longLongFilterVolFilterL and SMAFilterL and PriceFilterLOn59
Exit TP/SL stop and limit(LongFilter)On63
Open Short shortShortFilterVolFilterS and SMAFilterS and PriceFilterSOn65
Exit TP/SL stop and limit(ShortFilter)On69

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.

24/24trades 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−33.5%+102.5%8034%0.7245.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.0%+5.5%6938%1.047.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.9%+9.8%6736%1.392.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.2%+8.4%6441%1.170.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%7435%1.190.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%7744%1.950.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.2%+148.3%8633%0.820.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%7833%1.010.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 barsTradesWonP&L
Rising market2326%−$9,498.67
Sideways market4038%−$13,341.40
Falling market1735%−$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.

0%68%
All 80 trades
SideEntryExitBarsP&L
long30 Mar 2024 69,850.502 Apr 2024 69,408.103−$442.46
long10 Apr 2024 69,146.0015 Apr 2024 65,661.905−$3,484.15
short15 Apr 2024 65,661.9015 Apr 2024 65,661.900$0.00
short19 Apr 2024 63,470.1030 Apr 2024 63,866.0011−$395.91
short3 May 2024 59,060.604 May 2024 62,882.001−$3,821.41
short14 May 2024 62,940.108 Jun 2024 69,355.6025−$6,415.51
long8 Jun 2024 69,355.608 Jun 2024 69,355.600$0.00
short26 Jun 2024 61,806.007 Jul 2024 58,230.1011$3,575.88
short9 Jul 2024 56,714.6010 Jul 2024 58,050.001−$1,335.39
long18 Jul 2024 64,088.0024 Jul 2024 65,936.006$1,848.01
long30 Jul 2024 66,784.707 Aug 2024 56,022.008−$10,762.70
short7 Aug 2024 56,022.007 Aug 2024 56,022.000$0.00
short17 Aug 2024 58,874.6027 Aug 2024 62,834.0010−$3,959.41
long27 Aug 2024 62,834.0027 Aug 2024 62,834.000$0.00
short3 Sep 2024 59,132.1010 Sep 2024 57,042.007$2,090.11
long15 Sep 2024 59,993.0016 Sep 2024 59,132.001−$861.02
short18 Sep 2024 60,314.0024 Sep 2024 63,340.006−$3,026.00
long24 Sep 2024 63,340.0024 Sep 2024 63,340.000$0.00
long26 Sep 2024 63,152.001 Oct 2024 63,514.605$362.60
short12 Oct 2024 62,540.0018 Oct 2024 67,421.806−$4,881.79
long18 Oct 2024 67,421.8018 Oct 2024 67,421.800$0.00
long26 Oct 2024 66,698.301 Nov 2024 70,292.006$3,593.69
long13 Nov 2024 87,952.0015 Nov 2024 87,325.602−$626.41
long24 Nov 2024 97,672.406 Dec 2024 96,945.6012−$726.77
long10 Dec 2024 97,276.5027 Dec 2024 95,791.6017−$1,484.88
short2 Jan 2025 94,591.8017 Jan 2025 99,987.3015−$5,395.52
long17 Jan 2025 99,987.3017 Jan 2025 99,987.300$0.00
long20 Jan 2025 101,332.0023 Jan 2025 103,707.003$2,375.09
long27 Jan 2025 102,620.001 Feb 2025 102,214.005−$405.79
short4 Feb 2025 101,329.005 Feb 2025 97,763.101$3,565.37
long5 Feb 2025 97,763.105 Feb 2025 97,763.100$0.00
short11 Feb 2025 97,430.8020 Feb 2025 96,644.409$786.45
short28 Feb 2025 84,708.602 Mar 2025 86,064.502−$1,355.97
short12 Mar 2025 82,933.0015 Mar 2025 83,983.203−$1,050.20
short2 Apr 2025 85,158.4010 Apr 2025 82,615.208$2,543.13
short12 Apr 2025 83,423.8030 Apr 2025 94,256.8018−$10,833.00
long30 Apr 2025 94,256.8030 Apr 2025 94,256.800$0.00
long4 May 2025 95,856.405 May 2025 94,277.601−$1,578.81
long13 May 2025 102,791.0024 May 2025 107,318.0011$4,526.98
long13 Jun 2025 105,672.001 Jul 2025 107,147.0018$1,474.77
long5 Jul 2025 107,984.0016 Jul 2025 117,758.0011$9,773.83
long19 Jul 2025 117,925.0024 Jul 2025 118,756.005$831.16
long29 Jul 2025 118,062.009 Aug 2025 116,675.0011−$1,387.58
short21 Aug 2025 114,271.0023 Aug 2025 116,936.002−$2,664.77
short3 Sep 2025 111,240.0014 Sep 2025 115,918.0011−$4,678.28
long14 Sep 2025 115,918.0014 Sep 2025 115,918.000$0.00
long15 Sep 2025 115,268.0020 Sep 2025 115,632.005$364.38
short25 Sep 2025 113,307.0029 Sep 2025 112,164.004$1,143.05
long5 Oct 2025 122,391.008 Oct 2025 121,333.003−$1,058.03
short13 Oct 2025 114,959.0020 Oct 2025 108,643.007$6,316.04
short21 Oct 2025 110,532.0024 Oct 2025 109,784.003$748.40
short6 Nov 2025 103,885.008 Nov 2025 103,339.002$546.07
short10 Nov 2025 104,723.0019 Nov 2025 92,960.809$11,762.10
short24 Nov 2025 86,830.003 Dec 2025 91,277.909−$4,447.88
short10 Dec 2025 92,678.8017 Dec 2025 87,863.407$4,815.38
short20 Dec 2025 88,136.9028 Dec 2025 87,877.008$259.95
long16 Jan 2026 95,604.8019 Jan 2026 93,673.103−$1,931.67
short22 Jan 2026 89,454.7027 Jan 2026 88,347.105$1,107.65
short3 Feb 2026 78,738.607 Feb 2026 70,580.304$8,158.34
short14 Feb 2026 68,854.0021 Feb 2026 68,020.007$833.97
short26 Feb 2026 67,988.0010 Mar 2026 68,437.2012−$449.14
long18 Mar 2026 73,909.4019 Mar 2026 71,246.601−$2,662.82
long27 Mar 2026 68,820.3031 Mar 2026 66,797.404−$2,022.93
short31 Mar 2026 66,797.4031 Mar 2026 66,797.400$0.00
short1 Apr 2026 68,284.5013 Apr 2026 70,741.6012−$2,457.07
long13 Apr 2026 70,741.6013 Apr 2026 70,741.600$0.00
long28 Apr 2026 77,371.308 May 2026 80,006.0010$2,634.68
long13 May 2026 80,504.5024 May 2026 76,752.0011−$3,752.47
short24 May 2026 76,752.0024 May 2026 76,752.000$0.00
long27 May 2026 75,930.0031 May 2026 73,884.404−$2,045.63
short31 May 2026 73,884.4031 May 2026 73,884.400$0.00
short7 Jun 2026 60,884.608 Jun 2026 63,332.001−$2,447.39
short23 Jun 2026 64,020.0030 Jun 2026 60,260.207$3,759.81
short2 Jul 2026 60,024.0024 Jul 2026 65,099.0022−$5,074.98
long24 Jul 2026 65,099.0024 Jul 2026 65,099.000$0.00
short3 Aug 2026 63,570.0023 Aug 2026 77,074.9020−$13,504.90
long23 Aug 2026 77,074.9023 Aug 2026 77,074.900$0.00
long26 Aug 2026 78,539.1029 Aug 2026 77,845.903−$693.25
long5 Sep 2026 79,660.8024 Sep 2026 84,397.6019$4,736.83
long6 Oct 2026 85,766.9013 Oct 2026 81,850.007−$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.

ScriptSharesTypeNetTradesMax drawdown
BTC Volatility Band Strategy this page—v4 strategy−33.5%8045.0%
Lawyers Trend Pro Strategy by ErdemDemirsma stdev lowest highestv4 strategy+12.1%10241.7%
MACandles-LinearRegression-Strategy by Trendoscopestdev sma highest lowestv5 strategy+26.7%346.7%
VixFixLinReg-Strategy by Trendoscopehighest stdev sma lowestv4 strategy−49.3%1251.1%
Chandelier + BB + EMAS by juanchezhighest lowest sma stdevv4 strategy−20.6%1038.6%
Crunchster's Turtle and Trend System by Crunchster1lowest highest stdev smav5 strategy+18.0%3116.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 22 msWith a workaround 1,000 bars in 59 msNot measured
PineTSNo 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)