// A Peek Into the Future
// John F. Ehlers
// TASC Aug 2019
// Created by e2e4mfck for tradingview.com
//@version=4
title = "Voss Predictive Filter"
shorttitle = "VPF"
version = ""
study (title = title + version, shorttitle = "VPF", overlay = false)
// - - - - - Inputs - - - - - //
Source = input(close, type = input.source)
Period = input(20, type = input.integer)
Predict = input(3, type = input.integer)
Bandwidth = input(0.25, type = input.float)
// - - - - - Function - - - - - //
f_VossFilt (_period, _predict, _bandwidth, _source) =>
float _filt = 0, float _sumC = 0, float _voss = 0
_PI = 2 * asin(1)
_order = 3 * _predict
_f1 = cos(2 * _PI / _period)
_g1 = cos(_bandwidth * 2 * _PI / _period)
_s1 = 1 / _g1 - sqrt(1 / (_g1 * _g1) - 1)
_s2 = 1 + _s1
_s3 = 1 - _s1
_x1 = _source - _source[2]
_x2 = (3 + _order) / 2
for _i = 0 to (_order - 1)
_sumC := _sumC + ((_i + 1) / _order) * _voss[_order - _i]
if bar_index <= _order
_filt := 0
_voss := 0
else
_filt := 0.5 * _s3 * _x1 + _f1 * _s2 * _filt[1] - _s1 * _filt[2]
_voss := _x2 * _filt - _sumC
[_voss, _filt]
// - - - - - Declaration - - - - - //
[Voss, Filt] = f_VossFilt(Period, Predict, Bandwidth, Source)
// - - - - - Plot - - - - - //
plot(Filt, title = "Filter", style = plot.style_line, color = color.red, linewidth = 2)
plot(Voss, title = "Voss", style = plot.style_line, color = color.blue, linewidth = 2)
hline(0.0, title = "Zero", linestyle = hline.style_dashed, color = color.black, linewidth = 1)