Strategy library

Vix Fix + Stochastic strategy in Pine Script

Buys dips after a spike of the Williams Vix Fix and sells when the Stochastic turns down from overbought.

Williams Vix Fix · Stochastic · Bollinger Bands · long only · by timj · Mozilla Public License 2.0

What is its backtest worth?

A parameter sweep finds the best setting of the Vix Fix + Stochastic strategy. PineTester tells you if it holds up: whether the best result was only picked after the fact, what it makes with fees, what you could have known at the time (a walk-forward on data the pick did not see) and how deep it fell along the way. On the free start, your first own backtest gets the full evaluation; its trade list and result file come with the full report or a plan.

Creates a draft on Binance BTC/USDT 4h over about six and a half years with 0.1% commission per order and 2 ticks slippage; you start it yourself. A backtest uses credits; new accounts receive free credits.

The rules

  • Enters long when the Vix Fix has been above its Bollinger band or its percentile level and the price starts to recover (higher close than a few bars before, below the medium- or long-term close).
  • Can add up to nine entries (pyramiding 9).
  • Closes all entries when the Stochastic %K crosses above %D above the overbought level. The RSI inputs are calculated but do not change the trades.

What to watch for

  • Up to nine entries in one fall raise the position size exactly when the market drops – check the largest drop.
  • Buying dips does well in rising years; compare the result with buy & hold.

How PineTester judges a backtest, with its sources: how we judge results.

The Pine Script code

The author's code with its licence notice (Mozilla Public License 2.0), with one change marked in the code: the same test conditions for every library strategy in its strategy() line – the whole account per trade (split over the entries where it adds to a position), 0.1% commission per order and 2 ticks slippage; the trading rules are unchanged. Pine Script v5; PineTester converts it to v6 automatically, so results can differ slightly from TradingView.

//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © timj
// Modified by PineTester (2026-11-14): the same test conditions for every library strategy in strategy(): 11% of equity per entry (pyramiding 9),
// 0.1% commission per order, 2 ticks slippage, initial capital 10,000. The trading rules are unchanged.
//     ____      ____                                              _                                      
// ________  ________  ________  _______   ___       _______   ________  ________  _________  _______               ________  ________  ________ ___  ___  ________  ________  ________  _________  _______               ________  ________  ___       ___  _________  _______   ________  ________  _________  _______          
// |\   __  \|\   ____\|\   ____\|\  ___ \ |\  \     |\  ___ \ |\   __  \|\   __  \|\___   ___\\  ___ \             |\   __  \|\   __  \|\  _____\\  \|\  \|\   ____\|\   ____\|\   __  \|\___   ___\\  ___ \             |\   __  \|\   __  \|\  \     |\  \|\___   ___\\  ___ \ |\   __  \|\   __  \|\___   ___\\  ___ \         
// \ \  \|\  \ \  \___|\ \  \___|\ \   __/|\ \  \    \ \   __/|\ \  \|\  \ \  \|\  \|___ \  \_\ \   __/|            \ \  \|\  \ \  \|\ /\ \  \__/\ \  \\\  \ \  \___|\ \  \___|\ \  \|\  \|___ \  \_\ \   __/|            \ \  \|\  \ \  \|\ /\ \  \    \ \  \|___ \  \_\ \   __/|\ \  \|\  \ \  \|\  \|___ \  \_\ \   __/|        
//  \ \   __  \ \  \    \ \  \    \ \  \_|/_\ \  \    \ \  \_|/_\ \   _  _\ \   __  \   \ \  \ \ \  \_|/__           \ \  \\\  \ \   __  \ \   __\\ \  \\\  \ \_____  \ \  \    \ \   __  \   \ \  \ \ \  \_|/__           \ \  \\\  \ \   __  \ \  \    \ \  \   \ \  \ \ \  \_|/_\ \   _  _\ \   __  \   \ \  \ \ \  \_|/__      
//   \ \  \ \  \ \  \____\ \  \____\ \  \_|\ \ \  \____\ \  \_|\ \ \  \\  \\ \  \ \  \   \ \  \ \ \  \_|\ \ ___       \ \  \\\  \ \  \|\  \ \  \_| \ \  \\\  \|____|\  \ \  \____\ \  \ \  \   \ \  \ \ \  \_|\ \ ___       \ \  \\\  \ \  \|\  \ \  \____\ \  \   \ \  \ \ \  \_|\ \ \  \\  \\ \  \ \  \   \ \  \ \ \  \_|\ \ ___ 
//    \ \__\ \__\ \_______\ \_______\ \_______\ \_______\ \_______\ \__\\ _\\ \__\ \__\   \ \__\ \ \_______\\__\       \ \_______\ \_______\ \__\   \ \_______\____\_\  \ \_______\ \__\ \__\   \ \__\ \ \_______\\__\       \ \_______\ \_______\ \_______\ \__\   \ \__\ \ \_______\ \__\\ _\\ \__\ \__\   \ \__\ \ \_______\\__\
//    \|__|\|__|\|_______|\|_______|\|_______|\|_______|\|_______|\|__|\|__|\|__|\|__|    \|__|  \|_______\|__|        \|_______|\|_______|\|__|    \|_______|\_________\|_______|\|__|\|__|    \|__|  \|_______\|__|        \|_______|\|_______|\|_______|\|__|    \|__|  \|_______|\|__|\|__|\|__|\|__|    \|__|  \|_______\|__|
//                                                                                                                                                           \|_________|                                                                                                                                                                                                                                                             
strategy('Bottom Feeder - VIX Bottom dip buying strategy', overlay=false, pyramiding=9, margin_long=100, margin_short=100, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=11, commission_type=strategy.commission.percent, commission_value=0.1, slippage=2)
Stochlength = input.int(14, minval=1, title="lookback length of Stochastic")
StochOverBought = input.int(80, title="Stochastic overbought condition")
StochOverSold = input.int(20, title="Stochastic oversold condition")
smoothK = input(3, title="smoothing of Stochastic %K ")
smoothD = input(3, title="moving average of Stochastic %K")
k = ta.sma(ta.stoch(close, high, low, Stochlength), smoothK)
d = ta.sma(k, smoothD)
///////////// RSI 
RSIlength = input.int( 14, minval=1 , title="lookback length of RSI")
RSIOverBought = input.int( 70  , title="RSI overbought condition")
RSIOverSold = input.int( 30  , title="RSI oversold condition")
RSIprice = close
vrsi = ta.rsi(RSIprice, RSIlength)
///////////// Filtering
FilteredChecked = input(true, title="Enter on filtered signals")
AggressiveChecked = input(true, title="Enter on aggressive signals")
///////////// Double strategy: RSI strategy + Stochastic strategy
pd = input(22, title="LookBack Period Standard Deviation High")
bbl = input(20, title="Bolinger Band Length")
mult = input.float(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%")
new = input(false, title="-------Text Plots Below Use Original Criteria-------" )
sbc = input(false, title="Show Text Plot if WVF WAS True and IS Now False")
sbcc = input(false, title="Show Text Plot if WVF IS True")
new2 = input(false, title="-------Text Plots Below Use FILTERED Criteria-------" )
sbcFilt = input(true, title="Show Text Plot For Filtered Entry")
sbcAggr = input(true, title="Show Text Plot For AGGRESSIVE Filtered Entry")
ltLB = input.float(40, minval=25, maxval=99, title="Long-Term Look Back Current Bar Has To Close Below This Value OR Medium Term--Default=40")
mtLB = input.float(14, minval=10, maxval=20, title="Medium-Term Look Back Current Bar Has To Close Below This Value OR Long Term--Default=14")
str = input.int(3, minval=1, maxval=9, title="Entry Price Action Strength--Close > X Bars Back---Default=3")
//Alerts Instructions and Options Below...Inputs Tab
new4 = input(false, title="-------------------------Turn On/Off ALERTS Below---------------------" )
new5 = input(false, title="----To Activate Alerts You HAVE To Check The Boxes Below For Any Alert Criteria You Want----")
sa1 = input(false, title="Show Alert WVF = True?")
sa2 = input(false, title="Show Alert WVF Was True Now False?")
sa3 = input(false, title="Show Alert WVF Filtered?")
sa4 = input(false, title="Show Alert WVF AGGRESSIVE Filter?")
//Williams Vix Fix Formula
wvf = ((ta.highest(close, pd)-low)/(ta.highest(close, pd)))*100
sDev = mult * ta.stdev(wvf, bbl)
midLine = ta.sma(wvf, bbl)
lowerBand = midLine - sDev
upperBand = midLine + sDev
rangeHigh = (ta.highest(wvf, lb)) * ph
//Filtered Bar Criteria
upRange = low > low[1] and close > high[1]
upRange_Aggr = close > close[1] and close > open[1]
//Filtered Criteria
filtered = ((wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and (wvf < upperBand and wvf < rangeHigh))
filtered_Aggr = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and not (wvf < upperBand and wvf < rangeHigh)
//Alerts Criteria
alert1 = wvf >= upperBand or wvf >= rangeHigh ? 1 : 0
alert2 = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and (wvf < upperBand and wvf < rangeHigh) ? 1 : 0
alert3 = upRange and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered ? 1 : 0
alert4 = upRange_Aggr and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered_Aggr ? 1 : 0
//Coloring Criteria of Williams Vix Fix
col = wvf >= upperBand or wvf >= rangeHigh ? color.lime : color.gray
isOverBought = (ta.crossover(k,d) and k > StochOverBought) ? 1 : 0
isOverBoughtv2 = k > StochOverBought ? 1 : 0
filteredAlert = alert3 ? 1 : 0
aggressiveAlert = alert4 ? 1 : 0
if (filteredAlert and FilteredChecked == true)
    strategy.entry("Long", strategy.long)
    
if (aggressiveAlert and AggressiveChecked == true)
    strategy.entry("Long", strategy.long)    
if (isOverBought)
    strategy.close("Long")
    
    
//if (filteredAlert or aggressiveAlert)
//    strategy.entry("Long", strategy.long)    

Open-source script by timj, shown under the Mozilla Public License 2.0. Not a recommendation; neither the author nor TradingView endorses PineTester. Backtests are hypothetical results on past data, not a forecast.