TradingView
duncanstroud
25 gen 2021 23:15

Bandpass Filters v.02 

Ether / United States DollarCoinbase

Descrizione


This is an alternative way to do bandpass filtering. I Still need to update it to support moveable frequency bands. The lowBandpass() is just a 'trick,' as it simply subtracts the highBandpass() from the close data, so it is not really accurate in that it removes the low frequencies, just in a rather less-than-ideal manner.

The "spectrum" of the dataset to filter will always be from 0 to 100, so think of filter boundary as %. So, a boundary of 40% means: 40% of the low-frequencies have been removed from the original data to make the red graph, and 40% of the high-frequencies have been removed from the original data to make the green graph.

This came about after reading the excellent tutorial on signal processing in Pine Script (pinecoders.com/techniques/dsp/), as the techniques listed there did not do exactly what I was looking for.

Here is a low-pass graph



Here is a hi-pass graph

Commenti
duncanstroud
Unfortunately, the resulting series does not allow for comparisons, etc., because it is full of 'na' points. To get around this,

output=lowBandpass(close,50)
var float fullseries = na
fullseries = output ? output : fullseries

This will apply the last non-na value of output to the new series, and if the value is 'na', it defaults to the last value of 'fullseries', which was previously set with the last valid value of 'output'. Consequently, the output is a squarewave :( but at least it can be used for comparison.

So if output is "10,na,na,na,20,na,na,na", then fullseries will be "10,10,10,10,20,20,20,20"
daxuzhuo
@duncanstroud, 把代碼改一改啊 我覺得我可以在你這個基礎上做點什麽 好用了 發給你
Altro