Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Bollinger band & Volume based strategy V2

A Pine Script v4 strategy built on SMA (tr, 10), ATR (10) and RSI (close, 14). It has 14 order rules, 3 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 500 in cash and pays 0.04% commission. 23 settings; defaults include ATR Period 10, Source hl2 and ATR Multiplier 3.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 Bollinger band & Volume based strategy V2 repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Bollinger band & Volume based strategy V2 do on BTCUSDT 1D with default settings?
−0.07%
From 26 Jan 2024 to 21 Oct 2026, over 5 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Bollinger band & Volume based strategy V2 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 Bollinger band & Volume based strategy V2 use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Bollinger band & Volume based strategy V2 run in Zeal Terminal?
Yes
It compiles in 45 ms and runs 1,000 bars in 103 ms, in the browser.

BTCUSDT · 1D · default settings

  • Up Trend
  • UpTrend Begins
  • Buy
  • Down Trend
  • DownTrend Begins
  • Sell
  • Basis
  • Upper
  • Lower
  • 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 (23)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$99,926$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
−0.07%
−$73.84
Buy and hold
+102.5%
same period
Closed trades
5
4 won · 1 lost
Profitable
80.0%
of closed trades
Profit factor
0.34
gross profit ÷ gross loss
Max drawdown
0.16%
−$159.04

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.

  • Check

    1 setting does nothing

    “Highlighter On/Off ?” is declared but never read.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Note

    9 settings have no label

    In the settings dialog length1 (line 31), length3 (line 32), length7 (line 33), length9 (line 34), length14 (line 35), length20 (line 36), length60 (line 37), length120 (line 38), length (line 58) 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 iff(), which v5 removed line 49

    iff() on line 49, 50, 51. v5 writes it as the ternary c ? a : b.

  • Note

    Uses transp =, which v5 removed line 25

    transp = on line 25, 26, 29, 30. 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 sma → ta.sma, atr → ta.atr, max → math.max, min → math.min, rsi → ta.rsi, stdev → ta.stdev, valuewhen → ta.valuewhen, crossunder → ta.crossunder.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 6: input(type = input.integer) → input.int()
  • Line 8: input(type = input.float) → input.float()
  • Line 9: input(type = input.bool) → input.bool()
  • Line 10: input(type = input.bool) → input.bool()
  • Line 11: input(type = input.bool) → input.bool()
33 more edits
  • Line 12: sma → ta.sma
  • Line 12: tr → ta.tr
  • Line 13: atr → ta.atr
  • Line 16: max → math.max
  • Line 19: min → math.min
  • Line 25: transp = 0 → color.new(color.green, 0)
  • Line 26: transp = 0 → color.new(color.green, 0)
  • Line 29: transp = 0 → color.new(color.red, 0)
  • Line 30: transp = 0 → color.new(color.red, 0)
  • Line 39: sma → ta.sma
  • Line 40: sma → ta.sma
  • Line 41: sma → ta.sma
  • Line 42: sma → ta.sma
  • Line 43: sma → ta.sma
  • Line 44: sma → ta.sma
  • Line 45: sma → ta.sma
  • Line 46: sma → ta.sma
  • Line 47: rsi → ta.rsi
  • Line 49: iff(c, a, b) → (c ? a : b)
  • Line 50: iff(c, a, b) → (c ? a : b)
  • Line 51: iff(c, a, b) → (c ? a : b)
  • Line 52: input(type = input.integer) → input.int()
  • Line 53: input(type = input.integer) → input.int()
  • Line 55: sma → ta.sma
  • Line 56: sma → ta.sma
  • Line 64: sma → ta.sma
  • Line 65: stdev → ta.stdev
  • Line 68: stdev → ta.stdev
  • Line 71: stdev → ta.stdev
  • Line 74: stdev → ta.stdev
  • Line 77: input(type = input.integer) → input.int()
  • Line 90: valuewhen → ta.valuewhen
  • Line 113: crossunder → ta.crossunder
⋯// © KAIST291-//@version=4+//@version=5initial_capital=1000strategy("prototype", overlay=true,default_qty_type=strategy.cash,default_qty_value=500,commission_type=strategy.commission.percent,commission_value=0.04)-Periods = input(title="ATR Period", type=input.integer, defval=10)//sefval원래값이10이였음(이평선 일)+Periods = input.int(title="ATR Period", defval=10)//sefval원래값이10이였음(이평선 일)src1 = input(hl2, title="Source")-Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)+Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)-changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)+changeATR= input.bool(title="Change ATR Calculation Method ?", defval=true)-showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)+showsignals = input.bool(title="Show Buy/Sell Signals ?", defval=true)-highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)+highlighting = input.bool(title="Highlighter On/Off ?", defval=true)-atr2 = sma(tr, Periods)+atr2 = ta.sma(ta.tr, Periods)-atr= changeATR ? atr(Periods) : atr2+atr= changeATR ? ta.atr(Periods) : atr2up=src1-(Multiplier*atr)up1 = nz(up[1],up)-up := close[1] > up1 ? max(up,up1) : up+up := close[1] > up1 ? math.max(up,up1) : updn=src1+(Multiplier*atr)dn1 = nz(dn[1], dn)-dn := close[1] < dn1 ? min(dn, dn1) : dn+dn := close[1] < dn1 ? math.min(dn, dn1) : dntrend = 1⋯buySignal = trend == 1 and trend[1] == -1-plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)+plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))-plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)sellSignal = trend == -1 and trend[1] == 1-plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)+plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))-plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)length1=input(1)⋯length120=input(120)-ma1= sma(close,length1)+ma1= ta.sma(close,length1)-ma3= sma(close,length3)+ma3= ta.sma(close,length3)-ma7= sma(close,length7)+ma7= ta.sma(close,length7)-ma9= sma(close,length9)+ma9= ta.sma(close,length9)-ma14=sma(close,length14)+ma14=ta.sma(close,length14)-ma20=sma(close,length20)+ma20=ta.sma(close,length20)-ma60=sma(close,length60)+ma60=ta.sma(close,length60)-ma120=sma(close,length120)+ma120=ta.sma(close,length120)-rsi=rsi(close,14)+rsi=ta.rsi(close,14)// BUYING VOLUME AND SELLING VOLUME //-BV = iff( (high==low), 0, volume*(close-low)/(high-low))+BV = ( (high==low) ? 0 : volume*(close-low)/(high-low))-SV = iff( (high==low), 0, volume*(high-close)/(high-low))+SV = ( (high==low) ? 0 : volume*(high-close)/(high-low))-vol = iff(volume > 0, volume, 1)+vol = (volume > 0 ? volume : 1)-dailyLength = input(title = "Daily MA length", type = input.integer, defval = 50, minval = 1, maxval = 100)+dailyLength = input.int(title = "Daily MA length", defval = 50, minval = 1, maxval = 100)-weeklyLength = input(title = "Weekly MA length", type = input.integer, defval = 10, minval = 1, maxval = 100)+weeklyLength = input.int(title = "Weekly MA length", defval = 10, minval = 1, maxval = 100)//------------------------------------------------------------Davgvol = sma(volume, dailyLength)+Davgvol = ta.sma(volume, dailyLength)-Wavgvol = sma(volume, weeklyLength)+Wavgvol = ta.sma(volume, weeklyLength)//-----------------------------------------------------------⋯mult4= input(2.5, minval=0.001, maxval=50, title="exp2")-basis = sma(src, length)+basis = ta.sma(src, length)-dev = mult * stdev(src, length)+dev = mult * ta.stdev(src, length)upper = basis + devlower = basis - dev-dev2= mult2 * stdev(src, length)+dev2= mult2 * ta.stdev(src, length)Supper= basis + dev2Slower= basis - dev2-dev3= mult3 * stdev(src, length)+dev3= mult3 * ta.stdev(src, length)upper1= basis + dev3lower1= basis - dev3-dev4= mult4 * stdev(src, length)+dev4= mult4 * ta.stdev(src, length)upper2=basis + dev4lower2=basis - dev4-offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)+offset = input.int(0, "Offset", minval = -500, maxval = 500)plot(basis, "Basis", color=#FF6D00, offset = offset)⋯imInATrade = strategy.position_size != 0-highestPriceAfterEntry = valuewhen(imInATrade, high, 0)+highestPriceAfterEntry = ta.valuewhen(imInATrade, high, 0)//////////////////////////////////////////////////////////////////////////////////⋯//////////////////////////////////////////////////////////////////////////////////-if (low<ma20 and low<lower1 and close<Slower and crossunder(ma60,ma120)and bear)+if (low<ma20 and low<lower1 and close<Slower and ta.crossunder(ma60,ma120)and bear)    strategy.entry("Short",strategy.short)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 7: input() → input.source()
  • Line 31: input() → input.int()
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 34: input() → input.int()
  • Line 35: input() → input.int()
9 more edits
  • Line 36: input() → input.int()
  • Line 37: input() → input.int()
  • Line 38: input() → input.int()
  • Line 58: input() → input.int()
  • Line 59: input() → input.source()
  • Line 60: input() → input.float()
  • Line 61: input() → input.float()
  • Line 62: input() → input.float()
  • Line 63: input() → input.float()
⋯Periods = input.int(title="ATR Period", defval=10)//sefval원래값이10이였음(이평선 일)-src1 = input(hl2, title="Source")+src1 = input.source(hl2, title="Source")Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)⋯plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)-length1=input(1)+length1=input.int(1)-length3=input(3)+length3=input.int(3)-length7=input(7)+length7=input.int(7)-length9=input(9)+length9=input.int(9)-length14=input(14)+length14=input.int(14)-length20=input(20)+length20=input.int(20)-length60=input(60)+length60=input.int(60)-length120=input(120)+length120=input.int(120)ma1= ta.sma(close,length1)⋯//------------------------------------------------------------length = input(20, minval=1)+length = input.int(20, minval=1)-src = input(close, title="Source")+src = input.source(close, title="Source")-mult = input(2.0, minval=0.001, maxval=50, title="StdDev")+mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")-mult2= input(1.5, minval=0.001, maxval=50, title="exp")+mult2= input.float(1.5, minval=0.001, maxval=50, title="exp")-mult3= input(1.0, minval=0.001, maxval=50, title="exp1")+mult3= input.float(1.0, minval=0.001, maxval=50, title="exp1")-mult4= input(2.5, minval=0.001, maxval=50, title="exp2")+mult4= input.float(2.5, minval=0.001, maxval=50, title="exp2")basis = ta.sma(src, length)⋯

Does it run in Pine Script v6?

Yes

Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © KAIST291-//@version=5+//@version=6initial_capital=1000⋯

Settings

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

SettingDefaultType and rangeFeeds
ATR Period10int (written input.integer)atr2 atr
Sourcehl2sourceup dn
ATR Multiplier3.0float · step 0.1up dn
Change ATR Calculation Method ?trueboolatr
Show Buy/Sell Signals ?trueboolBuy Sell
Highlighter On/Off ?trueboolunused
Length1 (no label in the script)1intma1
Length3 (no label in the script)3intma3
Length7 (no label in the script)7intma7
Length9 (no label in the script)9intma9
Length14 (no label in the script)14intma14
Length20 (no label in the script)20intma20
Length60 (no label in the script)60intma60
Length120 (no label in the script)120intma120
Daily MA length50int (written input.integer) · min 1 · max 100Davgvol
Weekly MA length10int (written input.integer) · min 1 · max 100Wavgvol
Length (no label in the script)20int · min 1basis dev dev2 dev3 dev4
Sourceclosesourcebasis dev dev2 dev3 dev4
StdDev2.0float · min 0.001 · max 50dev
exp1.5float · min 0.001 · max 50dev2
exp11.0float · min 0.001 · max 50dev3
exp22.5float · min 0.001 · max 50dev4
Offset0int (written input.integer) · min -500 · max 500Upper Lower Basis

What it calculates

  • SMA (sma, ta.sma in v5)tr, ATR Period (10)atr2 · line 12
  • ATR (atr, ta.atr in v5)ATR Period (10)atr · line 13
  • SMA (sma, ta.sma in v5)close, Length1 (1)ma1 · line 39
  • SMA (sma, ta.sma in v5)close, Length3 (3)ma3 · line 40
  • SMA (sma, ta.sma in v5)close, Length7 (7)ma7 · line 41
  • SMA (sma, ta.sma in v5)close, Length9 (9)ma9 · line 42
  • SMA (sma, ta.sma in v5)close, Length14 (14)ma14 · line 43
  • SMA (sma, ta.sma in v5)close, Length20 (20)ma20 · line 44
  • SMA (sma, ta.sma in v5)close, Length60 (60)ma60 · line 45
  • SMA (sma, ta.sma in v5)close, Length120 (120)ma120 · line 46
  • RSI (rsi, ta.rsi in v5)close, 14rsi · line 47
  • SMA (sma, ta.sma in v5)volume, Daily MA length (50)Davgvol · line 55
  • SMA (sma, ta.sma in v5)volume, Weekly MA length (10)Wavgvol · line 56
  • SMA (sma, ta.sma in v5)Source (close), Length (20)basis · line 64
  • Stdev (stdev, ta.stdev in v5)Source (close), Length (20)dev · line 65
  • Stdev (stdev, ta.stdev in v5)Source (close), Length (20)dev2 · line 68
  • Stdev (stdev, ta.stdev in v5)Source (close), Length (20)dev3 · line 71
  • Stdev (stdev, ta.stdev in v5)Source (close), Length (20)dev4 · line 74
  • Valuewhen (valuewhen, ta.valuewhen in v5)imInATrade, high, 0highestPriceAfterEntry · line 90

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

Order rules

OrderFires whenBy defaultLine
Open Long long(bull and open>upper1 and open>Supper and open>upper and (trend == 1 ? up : na) and longcondition)On98
Close Long(strategy.openprofit>5)On102
Close Long(rsi>80 and strategy.position_avg_price*1.004<close)On104
Close Long(close < strategy.position_avg_price*0.91)On106
Close Long(open>upper and strategy.position_avg_price*1.004<close)On108
Close Long(strategy.position_size>0 and (trend == 1 ? na : dn))On111
Open Short short(low<ma20 and low<lower1 and close<Slower and crossunder(ma60,ma120)and bear)On114
Open Short short(ma3<ma9 and ma9<ma20 and ma20<ma60 and bear and (trend == 1 ? na : dn) and high<ma20 and close<lower1 and high<Slower and rsi>30)On116
Close Short(strategy.openprofit>10)On120
Close Short(rsi<20 and close<strategy.position_avg_price*0.996)On122
Close Short(high<lower and close<strategy.position_avg_price*0.996)On124
Close Short(strategy.openprofit < strategy.position_avg_price*0.92-close)On126
Close Short(strategy.position_size<0 and (trend == 1 ? up : na))On128
Close Short(open<lower and close<strategy.position_avg_price*0.996)On130

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • 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−0.1%+102.5%580%0.340.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.0%+5.5%580%2.820.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.2%+9.8%888%4.400.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%3100%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%3100%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%1100%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%475%0.560.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%5100%—0.0%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 market475%−$87.91
Sideways market0—$0.00
Falling market1100%$14.07

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

How bad could the drawdown be?

0.1%

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

0%1%
All 5 trades
SideEntryExitBarsP&L
short2 May 2024 58,365.0021 May 2024 71,446.6019−$112.51
long8 Nov 2024 75,857.9010 Nov 2024 76,677.502$5.00
long13 Nov 2024 87,952.0014 Nov 2024 90,375.201$13.37
short11 Mar 2025 78,595.909 Apr 2025 76,322.4029$14.07
long12 Jul 2025 117,528.0014 Jul 2025 119,087.002$6.23

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
Bollinger band & Volume based strategy V2 this page—v4 strategy−0.1%50.2%
Impulse Strategy Signals V2 by danieljordisma rsi atr valuewhenv5 strategyNo trades on this market
Golden Swing Strategy - Souradeep Dey by rajm14rsi sma atr stdevv5 strategy−0.0%110.0%
Volume and Moving average,will this model working in real-trade- by Ayden_Csma rsi stdev valuewhenv4 strategy−157,995.0%104,752.1%
[KL] Bollinger bands + RSI Strategy by DojiEmojisma stdev atr rsiv4 strategy+28.2%3014.7%
[KL] Bollinger Bands Consolidation Strategy by DojiEmojisma stdev atr rsiv4 strategy+39.1%3319.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 45 msYes 1,000 bars in 103 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.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © KAIST291//@version=4initial_capital=1000strategy("prototype", overlay=true,default_qty_type=strategy.cash,default_qty_value=500,commission_type=strategy.commission.percent,commission_value=0.04)Periods = input(title="ATR Period", type=input.integer, defval=10)//sefval원래값이10이였음(이평선 일)src1 = input(hl2, title="Source")Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)atr2 = sma(tr, Periods)atr= changeATR ? atr(Periods) : atr2up=src1-(Multiplier*atr)up1 = nz(up[1],up)up := close[1] > up1 ? max(up,up1) : updn=src1+(Multiplier*atr)dn1 = nz(dn[1], dn)dn := close[1] < dn1 ? min(dn, dn1) : dntrend = 1trend := nz(trend[1], trend)trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trendupPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)buySignal = trend == 1 and trend[1] == -1plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)sellSignal = trend == -1 and trend[1] == 1plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)length1=input(1)length3=input(3)length7=input(7)length9=input(9)length14=input(14)length20=input(20)length60=input(60)length120=input(120)ma1= sma(close,length1)ma3= sma(close,length3)ma7= sma(close,length7)ma9= sma(close,length9)ma14=sma(close,length14)ma20=sma(close,length20)ma60=sma(close,length60)ma120=sma(close,length120)rsi=rsi(close,14)// BUYING VOLUME AND SELLING VOLUME //BV = iff( (high==low), 0, volume*(close-low)/(high-low))SV = iff( (high==low), 0, volume*(high-close)/(high-low))vol = iff(volume > 0, volume, 1)dailyLength = input(title = "Daily MA length", type = input.integer, defval = 50, minval = 1, maxval = 100)weeklyLength = input(title = "Weekly MA length", type = input.integer, defval = 10, minval = 1, maxval = 100)//-----------------------------------------------------------Davgvol = sma(volume, dailyLength)Wavgvol = sma(volume, weeklyLength)//-----------------------------------------------------------length = input(20, minval=1)src = input(close, title="Source")mult = input(2.0, minval=0.001, maxval=50, title="StdDev")mult2= input(1.5, minval=0.001, maxval=50, title="exp")mult3= input(1.0, minval=0.001, maxval=50, title="exp1")mult4= input(2.5, minval=0.001, maxval=50, title="exp2")basis = sma(src, length)dev = mult * stdev(src, length)upper = basis + devlower = basis - devdev2= mult2 * stdev(src, length)Supper= basis + dev2Slower= basis - dev2dev3= mult3 * stdev(src, length)upper1= basis + dev3lower1= basis - dev3dev4= mult4 * stdev(src, length)upper2=basis + dev4lower2=basis - dev4offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)plot(basis, "Basis", color=#FF6D00, offset = offset)p1 = plot(upper, "Upper", color=#2962FF, offset = offset)p2 = plot(lower, "Lower", color=#2962FF, offset = offset)fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))//----------------------------------------------------exit=(close-strategy.position_avg_price / strategy.position_avg_price*100)bull=( BV>SV and BV>Davgvol)bull2=(BV>SV and BV>Davgvol)bux =(close>Supper and close>Slower and volume<Davgvol)bear=(SV>BV and SV>Davgvol)con=(BV>Wavgvol and rsi>80)imInATrade = strategy.position_size != 0highestPriceAfterEntry = valuewhen(imInATrade, high, 0)//////////////////////////////////////////////////////////////////////////////////sec=((open[1]-close[1])/(high[1]-low[1]))wgt=1-seclongcondition = (low+wgt)<(open)shortcondition= (low+wgt)>(open)// STRATEGY LONG //if (bull and open>upper1 and open>Supper and open>upper and (trend == 1 ? up : na) and longcondition)    strategy.entry("Long",strategy.long)    //////////////////////////////////////////////////////////////////////////////////if (strategy.openprofit>5)    strategy.close("Long")else if (rsi>80 and strategy.position_avg_price*1.004<close)    strategy.close("Long")else if (close < strategy.position_avg_price*0.91)    strategy.close("Long")else if (open>upper and strategy.position_avg_price*1.004<close)    strategy.close("Long")//////////////////////////////////////////////////////////////////////////////////if (strategy.position_size>0 and (trend == 1 ? na : dn))    strategy.close("Long")//////////////////////////////////////////////////////////////////////////////////if (low<ma20 and low<lower1 and close<Slower and crossunder(ma60,ma120)and bear)    strategy.entry("Short",strategy.short)else if (ma3<ma9 and ma9<ma20 and ma20<ma60 and bear and (trend == 1 ? na : dn) and high<ma20 and close<lower1 and high<Slower and rsi>30)    strategy.entry("Short",strategy.short)        if (strategy.openprofit>10)    strategy.close("Short")else if (rsi<20 and close<strategy.position_avg_price*0.996)    strategy.close("Short")else if (high<lower and close<strategy.position_avg_price*0.996)    strategy.close("Short")else if (strategy.openprofit < strategy.position_avg_price*0.92-close)    strategy.close("Short")else if (strategy.position_size<0 and (trend == 1 ? up : na))    strategy.close("Short")else if (open<lower and close<strategy.position_avg_price*0.996)    strategy.close("Short")