Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

OBV Pyr

A Pine Script v4 strategy built on EMA (source, 250), Change (src) and CUM (nv). It has 14 order rules, 7 entries among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 20% of equity and pays 0.075% commission. 6 settings; defaults include Strategy Direction long, Fast filter length 250 and Slow filter length 500.

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 OBV Pyr repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 7 of 7 trades.
How did OBV Pyr do on BTCUSDT 1D with default settings?
−1.22%
From 26 Jan 2024 to 21 Oct 2026, over 27 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can OBV Pyr 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 OBV Pyr use a stop loss?
Yes
strategy.exit sets a stop on line 60, 61, 62, 63, 64, 65, 66.
Does OBV Pyr run in Zeal Terminal?
Yes
It compiles in 19 ms and runs 1,000 bars in 36 ms, in the browser.

BTCUSDT · 1D · default settings

  • EMA
  • EMA
  • Change
  • CUM
  • SMA
  • Crossover
  • 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 (6)
0.00100,000200,000AprJulOct2025AprJulOct2026AprJulOct$9,878$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference.
Net profit
−1.22%
−$121.57
Buy and hold
+102.5%
same period
Closed trades
27
19 won · 8 lost
Profitable
70.4%
of closed trades
Profit factor
0.88
gross profit ÷ gross loss
Max drawdown
9.46%
−$984.54

One run with the author's default settings, $10,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.

  • Note

    3 settings have no label

    In the settings dialog LengthOBV (line 19), ProfitTarget_Percent (line 32), LossTarget_Percent (line 37) show an empty name. The labels on this page come from the variable names.

  • Note

    Uses an argument v6 removed

    when = on line 43, 45, 47, 49, 51, 53, 55. 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 ema → ta.ema, change → ta.change, cum → ta.cum, sma → ta.sma, crossover → ta.crossover.
  • 7 strategy calls use the when = argument (line 43, 45, 47, 49, 51, 53, 55). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 12: ema → ta.ema
  • Line 13: ema → ta.ema
  • Line 20: change → ta.change
  • Line 20: change → ta.change
  • Line 21: cum → ta.cum
  • Line 22: sma → ta.sma
  • Line 24: crossover → ta.crossover
⋯// © RafaelZioni-//@version=4+//@version=5strategy(title = " OBV Pyr", overlay = true, pyramiding=5,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 20, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)⋯source=close-v1=ema(source,fastLength)+v1=ta.ema(source,fastLength)-v2=ema(source,slowLength)+v2=ta.ema(source,slowLength) ⋯LengthOBV = input(20)-nv = change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume +nv = ta.change(src) > 0 ? volume : ta.change(src) < 0 ? -volume : 0*volume -c = cum(nv) +c = ta.cum(nv) -c_tb = c - sma(c,LengthOBV) +c_tb = c - ta.sma(c,LengthOBV) // Conditions-longCond = crossover(c_tb,0)+longCond = ta.crossover(c_tb,0)//shortCond =crossunder(cnv_tb,0)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.string()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 19: input() → input.int()
  • Line 32: input() → input.int()
  • Line 37: input() → input.int()
7 more edits
  • Line 43: when = strategy.opentrades == 0 and longsignal → if block
  • Line 45: when = strategy.opentrades == 1 and longsignal → if block
  • Line 47: when = strategy.opentrades == 2 and longsignal → if block
  • Line 49: when = strategy.opentrades == 3 and longsignal → if block
  • Line 51: when = strategy.opentrades == 4 and longsignal → if block
  • Line 53: when = strategy.opentrades == 5 and longsignal → if block
  • Line 55: when = strategy.opentrades == 6 and longsignal → if block
⋯strategy(title = " OBV Pyr", overlay = true, pyramiding=5,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 20, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)-strat_dir_input = input(title="Strategy Direction", defval="long", options=["long", "short", "all"])+strat_dir_input = input.string(title="Strategy Direction", defval="long", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all⋯//-fastLength = input(250, title="Fast filter length ", minval=1)+fastLength = input.int(250, title="Fast filter length ", minval=1)-slowLength = input(500,title="Slow filter length",  minval=1)+slowLength = input.int(500,title="Slow filter length",  minval=1)source=close⋯src = close-LengthOBV = input(20)+LengthOBV = input.int(20)nv = ta.change(src) > 0 ? volume : ta.change(src) < 0 ? -volume : 0*volume ⋯ -ProfitTarget_Percent = input(3)+ProfitTarget_Percent = input.int(3)Profit_Ticks = close * (ProfitTarget_Percent / 100) / syminfo.mintick⋯ -LossTarget_Percent = input(10)+LossTarget_Percent = input.int(10)Loss_Ticks = close * (LossTarget_Percent / 100) / syminfo.mintick⋯//-strategy.entry("Entry 1", strategy.long, when=strategy.opentrades == 0 and longsignal)+if strategy.opentrades == 0 and longsignal+    strategy.entry("Entry 1", strategy.long)//-strategy.entry("Entry 2", strategy.long, when=strategy.opentrades == 1 and longsignal)+if strategy.opentrades == 1 and longsignal+    strategy.entry("Entry 2", strategy.long)//-strategy.entry("Entry 3", strategy.long, when=strategy.opentrades == 2 and longsignal)+if strategy.opentrades == 2 and longsignal+    strategy.entry("Entry 3", strategy.long)//-strategy.entry("Entry 4", strategy.long, when=strategy.opentrades == 3 and longsignal)+if strategy.opentrades == 3 and longsignal+    strategy.entry("Entry 4", strategy.long)//-strategy.entry("Entry 5", strategy.long, when=strategy.opentrades == 4 and longsignal)+if strategy.opentrades == 4 and longsignal+    strategy.entry("Entry 5", strategy.long)//-strategy.entry("Entry 6", strategy.long, when=strategy.opentrades == 5 and longsignal)+if strategy.opentrades == 5 and longsignal+    strategy.entry("Entry 6", strategy.long)//-strategy.entry("Entry 7", strategy.long, when=strategy.opentrades == 6 and longsignal)+if strategy.opentrades == 6 and longsignal+    strategy.entry("Entry 7", strategy.long)//⋯

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

⋯// © RafaelZioni-//@version=5+//@version=6strategy(title = " OBV Pyr", overlay = true, pyramiding=5,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 20, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)⋯

Settings

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

SettingDefaultType and rangeFeeds
Strategy Directionlongstring · options ["long", "short", "all"]strat_dir_value
Fast filter length 250int · min 1v1
Slow filter length500int · min 1v2
Length OBV (no label in the script)20intc_tb
Profit Target Percent (no label in the script)3intProfit_Ticks
Loss Target Percent (no label in the script)10intLoss_Ticks

What it calculates

  • EMA (ema, ta.ema in v5)source, Fast filter length (250)v1 · line 12
  • EMA (ema, ta.ema in v5)source, Slow filter length (500)v2 · line 13
  • Change (change, ta.change in v5)srcnv · line 20
  • CUM (cum, ta.cum in v5)nvc · line 21
  • SMA (sma, ta.sma in v5)c, Length OBV (20)c_tb · line 22
  • Crossover (crossover, ta.crossover in v5)c_tb, 0longCond · line 24

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.

fastLengthFast filter length setting · 250slowLengthSlow filter lengthsetting · 500volumevolumeprice dataLengthOBVLength OBVsetting · 20strat_dir_inputStrategy Directionsetting · longclosecloseprice dataProfitTarget_PercentProfit Target Percentsetting · 3LossTarget_PercentLoss Target Percentsetting · 10v1EMA→ v1v2EMA→ v2nvChange→ nvcCUM→ cc_tbSMA→ c_tblongCondCrossover→ longCondstrat_dir_valuestrat_dir_valuevaluesource, srcsource · src2 valuesProfit_TicksProfit_TicksvalueLoss_TicksLoss_Ticksvaluelongsignallongsignalconditionentry:Entry 1Open Entry 1strategy.entryentry:Entry 2Open Entry 2strategy.entryentry:Entry 3Open Entry 3strategy.entryentry:Entry 4Open Entry 4strategy.entryentry:Entry 5Open Entry 5strategy.entryentry:Entry 6Open Entry 6strategy.entryentry:Entry 7Open Entry 7strategy.entryexit:Exit 1exit Exit 1strategy.exitexit:Exit 2exit Exit 2strategy.exitexit:Exit 3exit Exit 3strategy.exitexit:Exit 4exit Exit 4strategy.exitexit:Exit 5exit Exit 5strategy.exitexit:Exit 6exit Exit 6strategy.exitexit:Exit 7exit Exit 7strategy.exit

Order rules

OrderFires whenBy defaultLine
Open Entry 1 longstrategy.opentrades == 0 and longsignalOn43
Open Entry 2 longstrategy.opentrades == 1 and longsignalOn45
Open Entry 3 longstrategy.opentrades == 2 and longsignalOn47
Open Entry 4 longstrategy.opentrades == 3 and longsignalOn49
Open Entry 5 longstrategy.opentrades == 4 and longsignalOn51
Open Entry 6 longstrategy.opentrades == 5 and longsignalOn53
Open Entry 7 longstrategy.opentrades == 6 and longsignalOn55
Exit Exit 1 stop and limitstrategy.position_size > 0On60
Exit Exit 2 stop and limitstrategy.position_size > 0On61
Exit Exit 3 stop and limitstrategy.position_size > 0On62
Exit Exit 4 stop and limitstrategy.position_size > 0On63
Exit Exit 5 stop and limitstrategy.position_size > 0On64
Exit Exit 6 stop and limitstrategy.position_size > 0On65
Exit Exit 7 stop and limitstrategy.position_size > 0On66

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.

7/7trades 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−1.2%+102.5%2770%0.889.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+5.7%+5.5%1788%16.354.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−3.0%+9.8%967%0.455.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+4.6%+8.4%2383%2.754.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.7%+16.7%1070%1.174.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+6.4%+21.5%2286%11.154.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+1.7%+148.3%2186%1.297.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.6%+17.1%1486%2.246.6%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 market2100%$117.47
Sideways market1267%−$299.69
Falling market1369%$60.66

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

How bad could the drawdown be?

7.5%

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

0%9%
All 27 trades
SideEntryExitBarsP&L
long24 Jun 2025 105,334.0030 Jun 2025 108,585.006$58.63
long13 Aug 2025 120,134.0014 Aug 2025 123,833.001$58.84
long23 Aug 2025 116,936.0011 Sep 2025 114,556.0019−$44.15
long3 Sep 2025 111,240.0011 Sep 2025 114,556.008$2.24
long3 Sep 2025 111,240.0011 Sep 2025 114,659.008$56.16
long8 Sep 2025 111,137.0011 Sep 2025 114,659.003$2.39
long8 Sep 2025 111,137.001 Oct 2025 115,585.0023$73.97
long25 Sep 2025 113,307.001 Oct 2025 115,585.006$1.59
long25 Sep 2025 113,307.001 Oct 2025 116,728.006$55.83
long29 Sep 2025 112,164.001 Oct 2025 116,728.002$3.32
long29 Sep 2025 112,164.002 Oct 2025 120,355.003$138.62
long13 Oct 2025 114,959.0017 Oct 2025 104,139.004−$198.73
long27 Oct 2025 114,559.004 Nov 2025 103,901.008−$192.73
long3 Nov 2025 110,541.004 Nov 2025 99,882.401−$198.20
long11 Nov 2025 106,011.0014 Nov 2025 96,041.903−$187.32
long4 Dec 2025 93,429.909 Dec 2025 93,114.405−$9.38
long8 Dec 2025 90,395.309 Dec 2025 93,114.401$1.42
long8 Dec 2025 90,395.3022 Dec 2025 90,523.2014−$0.16
long17 Dec 2025 87,863.4022 Dec 2025 90,523.205$2.94
long17 Dec 2025 87,863.4029 Dec 2025 90,008.1012$41.43
long27 Dec 2025 87,369.6029 Dec 2025 90,008.102$3.48
long27 Dec 2025 87,369.6013 Jan 2026 96,149.0017$178.02
long23 Jan 2026 89,559.7031 Jan 2026 81,133.608−$187.99
long21 Feb 2026 68,020.0025 Feb 2026 69,941.804$51.61
long1 Mar 2026 66,973.302 Mar 2026 68,946.601$54.23
long3 Mar 2026 68,830.104 Mar 2026 70,880.201$55.16
long10 Mar 2026 68,432.2011 Mar 2026 70,530.601$57.20

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
OBV Pyr this page—v4 strategy−1.2%279.5%
MACD Strategy with trailing ATR stop by Wunderbitcum ema smav4 strategy+72.7%8953.7%
Full CRYPTO pack macd, rsi, obv, ema strategy by SoftKill21ema sma cumv4 strategyNo trades on this market
meta-capitulation by serafimovklimentsma cumv5 strategyNo trades on this market
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 19 msYes 1,000 bars in 36 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/// © RafaelZioni//@version=4strategy(title = " OBV Pyr", overlay = true, pyramiding=5,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 20, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)strat_dir_input = input(title="Strategy Direction", defval="long", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.allstrategy.risk.allow_entry_in(strat_dir_value)//fastLength = input(250, title="Fast filter length ", minval=1)slowLength = input(500,title="Slow filter length",  minval=1)source=closev1=ema(source,fastLength)v2=ema(source,slowLength) // filter=true src = closeLengthOBV = input(20)nv = change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume c = cum(nv) c_tb = c - sma(c,LengthOBV) // ConditionslongCond = crossover(c_tb,0)//shortCond =crossunder(cnv_tb,0)//longsignal  = (v1 > v2 or filter == false ) and longCond//shortsignal = (v1 < v2 or filter == false ) and shortCond  //set take profit ProfitTarget_Percent = input(3)Profit_Ticks = close * (ProfitTarget_Percent / 100) / syminfo.mintick //set take profit LossTarget_Percent = input(10)Loss_Ticks = close * (LossTarget_Percent / 100) / syminfo.mintick  ////Order Placing//strategy.entry("Entry 1", strategy.long, when=strategy.opentrades == 0 and longsignal)//strategy.entry("Entry 2", strategy.long, when=strategy.opentrades == 1 and longsignal)//strategy.entry("Entry 3", strategy.long, when=strategy.opentrades == 2 and longsignal)//strategy.entry("Entry 4", strategy.long, when=strategy.opentrades == 3 and longsignal)//strategy.entry("Entry 5", strategy.long, when=strategy.opentrades == 4 and longsignal)//strategy.entry("Entry 6", strategy.long, when=strategy.opentrades == 5 and longsignal)//strategy.entry("Entry 7", strategy.long, when=strategy.opentrades == 6 and longsignal)//////if strategy.position_size > 0    strategy.exit(id="Exit 1", from_entry="Entry 1", profit=Profit_Ticks, loss=Loss_Ticks)    strategy.exit(id="Exit 2", from_entry="Entry 2", profit=Profit_Ticks, loss=Loss_Ticks)    strategy.exit(id="Exit 3", from_entry="Entry 3", profit=Profit_Ticks, loss=Loss_Ticks)    strategy.exit(id="Exit 4", from_entry="Entry 4", profit=Profit_Ticks, loss=Loss_Ticks)    strategy.exit(id="Exit 5", from_entry="Entry 5", profit=Profit_Ticks, loss=Loss_Ticks)    strategy.exit(id="Exit 6", from_entry="Entry 6", profit=Profit_Ticks, loss=Loss_Ticks)    strategy.exit(id="Exit 7", from_entry="Entry 7", profit=Profit_Ticks, loss=Loss_Ticks)