Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[KL] Relative Volume Strategy

A Pine Script v4 strategy built on SMA (BOLL_src, BOLL_length) and Stdev (BOLL_src, BOLL_length). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 9 settings; defaults include Length of ATR to determine volality 10, Length of ATR for trailing stop loss 10 and ATR Multiplier for trailing stop loss 2.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 [KL] Relative Volume Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
How did [KL] Relative Volume Strategy do on BTCUSDT 1D with default settings?
+9.02%
From 26 Jan 2024 to 21 Oct 2026, over 30 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can [KL] Relative Volume 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 [KL] Relative Volume Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does [KL] Relative Volume Strategy run in Zeal Terminal?
Yes
It compiles in 21 ms and runs 1,000 bars in 55 ms, in the browser.

BTCUSDT · 1D · default settings

  • Basis
  • BOLL Upper
  • BOLL Lower
  • SMA20 + ATR_X2_volat
  • SMA20 - ATR_X2_volat
  • ATR_X2_volat
  • Plot
  • 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,000AprJulOct2025AprJulOct2026AprJulOct$110,561$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
+9.02%
$9,024.38
Buy and hold
+102.5%
same period
Closed trades
30
11 won · 19 lost
Profitable
36.7%
of closed trades
Profit factor
1.08
gross profit ÷ gross loss
Max drawdown
32.88%
−$39,744.00

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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

    No stop loss

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

  • 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 56. 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, atr → ta.atr, max → math.max, min → math.min.
  • 1 strategy call uses the when = argument (line 56). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 7: input(type = input.time) → input.time()
  • Line 9: input(type = input.time) → input.time()
  • Line 13: sma → ta.sma
  • Line 13: stdev → ta.stdev
  • Line 19: atr → ta.atr
7 more edits
  • Line 25: atr → ta.atr
  • Line 25: input(type = input.float) → input.float()
  • Line 33: max → math.max
  • Line 38: sma → ta.sma
  • Line 39: input(type = input.float) → input.float()
  • Line 40: min → math.min
  • Line 44: input(type = input.float) → input.float()
⋯// © DojiEmoji (kevinhhl)-//@version=4+//@version=5strategy("[KL] Relative Volume Strategy",overlay=true,pyramiding=1)⋯// Timeframe {-backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)+backtest_timeframe_start = input.time(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time")USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")-backtest_timeframe_end = input(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)+backtest_timeframe_end = input.time(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)")within_timeframe = time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)⋯// Volatility Indicators {-BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)+BOLL_length = 20, BOLL_src = close, SMA20 = ta.sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * ta.stdev(BOLL_src, BOLL_length)BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2⋯fill(BOLL_p1, BOLL_p2, title = "Background", color=color.new(#198787,90))-ATR_X2_volat = atr(input(10,title="Length of ATR to determine volality"))*2+ATR_X2_volat = ta.atr(input(10,title="Length of ATR to determine volality"))*2plot(SMA20+ATR_X2_volat, "SMA20 + ATR_X2_volat", color=color.new(color.gray,75), offset = 0)⋯// Trailing stop loss {-ATR_X2_TSL = atr(input(10,title="Length of ATR for trailing stop loss")) * input(2.0,title="ATR Multiplier for trailing stop loss",type=input.float)+ATR_X2_TSL = ta.atr(input(10,title="Length of ATR for trailing stop loss")) * input.float(2.0,title="ATR Multiplier for trailing stop loss")TSL_source = low⋯else if strategy.position_size > 0-    stop_loss_price := max(stop_loss_price, TSL_source - ATR_X2_TSL)+    stop_loss_price := math.max(stop_loss_price, TSL_source - ATR_X2_TSL)    TSL_transp := 0⋯// Signals for entry {-_avg_vol = sma(volume,input(5, title="SMA(volume) length (for relative comparison)"))+_avg_vol = ta.sma(volume,input(5, title="SMA(volume) length (for relative comparison)"))-_relative_vol = _avg_vol * input(1,title="Multiple of avg vol to consider relative volume as being high",type=input.float)+_relative_vol = _avg_vol * input.float(1,title="Multiple of avg vol to consider relative volume as being high")-__lowerOfOpenClose = min(open,close)+__lowerOfOpenClose = math.min(open,close)_wickRatio_lower = (__lowerOfOpenClose - low) / (high - low)⋯entry_signal2 = ATR_X2_volat > BOLL_sDEV_x2-entry_signal3 = _wickRatio_lower > input(0.1,title="Wick ratio (lower:high-low) of entry bar",type=input.float)+entry_signal3 = _wickRatio_lower > input.float(0.1,title="Wick ratio (lower:high-low) of entry bar")// }⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.bool()
  • Line 19: input() → input.int()
  • Line 25: input() → input.int()
  • Line 38: input() → input.int()
  • Line 56: when = exit_condition → if block
⋯backtest_timeframe_start = input.time(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time")-USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")+USE_ENDTIME = input.bool(false,title="Define backtest end-time (If false, will test up to most recent candle)")backtest_timeframe_end = input.time(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)")⋯fill(BOLL_p1, BOLL_p2, title = "Background", color=color.new(#198787,90))-ATR_X2_volat = ta.atr(input(10,title="Length of ATR to determine volality"))*2+ATR_X2_volat = ta.atr(input.int(10,title="Length of ATR to determine volality"))*2plot(SMA20+ATR_X2_volat, "SMA20 + ATR_X2_volat", color=color.new(color.gray,75), offset = 0)⋯// Trailing stop loss {-ATR_X2_TSL = ta.atr(input(10,title="Length of ATR for trailing stop loss")) * input.float(2.0,title="ATR Multiplier for trailing stop loss")+ATR_X2_TSL = ta.atr(input.int(10,title="Length of ATR for trailing stop loss")) * input.float(2.0,title="ATR Multiplier for trailing stop loss")TSL_source = low⋯// Signals for entry {-_avg_vol = ta.sma(volume,input(5, title="SMA(volume) length (for relative comparison)"))+_avg_vol = ta.sma(volume,input.int(5, title="SMA(volume) length (for relative comparison)"))_relative_vol = _avg_vol * input.float(1,title="Multiple of avg vol to consider relative volume as being high")⋯        exit_condition = TSL_source <= stop_loss_price-        strategy.close(ENUM_LONG, when=exit_condition, comment=exit_msg)+        if exit_condition+            strategy.close(ENUM_LONG, comment=exit_msg)// CLEAN UP:⋯

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: 30 before, 29 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.

⋯// © DojiEmoji (kevinhhl)-//@version=5+//@version=6strategy("[KL] Relative Volume Strategy",overlay=true,pyramiding=1)⋯

Settings

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

SettingDefaultType and rangeFeeds
Backtest Start Timetimestamp("01 Apr 2016 13:30 +0000")timewithin_timeframe
Define backtest end-time (If false, will test up to most recent candle)falseboolwithin_timeframe
Backtest End Time (if checked above)timestamp("01 May 2021 19:30 +0000")timewithin_timeframe
Length of ATR to determine volality10intentry_signal2 SMA20 + ATR_X2_volat SMA20 - ATR_X2_volat plotchar
Length of ATR for trailing stop loss10intstop_loss_price
ATR Multiplier for trailing stop loss2.0floatstop_loss_price
SMA(volume) length (for relative comparison)5int_relative_vol
Multiple of avg vol to consider relative volume as being high1floatentry_signal1
Wick ratio (lower:high-low) of entry bar0.1floatentry Long line 49

What it calculates

  • SMA (sma, ta.sma in v5)BOLL_src, BOLL_lengthSMA20 · line 13
  • Stdev (stdev, ta.stdev in v5)BOLL_src, BOLL_lengthBOLL_sDEV_x2 · line 13

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.

closecloseprice datalowlowprice dataATR_X2_TSLATR Multiplier for trai…setting · 2.0openopenprice datahighhighprice datavolumevolumeprice data_relative_volMultiple of avg vol to …setting · 1ATR_X2_volatLength of ATR to determ…setting · 10timetimeprice databacktest_timeframe_startBacktest Start Timesetting · timestamp("01 Apr 2…backtest_timeframe_endBacktest End Time (if c…setting · timestamp("01 May 2…entry_signal3Wick ratio (lower:high-…setting · 0.1SMA20SMA→ SMA20BOLL_sDEV_x2Stdev→ BOLL_sDEV_x2BOLL_src, exit_msgBOLL_src · exit_msg2 valuesBOLL_upper, BOLL_lowerBOLL_upper · BOLL_lower2 valuesTSL_sourceTSL_sourcevaluestop_loss_pricestop_loss_pricevalue__lowerOfOpenClose__lowerOfOpenClosevalue_wickRatio_lower_wickRatio_lowervalueentry_msgentry_msgvalueentry_signal1entry_signal1conditionentry_signal2entry_signal2conditionexit_conditionexit_conditionconditionwithin_timeframewithin_timeframeconditionTSL_line_colorColourTSL_line_colorentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeplot:15Basisplotplot:16BOLL Upperplotplot:17BOLL Lowerplotfill:BackgroundBackgroundfillplot:20SMA20 + ATR_X2_volatplotplot:21SMA20 - ATR_X2_volatplotplotchar:22plotcharplotcharplot:35plotplot

Order rules

OrderFires whenBy defaultLine
Open Long longentry_signal1 and entry_signal2 and entry_signal3On51
Close Longexit_conditionTSL_source <= stop_loss_priceOn56

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.

5/5trades 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+9.0%+102.5%3037%1.0832.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−4.4%+5.5%3426%0.8919.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.3%+9.8%3330%0.942.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.2%+8.4%3033%1.180.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%3348%1.230.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%3135%1.110.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%2948%1.160.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%3333%0.900.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 market1040%$18,632.50
Sideways market1527%−$34,590.40
Falling market560%$24,982.30

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

How bad could the drawdown be?

50.7%

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

0%58%
All 30 trades
SideEntryExitBarsP&L
long21 Mar 2024 67,840.5014 Apr 2024 63,924.5024−$3,915.99
long15 Apr 2024 65,661.902 May 2024 58,365.0017−$7,296.88
long3 May 2024 59,060.6012 Jun 2024 67,314.2040$8,253.63
long13 Jun 2024 68,264.0025 Jun 2024 60,293.3012−$7,970.68
long2 Aug 2024 65,354.006 Aug 2024 54,018.804−$11,335.20
long20 Aug 2024 59,438.5028 Aug 2024 59,415.008−$23.50
long29 Aug 2024 59,034.907 Sep 2024 53,963.009−$5,071.93
long17 Sep 2024 58,214.002 Oct 2024 60,804.9015$2,590.93
long9 Oct 2024 62,160.505 Nov 2024 67,850.0027$5,689.51
long6 Nov 2024 69,372.0020 Dec 2024 97,461.9044$28,089.90
long21 Dec 2024 97,805.4010 Jan 2025 92,552.5020−$5,252.95
long14 Jan 2025 94,536.104 Feb 2025 101,329.0021$6,792.40
long5 Feb 2025 97,763.1026 Feb 2025 88,680.4021−$9,082.75
long27 Feb 2025 84,250.1012 Mar 2025 82,933.0013−$1,317.10
long21 Mar 2025 84,223.407 Apr 2025 78,430.0017−$5,793.38
long8 Apr 2025 79,163.206 Jun 2025 101,509.0059$22,345.40
long11 Jun 2025 110,274.0022 Jun 2025 102,120.0011−$8,154.37
long23 Jun 2025 100,964.002 Aug 2025 113,298.0040$12,334.10
long8 Aug 2025 117,472.0020 Aug 2025 112,873.0012−$4,599.07
long21 Aug 2025 114,271.0030 Aug 2025 108,377.009−$5,893.83
long6 Sep 2025 110,660.0024 Sep 2025 111,999.0018$1,338.80
long25 Sep 2025 113,307.0011 Oct 2025 112,774.0016−$532.52
long29 Oct 2025 112,898.005 Nov 2025 101,497.007−$11,401.20
long6 Nov 2025 103,885.0015 Nov 2025 94,594.009−$9,291.16
long9 Dec 2025 90,634.4021 Jan 2026 88,427.7043−$2,206.69
long22 Jan 2026 89,454.7030 Jan 2026 84,650.208−$4,804.57
long24 Feb 2026 64,656.0023 Mar 2026 67,859.0027$3,202.99
long25 Mar 2026 70,556.7019 May 2026 77,001.9055$6,445.14
long24 May 2026 76,752.0029 May 2026 73,617.505−$3,134.48
long24 Jun 2026 62,734.609 Oct 2026 81,754.50107$19,019.90

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
[KL] Relative Volume Strategy this page—v4 strategy+9.0%3032.9%
Double Bollinger Binary Options by Trade_by_DBsma stdevv5 strategyNo trades on this market
Improved Bollinger Swing Strategy Stock Nasdaq by exlux99sma stdevv4 strategy−20.4%722.3%
I11L Long Put-Call Ratio Inversion by I11Lsma stdevv5 strategyNo trades on this market
P-Signal Strategy by Kharevskystdev smav4 strategy−9.7%2934.6%
P-Signal Strategy & Alert by Kharevskystdev smav4 strategy−9.7%2934.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 21 msYes 1,000 bars in 55 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/// © DojiEmoji (kevinhhl)//@version=4strategy("[KL] Relative Volume Strategy",overlay=true,pyramiding=1)ENUM_LONG = "Long"// Timeframe {backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")backtest_timeframe_end = input(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)within_timeframe = time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)// }// Volatility Indicators {BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2plot(SMA20, "Basis", color=#872323, offset = 0)BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.new(color.navy,50), offset = 0)BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.new(color.navy,50), offset = 0)fill(BOLL_p1, BOLL_p2, title = "Background", color=color.new(#198787,90))ATR_X2_volat = atr(input(10,title="Length of ATR to determine volality"))*2plot(SMA20+ATR_X2_volat, "SMA20 + ATR_X2_volat", color=color.new(color.gray,75), offset = 0)plot(SMA20-ATR_X2_volat, "SMA20 - ATR_X2_volat", color=color.new(color.gray,75), offset = 0)plotchar(ATR_X2_volat, "ATR_X2_volat", "", location = location.bottom)// }// Trailing stop loss {ATR_X2_TSL = atr(input(10,title="Length of ATR for trailing stop loss")) * input(2.0,title="ATR Multiplier for trailing stop loss",type=input.float)TSL_source = lowvar stop_loss_price = float(0)TSL_line_color = color.green, TSL_transp = 100if strategy.position_size == 0 or not within_timeframe    TSL_line_color := color.black    stop_loss_price := TSL_source - ATR_X2_TSL else if strategy.position_size > 0    stop_loss_price := max(stop_loss_price, TSL_source - ATR_X2_TSL)    TSL_transp := 0plot(stop_loss_price, color=color.new(TSL_line_color, TSL_transp))// }// Signals for entry {_avg_vol = sma(volume,input(5, title="SMA(volume) length (for relative comparison)"))_relative_vol = _avg_vol * input(1,title="Multiple of avg vol to consider relative volume as being high",type=input.float)__lowerOfOpenClose = min(open,close)_wickRatio_lower = (__lowerOfOpenClose - low) / (high - low)entry_signal1 = volume > _relative_volentry_signal2 = ATR_X2_volat > BOLL_sDEV_x2entry_signal3 = _wickRatio_lower > input(0.1,title="Wick ratio (lower:high-low) of entry bar",type=input.float)// }// MAIN:if within_timeframe    // ENTRY :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::    if entry_signal1 and entry_signal2 and entry_signal3        entry_msg = strategy.position_size > 0 ? "adding" : "initial"        strategy.entry(ENUM_LONG, strategy.long, comment=entry_msg)    // EXIT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::    exit_msg = close <= strategy.position_avg_price ? "stop loss" : "take profit"    if strategy.position_size > 0        exit_condition = TSL_source <= stop_loss_price        strategy.close(ENUM_LONG, when=exit_condition, comment=exit_msg)// CLEAN UP:if strategy.position_size == 0    stop_loss_price := float(0)