Pine Script v4 · Strategy
VixFixLinReg-Strategy
A Pine Script v4 strategy built on Highest (close, 22), Stdev (wvf, 20) and SMA (wvf, 20). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays 0.01% commission. 17 settings; defaults include LookBack Period Standard Deviation High 22, Bolinger Band Length 20 and Bollinger Band Standard Devaition Up 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 VixFixLinReg-Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did VixFixLinReg-Strategy do on BTCUSDT 1D with default settings?
- −49.25%
- From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can VixFixLinReg-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 VixFixLinReg-Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 56.
- Does VixFixLinReg-Strategy run in Zeal Terminal?
- Yes
- It compiles in 20 ms and runs 1,000 bars in 59 ms, in the browser.
BTCUSDT · 1D · default settings
- Williams Vix Fix
- Linear Regression
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −49.25%
- −$49,250.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 12
- 2 won · 10 lost
- Profitable
- 16.7%
- of closed trades
- Profit factor
- 0.19
- gross profit ÷ gross loss
- Max drawdown
- 51.12%
- −$51,120.50
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
2 settings do nothing
“KC Length”, “KC MultFactor” are declared but never read.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
5 settings have no label
In the settings dialog considerVIXFixClose (line 19), atrLen (line 22), atrMult (line 23), initialStopBar (line 24), waitForCloseBeforeStop (line 25) 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 an argument v6 removed
when = on line 54, 55, 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 atr → ta.atr, lowest → ta.lowest, max → math.max, highest → ta.highest, stdev → ta.stdev, sma → ta.sma, linreg → ta.linreg, abs → math.abs, tostring → str.tostring.
- 3 strategy calls use the when = argument (line 54, 55, 56). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 16: input(type = input.time) → input.time()
- Line 17: input(type = input.time) → input.time()
- Line 27: atr → ta.atr
- Line 27: lowest → ta.lowest
- Line 28: max → math.max
11 more edits
- Line 28: lowest → ta.lowest
- Line 30: highest → ta.highest
- Line 30: highest → ta.highest
- Line 31: stdev → ta.stdev
- Line 32: sma → ta.sma
- Line 35: highest → ta.highest
- Line 36: lowest → ta.lowest
- Line 38: linreg → ta.linreg
- Line 39: abs → math.abs
- Line 47: max → math.max
- Line 52: tostring → str.tostring
⋯// © HeWhoMustNotBeNamed-//@version=4+//@version=5strategy("VixFixLinReg-Strategy", shorttitle="VixFixLinReg - Strategy",⋯sd = input(false, title="Show Standard Deviation Line?")-i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)+i_startTime = input.time(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time")-i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)+i_endTime = input.time(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time")inDateRange = time >= i_startTime and time <= i_endTime⋯f_getStop(atrLen, atrMult)=>- stop = strategy.position_size > 0 ? close - (atrMult * atr(atrLen)) : lowest(initialStopBar)+ stop = strategy.position_size > 0 ? close - (atrMult * ta.atr(atrLen)) : ta.lowest(initialStopBar)- stop := strategy.position_size > 0 ? max(stop,nz(stop[1], stop)) : lowest(initialStopBar)+ stop := strategy.position_size > 0 ? math.max(stop,nz(stop[1], stop)) : ta.lowest(initialStopBar) stop-wvf = ((highest(close, pd)-low)/(highest(close, pd)))*100+wvf = ((ta.highest(close, pd)-low)/(ta.highest(close, pd)))*100-sDev = mult * stdev(wvf, bbl)+sDev = mult * ta.stdev(wvf, bbl)-midLine = sma(wvf, bbl)+midLine = ta.sma(wvf, bbl)lowerBand = midLine - sDevupperBand = midLine + sDev-rangeHigh = (highest(wvf, lb)) * ph+rangeHigh = (ta.highest(wvf, lb)) * ph-rangeLow = (lowest(wvf, lb)) * pl+rangeLow = (ta.lowest(wvf, lb)) * plcol = wvf >= upperBand or wvf >= rangeHigh ? color.lime : color.gray-val = linreg(wvf, pd, 0)+val = ta.linreg(wvf, pd, 0)-absVal = abs(val)+absVal = math.abs(val)linRegColor = val>val[1]? (val > 0 ? color.green : color.orange): (val > 0 ? color.lime : color.red)⋯vixFixState = (col == color.lime) ? 1: 0-vixFixState := strategy.position_size == 0? max(vixFixState, nz(vixFixState[1],0)) : vixFixState+vixFixState := strategy.position_size == 0? math.max(vixFixState, nz(vixFixState[1],0)) : vixFixStatelongCondition = (vixFixState == 1 and linRegColor == color.lime) and inDateRange⋯label_x = time+(60*60*24*1000*20) -myLabel = label.new(x=label_x, y=0, text="Stop : "+tostring(stop), xloc=xloc.bar_time, style=label.style_none, textcolor=color.black, size=size.normal)+myLabel = label.new(x=label_x, y=0, text="Stop : "+str.tostring(stop), xloc=xloc.bar_time, style=label.style_none, textcolor=color.black, size=size.normal)label.delete(myLabel[1])⋯Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.float()
- Line 11: input() → input.int()
- Line 12: input() → input.float()
- Line 13: input() → input.float()
12 more edits
- Line 14: input() → input.bool()
- Line 15: input() → input.bool()
- Line 19: input() → input.bool()
- Line 20: input() → input.int()
- Line 21: input() → input.float()
- Line 22: input() → input.int()
- Line 23: input() → input.int()
- Line 24: input() → input.int()
- Line 25: input() → input.bool()
- Line 54: when = longCondition → if block
- Line 55: when = exitLongCondition or (close < stop and waitForCloseBeforeStop and linRegColor == color.green) → if block
- Line 56: when = not waitForCloseBeforeStop and linRegColor == color.green → if block
⋯ commission_value = 0.01)-pd = input(22, title="LookBack Period Standard Deviation High")+pd = input.int(22, title="LookBack Period Standard Deviation High")-bbl = input(20, title="Bolinger Band Length")+bbl = input.int(20, title="Bolinger Band Length")-mult = input(2.0 , minval=1, maxval=5, title="Bollinger Band Standard Devaition Up")+mult = input.float(2.0 , minval=1, maxval=5, title="Bollinger Band Standard Devaition Up")-lb = input(50 , title="Look Back Period Percentile High")+lb = input.int(50 , title="Look Back Period Percentile High")-ph = input(.85, title="Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%")+ph = input.float(.85, title="Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%")-pl = input(1.01, title="Lowest Percentile - 1.10=90%, 1.05=95%, 1.01=99%")+pl = input.float(1.01, title="Lowest Percentile - 1.10=90%, 1.05=95%, 1.01=99%")-hp = input(false, title="Show High Range - Based on Percentile and LookBack Period?")+hp = input.bool(false, title="Show High Range - Based on Percentile and LookBack Period?")-sd = input(false, title="Show Standard Deviation Line?")+sd = input.bool(false, title="Show Standard Deviation Line?")i_startTime = input.time(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time")⋯inDateRange = time >= i_startTime and time <= i_endTime-considerVIXFixClose = input(false)+considerVIXFixClose = input.bool(false)-lengthKC=input(20, title="KC Length")+lengthKC=input.int(20, title="KC Length")-multKC = input(1.5, title="KC MultFactor")+multKC = input.float(1.5, title="KC MultFactor")-atrLen = input(22)+atrLen = input.int(22)-atrMult = input(5)+atrMult = input.int(5)-initialStopBar = input(5)+initialStopBar = input.int(5)-waitForCloseBeforeStop = input(true)+waitForCloseBeforeStop = input.bool(true)f_getStop(atrLen, atrMult)=>⋯label.delete(myLabel[1])-strategy.entry("Long", strategy.long, when=longCondition, oca_name="oca_buy", oca_type=strategy.oca.cancel)+if longCondition+ strategy.entry("Long", strategy.long, oca_name="oca_buy", oca_type=strategy.oca.cancel)-strategy.close("Long", when=exitLongCondition or (close < stop and waitForCloseBeforeStop and linRegColor == color.green))+if exitLongCondition or (close < stop and waitForCloseBeforeStop and linRegColor == color.green)+ strategy.close("Long")-strategy.exit("ExitLong", "Long", stop = stop, when=not waitForCloseBeforeStop and linRegColor == color.green)+if not waitForCloseBeforeStop and linRegColor == color.green+ strategy.exit("ExitLong", "Long", stop = stop)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: 12 before, 15 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.
⋯// © HeWhoMustNotBeNamed-//@version=5+//@version=6strategy("VixFixLinReg-Strategy", shorttitle="VixFixLinReg - Strategy",⋯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 |
|---|---|---|---|
| LookBack Period Standard Deviation High | 22 | int | wvf val |
| Bolinger Band Length | 20 | int | sDev midLine |
| Bollinger Band Standard Devaition Up | 2.0 | float · min 1 · max 5 | sDev |
| Look Back Period Percentile High | 50 | int | rangeHigh rangeLow |
| Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99% | .85 | float | rangeHigh |
| Lowest Percentile - 1.10=90%, 1.05=95%, 1.01=99% | 1.01 | float | rangeLow |
| Show High Range - Based on Percentile and LookBack Period? | false | bool | Range High Percentile |
| Show Standard Deviation Line? | false | bool | Upper Band |
| Start Time | timestamp("01 Jan 2010 00:00 +0000") | time | inDateRange |
| End Time | timestamp("01 Jan 2099 00:00 +0000") | time | inDateRange |
| Consider VIXFix Close (no label in the script) | false | bool | exitLongCondition |
| KC Length | 20 | int | unused |
| KC MultFactor | 1.5 | float | unused |
| ATR Len (no label in the script) | 22 | int | stop |
| ATR Mult (no label in the script) | 5 | int | stop |
| Initial Stop Bar (no label in the script) | 5 | int | stop |
| Wait For Close Before Stop (no label in the script) | true | bool | close Long exit ExitLong |
What it calculates
- Highest (
highest,ta.highestin v5)close, LookBack Period Standard Deviation High (22)wvf · line 30 - Stdev (
stdev,ta.stdevin v5)wvf, Bolinger Band Length (20)sDev · line 31 - SMA (
sma,ta.smain v5)wvf, Bolinger Band Length (20)midLine · line 32 - Highest (
highest,ta.highestin v5)wvf, Look Back Period Percentile High (50)rangeHigh · line 35 - Lowest (
lowest,ta.lowestin v5)wvf, Look Back Period Percentile High (50)rangeLow · line 36 - Linreg (
linreg,ta.linregin v5)wvf, LookBack Period Standard Deviation High (22), 0val · line 38
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | longCondition | On | 54 |
| Close Long | exitLongCondition or (close < stop and waitForCloseBeforeStop and linRegColor == color.green) | On | 55 |
| Exit ExitLong stop | not waitForCloseBeforeStop and linRegColor == color.green | On | 56 |
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.
- 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 | −49.3% | +102.5% | 12 | 17% | 0.19 | 51.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.1% | +5.5% | 12 | 33% | 0.99 | 17.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −11.4% | +9.8% | 11 | 9% | 0.87 | 45.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +54.7% | +8.4% | 7 | 43% | 5.25 | 8.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −81.7% | +16.7% | 14 | 21% | 0.07 | 82.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +40.2% | +21.5% | 9 | 44% | 2.79 | 13.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −3.6% | +148.3% | 12 | 25% | 0.95 | 34.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +17.6% | +17.1% | 9 | 44% | 2.13 | 12.5% | 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 | 2 | 50% | −$10,415.00 |
| Sideways market | 6 | 17% | −$18,146.20 |
| Falling market | 4 | 0% | −$20,683.70 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
56.1%
The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 49.2% to 56.1%; the tick is what actually happened, 49.2%. Order luck alone moves it this much.
All 12 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 26 Mar 2024 69,880.00 | 5 Jul 2024 57,050.00 | 101 | −$18,376.30 |
| long | 10 Jul 2024 58,050.00 | 6 Aug 2024 54,018.80 | 27 | −$5,683.40 |
| long | 14 Aug 2024 60,587.20 | 16 Aug 2024 57,541.10 | 2 | −$3,832.43 |
| long | 8 Nov 2024 75,857.90 | 27 Feb 2025 84,250.10 | 111 | $7,961.31 |
| long | 7 Mar 2025 89,931.90 | 10 Mar 2025 80,734.50 | 3 | −$8,203.10 |
| long | 15 Mar 2025 83,983.20 | 9 Apr 2025 76,322.40 | 25 | −$6,568.53 |
| long | 10 May 2025 102,972.00 | 30 Aug 2025 108,377.00 | 112 | $3,413.98 |
| long | 4 Sep 2025 111,706.00 | 12 Oct 2025 110,644.00 | 38 | −$666.44 |
| long | 25 Oct 2025 111,005.00 | 5 Nov 2025 101,497.00 | 11 | −$5,840.56 |
| long | 25 Nov 2025 88,300.00 | 1 Feb 2026 78,741.10 | 68 | −$6,745.03 |
| long | 11 Feb 2026 68,841.30 | 3 Jun 2026 66,760.80 | 112 | −$1,686.79 |
| long | 13 Jun 2026 63,580.00 | 2 Jul 2026 60,024.00 | 19 | −$3,017.63 |
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 |
|---|---|---|---|---|---|
| VixFixLinReg-Strategy this page | — | v4 strategy | −49.3% | 12 | 51.1% |
| Lawyers Trend Pro Strategy by ErdemDemir | sma stdev lowest highest | v4 strategy | +12.1% | 102 | 41.7% |
| BTC Volatility Band Strategy by gary_trades | sma stdev lowest highest | v4 strategy | −33.5% | 80 | 45.0% |
| MACandles-LinearRegression-Strategy by Trendoscope | stdev sma highest lowest | v5 strategy | +26.7% | 3 | 46.7% |
| Chandelier + BB + EMAS by juanchez | highest lowest sma stdev | v4 strategy | −20.6% | 10 | 38.6% |
| Crunchster's Turtle and Trend System by Crunchster1 | lowest highest stdev sma | v5 strategy | +18.0% | 31 | 16.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 20 ms | Yes 1,000 bars in 59 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/// © HeWhoMustNotBeNamed//@version=4strategy("VixFixLinReg-Strategy", shorttitle="VixFixLinReg - Strategy", overlay=false, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)pd = input(22, title="LookBack Period Standard Deviation High")bbl = input(20, title="Bolinger Band Length")mult = input(2.0 , minval=1, maxval=5, title="Bollinger Band Standard Devaition Up")lb = input(50 , title="Look Back Period Percentile High")ph = input(.85, title="Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%")pl = input(1.01, title="Lowest Percentile - 1.10=90%, 1.05=95%, 1.01=99%")hp = input(false, title="Show High Range - Based on Percentile and LookBack Period?")sd = input(false, title="Show Standard Deviation Line?")i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)inDateRange = time >= i_startTime and time <= i_endTimeconsiderVIXFixClose = input(false)lengthKC=input(20, title="KC Length")multKC = input(1.5, title="KC MultFactor")atrLen = input(22)atrMult = input(5)initialStopBar = input(5)waitForCloseBeforeStop = input(true)f_getStop(atrLen, atrMult)=> stop = strategy.position_size > 0 ? close - (atrMult * atr(atrLen)) : lowest(initialStopBar) stop := strategy.position_size > 0 ? max(stop,nz(stop[1], stop)) : lowest(initialStopBar) stopwvf = ((highest(close, pd)-low)/(highest(close, pd)))*100sDev = mult * stdev(wvf, bbl)midLine = sma(wvf, bbl)lowerBand = midLine - sDevupperBand = midLine + sDevrangeHigh = (highest(wvf, lb)) * phrangeLow = (lowest(wvf, lb)) * plcol = wvf >= upperBand or wvf >= rangeHigh ? color.lime : color.grayval = linreg(wvf, pd, 0)absVal = abs(val)linRegColor = val>val[1]? (val > 0 ? color.green : color.orange): (val > 0 ? color.lime : color.red)plot(hp and rangeHigh ? rangeHigh : na, title="Range High Percentile", style=plot.style_line, linewidth=4, color=color.orange)plot(hp and rangeLow ? rangeLow : na, title="Range High Percentile", style=plot.style_line, linewidth=4, color=color.orange)plot(wvf, title="Williams Vix Fix", style=plot.style_histogram, linewidth = 4, color=col)plot(sd and upperBand ? upperBand : na, title="Upper Band", style=plot.style_line, linewidth = 3, color=color.aqua)plot(-absVal, title="Linear Regression", style=plot.style_histogram, linewidth=4, color=linRegColor)vixFixState = (col == color.lime) ? 1: 0vixFixState := strategy.position_size == 0? max(vixFixState, nz(vixFixState[1],0)) : vixFixStatelongCondition = (vixFixState == 1 and linRegColor == color.lime) and inDateRangeexitLongCondition = (linRegColor == color.orange or linRegColor == color.red) and considerVIXFixClosestop = f_getStop(atrLen, atrMult)label_x = time+(60*60*24*1000*20) myLabel = label.new(x=label_x, y=0, text="Stop : "+tostring(stop), xloc=xloc.bar_time, style=label.style_none, textcolor=color.black, size=size.normal)label.delete(myLabel[1])strategy.entry("Long", strategy.long, when=longCondition, oca_name="oca_buy", oca_type=strategy.oca.cancel)strategy.close("Long", when=exitLongCondition or (close < stop and waitForCloseBeforeStop and linRegColor == color.green))strategy.exit("ExitLong", "Long", stop = stop, when=not waitForCloseBeforeStop and linRegColor == color.green)