Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Strategy Oil Z Score

A Pine Script v4 strategy built on BB (close, 20), EMA (close, 100) and SMA (divO, 252). It has 8 order rules, 4 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 8 settings; defaults include Length 252, Oil Z Std Dev 2.0 and Use underlying Oil.

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 Strategy Oil Z Score repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Strategy Oil Z Score do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings; it opened a long position that was still open on the last bar, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
Can Strategy Oil Z Score be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does Strategy Oil Z Score use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Strategy Oil Z Score run in Zeal Terminal?
Yes
It compiles in 19 ms and runs 1,000 bars in 48 ms, in the browser.

BTCUSDT · 1D · default settings

  • HLine
  • HLine
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctHLine$4,389,040$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. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. The live re-run is not offered here: the script requests TVC:MOVE D, VIX D, CBOE:OVX D, TVC:USOIL D, which this page cannot load in your browser.

Needs TVC:MOVE D data, not available: not a Binance spot market Needs VIX D data, not available: not a Binance spot market Needs CBOE:OVX D data, not available: not a Binance spot market Needs TVC:USOIL D data, not available: not a Binance spot market Values that depend on it are empty on this chart.

Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
42.92%
−$42,917.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

    1 setting has no label

    In the settings dialog Length (line 12) shows 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 an argument v6 removed

    when = on line 55, 56, 58, 59, 63, 64, 66, 67. 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 highest → ta.highest, security → request.security, bb → ta.bb, ema → ta.ema, sma → ta.sma, stdev → ta.stdev.
  • 8 strategy calls use the when = argument (line 55, 56, 58, 59, 63, 64, 66, 67). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 3: //@version=4 → //@version=5
  • Line 9: highest → ta.highest
  • Line 15: input(type = input.float) → input.float()
  • Line 16: input(type = input.integer) → input.int()
  • Line 18: security → request.security
  • Line 19: security → request.security
8 more edits
  • Line 20: security → request.security
  • Line 21: security → request.security
  • Line 22: input(type = input.bool) → input.bool()
  • Line 24: input(type = input.time) → input.time()
  • Line 28: bb → ta.bb
  • Line 30: ema → ta.ema
  • Line 40: sma → ta.sma
  • Line 41: stdev → ta.stdev
⋯// © jroche1973-//@version=4+//@version=5strategy("Strategy Oil Z Score", precision=6, overlay=false, pyramiding=100, calc_on_order_fills=true)⋯    // On next bars, update the label's x and y position, and the text it displays.-    label.set_xy(_label, bar_index, highest(10)[1])+    label.set_xy(_label, bar_index, ta.highest(10)[1])    label.set_text(_label, _text)⋯use_what    = input(title="Use underlying", defval="Oil", options=["Oil", "Move", "Vix"])-_bb_mult    = input(title="BB mult", type=input.float, defval=2)+_bb_mult    = input.float(title="BB mult", defval=2)-_bb_range   = input(title="BB mean range", type=input.integer, defval=20)+_bb_range   = input.int(title="BB mean range", defval=20)//src = input(close)-MOVE        = security("TVC:MOVE", timeframe.period, close)+MOVE        = request.security("TVC:MOVE", timeframe.period, close)-VIX         = security("VIX", timeframe.period, close)+VIX         = request.security("VIX", timeframe.period, close)-OILVIX      = security("CBOE:OVX", timeframe.period, close)+OILVIX      = request.security("CBOE:OVX", timeframe.period, close)-USO         = security("TVC:USOIL", timeframe.period, close)+USO         = request.security("TVC:USOIL", timeframe.period, close)-show_ema    = input(type=input.bool, title="Apply EMA", defval=true)+show_ema    = input.bool(title="Apply EMA", defval=true)l_ema       = input( title="EMA Length", defval=100)-startDateTime = input(type=input.time, defval=timestamp("15 July 2019 09:30"), +startDateTime = input.time(defval=timestamp("15 July 2019 09:30"),      title="Start Date", group="Strategy Date Range", ⋯     "the strategy simulates buy and sell trades.")    -[_bb_mid, _bb_hig, _bb_low] = bb(close, _bb_range, _bb_mult)+[_bb_mid, _bb_hig, _bb_low] = ta.bb(close, _bb_range, _bb_mult)_bb_percent = (close - _bb_low) / (_bb_hig - _bb_low)-s_ema = ema(close, l_ema)+s_ema = ta.ema(close, l_ema)iOILVIX = 1/OILVIX⋯    divO := USO/iOILVIX-m_basis = sma(divO, Length)+m_basis = ta.sma(divO, Length)-m_zscore = (divO - m_basis) / stdev(divO, Length)+m_zscore = (divO - m_basis) / ta.stdev(divO, Length)show_m = true⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 12: input() → input.int()
  • Line 13: input() → input.float()
  • Line 14: input() → input.string()
  • Line 23: input() → input.int()
  • Line 55: when = strategy.position_size > 0 → if block
  • Line 56: when = long_move → if block
6 more edits
  • Line 58: when = strategy.position_size <= 0 → if block
  • Line 59: when = short_move → if block
  • Line 63: when = strategy.position_size > 0 → if block
  • Line 64: when = long_move → if block
  • Line 66: when = strategy.position_size <= 0 → if block
  • Line 67: when = short_move → if block
⋯    -Length      = input(252) //252+Length      = input.int(252) //252-o_StdDevs   = input(defval = 2.0, title="Oil Z Std Dev")+o_StdDevs   = input.float(defval = 2.0, title="Oil Z Std Dev")-use_what    = input(title="Use underlying", defval="Oil", options=["Oil", "Move", "Vix"])+use_what    = input.string(title="Use underlying", defval="Oil", options=["Oil", "Move", "Vix"])_bb_mult    = input.float(title="BB mult", defval=2)⋯show_ema    = input.bool(title="Apply EMA", defval=true)-l_ema       = input( title="EMA Length", defval=100)+l_ema       = input.int( title="EMA Length", defval=100)startDateTime = input.time(defval=timestamp("15 July 2019 09:30"), ⋯        if m_zscore > 0 and _bb_percent < 0.5 and close < s_ema //short-            strategy.entry("sell", strategy.short, 100,  when=strategy.position_size > 0)+            if strategy.position_size > 0+                strategy.entry("sell", strategy.short, 100)-            strategy.close("close long", when=long_move)+            if long_move+                strategy.close("close long")        else-            strategy.entry("buy", strategy.long, 100, when=strategy.position_size <= 0)+            if strategy.position_size <= 0+                strategy.entry("buy", strategy.long, 100)-            strategy.close("close short", when=short_move)+            if short_move+                strategy.close("close short")else⋯        if m_zscore > 0 and _bb_percent < 0.5//short-            strategy.entry("sell", strategy.short, 100,  when=strategy.position_size > 0)+            if strategy.position_size > 0+                strategy.entry("sell", strategy.short, 100)-            strategy.close("close long", when=long_move)+            if long_move+                strategy.close("close long")        else-            strategy.entry("buy", strategy.long, 100, when=strategy.position_size <= 0)+            if strategy.position_size <= 0+                strategy.entry("buy", strategy.long, 100)-            strategy.close("close short", when=short_move)+            if short_move+                strategy.close("close short")

Does it run in Pine Script v6?

Not tested

Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © jroche1973-//@version=5+//@version=6strategy("Strategy Oil Z Score", precision=6, overlay=false, pyramiding=100, calc_on_order_fills=true)⋯

Settings

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

SettingDefaultType and rangeFeeds
Length (no label in the script)252intm_basis m_zscore
Oil Z Std Dev2.0floathline
Use underlyingOilstring · options ["Oil", "Move", "Vix"]line 34 line 36
BB mult2float_bb_mid _bb_hig _bb_low
BB mean range20int (written input.integer)_bb_mid _bb_hig _bb_low
Apply EMAtrueboolline 52
EMA Length100ints_ema
Strategy Date Range
Start DateSpecifies the start date and time from which " + "the strategy simulates buy and sell trades.timestamp("15 July 2019 09:30")timeline 53 line 61

What it calculates

  • BB (bb, ta.bb in v5)close, BB mean range (20), BB mult (2)_bb_mid · line 28
  • BB (bb, ta.bb in v5)close, BB mean range (20), BB mult (2)_bb_hig · line 28
  • BB (bb, ta.bb in v5)close, BB mean range (20), BB mult (2)_bb_low · line 28
  • EMA (ema, ta.ema in v5)close, EMA Length (100)s_ema · line 30
  • SMA (sma, ta.sma in v5)divO, Length (252)m_basis · line 40
  • Stdev (stdev, ta.stdev in v5)divO, Length (252)m_zscore · line 41

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 data_bb_rangeBB mean rangesetting · 20_bb_multBB multsetting · 2l_emaEMA Lengthsetting · 100LengthLengthsetting · 252o_StdDevsOil Z Std Devsetting · 2.0_bb_midBB→ _bb_mid_bb_higBB→ _bb_hig_bb_lowBB→ _bb_lows_emaEMA→ s_emam_basisSMA→ m_basism_zscoreStdev→ m_zscoreMOVE, VIX, OILVIX, USOMOVE · VIX +24 values_bb_percent_bb_percentvalueiOILVIXiOILVIXvaluedivOdivOvalueuse_buse_bvaluelong_movelong_moveconditionshort_moveshort_movecondition_label, m_color, mb_colorColour_label · m_color +1entry:sellOpen sellstrategy.entryclose:close longClose close longstrategy.closeentry:buyOpen buystrategy.entryclose:close shortClose close shortstrategy.closehline:43hlinehlinehline:44hlinehlinebgcolor:48bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open sell shortstrategy.position_size > 0On55
Close close longlong_movem_zscore < 0 and _bb_percent > 0.5On56
Open buy longstrategy.position_size <= 0On58
Close close shortshort_movem_zscore > 0 and _bb_percent < 0.5On59
Open sell shortstrategy.position_size > 0On63
Close close longlong_movem_zscore < 0 and _bb_percent > 0.5On64
Open buy longstrategy.position_size <= 0On66
Close close shortshort_movem_zscore > 0 and _bb_percent < 0.5On67

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 data4 security call(s), none with lookahead on.
  • 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

Not run on other markets: the script requests TVC:MOVE D, VIX D, CBOE:OVX D, TVC:USOIL D, and that data is not available here (not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market). Its results would rest on empty values.

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
Strategy Oil Z Score this page—v4 strategy0.0%042.9%
Strategy- Combo Z Score by jroche1973bb ema sma stdevv4 strategyNo trades on this market
Volume Weighted Bollinger Bands Strategy by Ankit_1618ema sma stdevv4 strategy+10.0%1527.5%
BB21_MA200_Strategy by mohaneeema sma stdevv4 strategyNo trades on this market
Super Breakout day trading by beststockalertstdev sma emav4 strategyNo trades on this market
Super Auto Breakout Day Trade Volatile stocks by beststockalertstdev sma emav4 strategy−6.1%5129.1%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 19 msWith a workaround 1,000 bars in 48 msNot measured
PineTSNo v5 and v6 only—Not measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © jroche1973//@version=4strategy("Strategy Oil Z Score", precision=6, overlay=false, pyramiding=100, calc_on_order_fills=true)f_print(_text) =>    // Create label on the first bar.    var _label = label.new(bar_index, na, _text, xloc.bar_index, yloc.price, color(na), label.style_none, color.gray, size.large, text.align_left)    // On next bars, update the label's x and y position, and the text it displays.    label.set_xy(_label, bar_index, highest(10)[1])    label.set_text(_label, _text)    Length      = input(252) //252o_StdDevs   = input(defval = 2.0, title="Oil Z Std Dev")use_what    = input(title="Use underlying", defval="Oil", options=["Oil", "Move", "Vix"])_bb_mult    = input(title="BB mult", type=input.float, defval=2)_bb_range   = input(title="BB mean range", type=input.integer, defval=20)//src = input(close)MOVE        = security("TVC:MOVE", timeframe.period, close)VIX         = security("VIX", timeframe.period, close)OILVIX      = security("CBOE:OVX", timeframe.period, close)USO         = security("TVC:USOIL", timeframe.period, close)show_ema    = input(type=input.bool, title="Apply EMA", defval=true)l_ema       = input( title="EMA Length", defval=100)startDateTime = input(type=input.time, defval=timestamp("15 July 2019 09:30"),      title="Start Date", group="Strategy Date Range",      tooltip="Specifies the start date and time from which " +      "the strategy simulates buy and sell trades.")    [_bb_mid, _bb_hig, _bb_low] = bb(close, _bb_range, _bb_mult)_bb_percent = (close - _bb_low) / (_bb_hig - _bb_low)s_ema = ema(close, l_ema)iOILVIX = 1/OILVIXdivO = USO/iOILVIX//Proxy of M of Move ie alt VVIXif use_what == "Move"    divO := MOVE/iOILVIXelse if use_what == "Vix"    divO := VIX/iOILVIXelse    divO := USO/iOILVIXm_basis = sma(divO, Length)m_zscore = (divO - m_basis) / stdev(divO, Length)show_m = truehline(o_StdDevs, color=color.white, linestyle=hline.style_dotted)hline(-1 * o_StdDevs, color=color.white, linestyle=hline.style_dotted)color m_color = m_zscore < 0 ? color.new(color.white, 70): color.new(color.blue, 70) //we want white if not activecolor mb_color = m_zscore < 0 and _bb_percent > 0.5 ? color.new(color.white, 70): color.new(color.blue, 70) //we want white if not activeuse_b = _bb_percent < 0.5 ? true: falsebgcolor(show_m and use_b ? color.new(m_color,70) : color.new(color.white, 70)) // we want whatever color our status stipulates if 'on' or white if 'off'//Strategy Testinglong_move =     m_zscore < 0    and     _bb_percent > 0.5short_move =    m_zscore > 0    and     _bb_percent < 0.5if show_ema    if time >= startDateTime and time <= timenow         if m_zscore > 0 and _bb_percent < 0.5 and close < s_ema //short            strategy.entry("sell", strategy.short, 100,  when=strategy.position_size > 0)            strategy.close("close long", when=long_move)        else            strategy.entry("buy", strategy.long, 100, when=strategy.position_size <= 0)            strategy.close("close short", when=short_move)else    if time >= startDateTime and time <= timenow         if m_zscore > 0 and _bb_percent < 0.5//short            strategy.entry("sell", strategy.short, 100,  when=strategy.position_size > 0)            strategy.close("close long", when=long_move)        else            strategy.entry("buy", strategy.long, 100, when=strategy.position_size <= 0)            strategy.close("close short", when=short_move)