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
- 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
VerifiedSame 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)⋯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.
⋯// © 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| ATR Period | 10 | int (written input.integer) | atr2 atr |
| Source | hl2 | source | up dn |
| ATR Multiplier | 3.0 | float · step 0.1 | up dn |
| Change ATR Calculation Method ? | true | bool | atr |
| Show Buy/Sell Signals ? | true | bool | Buy Sell |
| Highlighter On/Off ? | true | bool | unused |
| Length1 (no label in the script) | 1 | int | ma1 |
| Length3 (no label in the script) | 3 | int | ma3 |
| Length7 (no label in the script) | 7 | int | ma7 |
| Length9 (no label in the script) | 9 | int | ma9 |
| Length14 (no label in the script) | 14 | int | ma14 |
| Length20 (no label in the script) | 20 | int | ma20 |
| Length60 (no label in the script) | 60 | int | ma60 |
| Length120 (no label in the script) | 120 | int | ma120 |
| Daily MA length | 50 | int (written input.integer) · min 1 · max 100 | Davgvol |
| Weekly MA length | 10 | int (written input.integer) · min 1 · max 100 | Wavgvol |
| Length (no label in the script) | 20 | int · min 1 | basis dev dev2 dev3 dev4 |
| Source | close | source | basis dev dev2 dev3 dev4 |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev |
| exp | 1.5 | float · min 0.001 · max 50 | dev2 |
| exp1 | 1.0 | float · min 0.001 · max 50 | dev3 |
| exp2 | 2.5 | float · min 0.001 · max 50 | dev4 |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | Upper Lower Basis |
What it calculates
- SMA (
sma,ta.smain v5)tr, ATR Period (10)atr2 · line 12 - ATR (
atr,ta.atrin v5)ATR Period (10)atr · line 13 - SMA (
sma,ta.smain v5)close, Length1 (1)ma1 · line 39 - SMA (
sma,ta.smain v5)close, Length3 (3)ma3 · line 40 - SMA (
sma,ta.smain v5)close, Length7 (7)ma7 · line 41 - SMA (
sma,ta.smain v5)close, Length9 (9)ma9 · line 42 - SMA (
sma,ta.smain v5)close, Length14 (14)ma14 · line 43 - SMA (
sma,ta.smain v5)close, Length20 (20)ma20 · line 44 - SMA (
sma,ta.smain v5)close, Length60 (60)ma60 · line 45 - SMA (
sma,ta.smain v5)close, Length120 (120)ma120 · line 46 - RSI (
rsi,ta.rsiin v5)close, 14rsi · line 47 - SMA (
sma,ta.smain v5)volume, Daily MA length (50)Davgvol · line 55 - SMA (
sma,ta.smain v5)volume, Weekly MA length (10)Wavgvol · line 56 - SMA (
sma,ta.smain v5)Source (close), Length (20)basis · line 64 - Stdev (
stdev,ta.stdevin v5)Source (close), Length (20)dev · line 65 - Stdev (
stdev,ta.stdevin v5)Source (close), Length (20)dev2 · line 68 - Stdev (
stdev,ta.stdevin v5)Source (close), Length (20)dev3 · line 71 - Stdev (
stdev,ta.stdevin v5)Source (close), Length (20)dev4 · line 74 - Valuewhen (
valuewhen,ta.valuewhenin 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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (bull and open>upper1 and open>Supper and open>upper and (trend == 1 ? up : na) and longcondition) | On | 98 |
| Close Long | (strategy.openprofit>5) | On | 102 |
| Close Long | (rsi>80 and strategy.position_avg_price*1.004<close) | On | 104 |
| Close Long | (close < strategy.position_avg_price*0.91) | On | 106 |
| Close Long | (open>upper and strategy.position_avg_price*1.004<close) | On | 108 |
| Close Long | (strategy.position_size>0 and (trend == 1 ? na : dn)) | On | 111 |
| Open Short short | (low<ma20 and low<lower1 and close<Slower and crossunder(ma60,ma120)and bear) | On | 114 |
| 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) | On | 116 |
| Close Short | (strategy.openprofit>10) | On | 120 |
| Close Short | (rsi<20 and close<strategy.position_avg_price*0.996) | On | 122 |
| Close Short | (high<lower and close<strategy.position_avg_price*0.996) | On | 124 |
| Close Short | (strategy.openprofit < strategy.position_avg_price*0.92-close) | On | 126 |
| Close Short | (strategy.position_size<0 and (trend == 1 ? up : na)) | On | 128 |
| Close Short | (open<lower and close<strategy.position_avg_price*0.996) | On | 130 |
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.
- 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 | −0.1% | +102.5% | 5 | 80% | 0.34 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.0% | +5.5% | 5 | 80% | 2.82 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.2% | +9.8% | 8 | 88% | 4.40 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.1% | +8.4% | 3 | 100% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 3 | 100% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 1 | 100% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 4 | 75% | 0.56 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 5 | 100% | — | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 4 | 75% | −$87.91 |
| Sideways market | 0 | — | $0.00 |
| Falling market | 1 | 100% | $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.
All 5 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 2 May 2024 58,365.00 | 21 May 2024 71,446.60 | 19 | −$112.51 |
| long | 8 Nov 2024 75,857.90 | 10 Nov 2024 76,677.50 | 2 | $5.00 |
| long | 13 Nov 2024 87,952.00 | 14 Nov 2024 90,375.20 | 1 | $13.37 |
| short | 11 Mar 2025 78,595.90 | 9 Apr 2025 76,322.40 | 29 | $14.07 |
| long | 12 Jul 2025 117,528.00 | 14 Jul 2025 119,087.00 | 2 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Bollinger band & Volume based strategy V2 this page | — | v4 strategy | −0.1% | 5 | 0.2% |
| Impulse Strategy Signals V2 by danieljordi | sma rsi atr valuewhen | v5 strategy | No trades on this market | ||
| Golden Swing Strategy - Souradeep Dey by rajm14 | rsi sma atr stdev | v5 strategy | −0.0% | 11 | 0.0% |
| Volume and Moving average,will this model working in real-trade- by Ayden_C | sma rsi stdev valuewhen | v4 strategy | −157,995.0% | 10 | 4,752.1% |
| [KL] Bollinger bands + RSI Strategy by DojiEmoji | sma stdev atr rsi | v4 strategy | +28.2% | 30 | 14.7% |
| [KL] Bollinger Bands Consolidation Strategy by DojiEmoji | sma stdev atr rsi | v4 strategy | +39.1% | 33 | 19.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 45 ms | Yes 1,000 bars in 103 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/// © 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")