STD/Clutter-Filtered, Variety FIR Filters [Loxx]STD/Clutter-Filtered, Variety FIR Filters is a FIR filter explorer. The following FIR Digital Filters are included.
Rectangular - simple moving average
Hanning
Hamming
Blackman
Blackman/Harris
Linear weighted
Triangular
There are 10s of windowing functions like the ones listed above. This indicator will be updated over time as I create more windowing functions in Pine.
Uniform/Rectangular Window
The uniform window (also called the rectangular window) is a time window with unity amplitude for all time samples and has the same effect as not applying a window.
Use this window when leakage is not a concern, such as observing an entire transient signal.
The uniform window has a rectangular shape and does not attenuate any portion of the time record. It weights all parts of the time record equally. Because the uniform window does not force the signal to appear periodic in the time record, it is generally used only with functions that are already periodic within a time record, such as transients and bursts.
The uniform window is sometimes called a transient or boxcar window.
For sine waves that are exactly periodic within a time record, using the uniform window allows you to measure the amplitude exactly (to within hardware specifications) from the Spectrum trace.
Hanning Window
The Hanning window attenuates the input signal at both ends of the time record to zero. This forces the signal to appear periodic. The Hanning window offers good frequency resolution at the expense of some amplitude accuracy.
This window is typically used for broadband signals such as random noise. This window should not be used for burst or chirp source types or other strictly periodic signals. The Hanning window is sometimes called the Hann window or random window.
Hamming Window
Computers can't do computations with an infinite number of data points, so all signals are "cut off" at either end. This causes the ripple on either side of the peak that you see. The hamming window reduces this ripple, giving you a more accurate idea of the original signal's frequency spectrum.
Blackman
The Blackman window is a taper formed by using the first three terms of a summation of cosines. It was designed to have close to the minimal leakage possible. It is close to optimal, only slightly worse than a Kaiser window.
Blackman-Harris
This is the original "Minimum 4-sample Blackman-Harris" window, as given in the classic window paper by Fredric Harris "On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform", Proceedings of the IEEE, vol 66, no. 1, pp. 51-83, January 1978. The maximum side-lobe level is -92.00974072 dB.
Linear Weighted
A Weighted Moving Average puts more weight on recent data and less on past data. This is done by multiplying each bar’s price by a weighting factor. Because of its unique calculation, WMA will follow prices more closely than a corresponding Simple Moving Average.
Triangular Weighted
Triangular windowing is known for very smooth results. The weights in the triangular moving average are adding more weight to central values of the averaged data. Hence the coefficients are specifically distributed. Some of the examples that can give a clear picture of the coefficients progression:
period 1 : 1
period 2 : 1 1
period 3 : 1 2 1
period 4 : 1 2 2 1
period 5 : 1 2 3 2 1
period 6 : 1 2 3 3 2 1
period 7 : 1 2 3 4 3 2 1
period 8 : 1 2 3 4 4 3 2 1
Read here to read about how each of these filters compare with each other: Windowing
What is a Finite Impulse Response Filter?
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
Ultra Low Lag Moving Average's weights are designed to have MAXIMUM possible smoothing and MINIMUM possible lag compatible with as-flat-as-possible phase response.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
Related Indicators
STD/Clutter-Filtered, Kaiser Window FIR Digital Filter
STD- and Clutter-Filtered, Non-Lag Moving Average
Clutter-Filtered, D-Lag Reducer, Spec. Ops FIR Filter
STD-Filtered, Ultra Low Lag Moving Average
Blackman
Windowed Volume Weighted Moving AverageIntroduction
The concept of windowing was briefly introduced in the Blackman filter post, however windowing is more than just some window functions, and isn't exclusively used in filter design.
Today we will use windowing with the volume weighted moving average, a moving average that weight the price with volume in order to be more reactive when volume is high, that is the moving average is more reactive when the market is more active. The use of windowing in the vwma allow to enhance its performance in the frequency domain which result in a smoother output.
Note that i made a similar indicator long ago, but at that time I was not great at all with math and pinescript in general and the indicator was therefore wrong, i want to remind to the community that i'am not a professional, only an enthusiast, I never claimed to be a master coder and i'am totally open to receive criticism, if I sounded like bragging in the past I apologize, at 20 years old it is still easy to act like a kid, the information contained in my posts is only shared in order to help others but also myself, since sharing is also a way to learn more effectively. That said lets go with the indicator.
Windowing
Windowing consist on applying a window function to a signal, by applying i mostly talk about multiplying, this process is mostly used with windowed sinc filters in order to reduce ripples in the pass/stop band, but can be used with any kind of filters in order to have better frequency domain performance, the only thing we need to do is to multiply the filter weights by a window function.
In order to understand windowing it is useful to visualize this process and understand spectral leakage. Remember that we can describe a signal as the sum of sine/cosine waves of different frequencies, amplitude and phase, leakage is an effect that appear with signals having discontinuities, that is when a signal non periodic.
This figure show a non periodic sine wave of frequency 0.1, a non periodic signal will have is last sample value different from its first sample value, if we where to do its fourier transform we wouldn't end up with a single bin at 0.1 but with more bins, this is spectral leakage, the discontinuities in the signal create additional frequency components. In order to reduce leakage we must make the signal approximately periodic, this is done by making use of window functions.
A window function is symmetric and relatively smooth, all we have to do is to multiply our first non periodic signal with the window function.
We end up with the following windowed signal :
The signal is approximately periodic and leakage has been reduced. Now that we have seen that, it might be useful to see why it is useful in filters.
Remember that the Fourier transform of the filter weights gives us its frequency response, if our weights introduce leakage we end up with ripples, so windowing the filter weights might help reduce the ripples in the frequency response, which result in a smoother filter output.
Volume Weighted Moving Average
A volume weighted moving average is a FIR filter who use volume as filter kernel, therefore the frequency response of this filter always change, it is therefore not wrong to qualify the vwma as an adaptive moving average. Higher volume mean higher weighting of the current closing price value, which therefore produce a more reactive output.
However the smoothness of the moving average is relatively poor.
Windowed Volume Weighted Moving Average
The proposed moving average has a length setting who control the moving average period, and various options that we will describe below. The first option is the type of window, there are many windows, certains more complex than others, here 3 windows are proposed, the famous Blackman window, the Bartlett, and finally the Hanning window, they provide each different level of smoothness. lets compare our moving average with period 100 with a vwma of the same period.
Our moving average in red, and the vwma in blue. As you can see the results are smoother.
The power parameter is used in order to give an even higher weighting to closing prices with high volume, this create a more boxy output. Below is a comparison with a vwma in blue and a powered vwma in red with power = 2 without windowing :
We can then apply a window, here i will choose the Blackman window :
Conclusion
A new moving average based on windowed volume weighting has been proposed. The result are smoother which might therefore reduce whipsaw trades. I wish i could have explained things better, unfortunately windowing isn't something i use much, i wanted to post this moving average earlier this year.
I will be off in France for 1 week, my flight is tomorrow in the morning, therefore i don't think i'll have the possibility to make other posts this year. I want to profit from this occasion to review my year in tradingview.
Many indicators have been posted, some being extremely bad and others really interesting, this year introduced my attempts on estimating the lsma efficiently, the linear channels, an attempt on making lines and remain the first indicator from the v4 i posted if i'am right. Then came the efficient auto-line, who gained some popularity quite fast. Then finally the %G oscillator and the recursive bands where posted, and remain some of the favorites indicators i made. I also wanted to leave this year due to studies, that i totally abandoned, i'am thankful that i chosen to stay.
I also want to express my apologies to any member that i could have offended, i think that i'am not a mean person but i certainly not contest the fact that i'am clumsy, even in my work, however my clumsiness is far greater when it comes to interact with other peoples or a group of peoples, i don't want to hurt anyone, if i made anything that made you feel bad then i'am sincerely sorry, and hope we can start this new year from 0.
Finally i thank the tradingview community for their interest and curiosity, i thank all the great coders who work on making pinescript a better scripting language, i also thank the tradingview staff for their work this year. I wish you all a merry christmas, and an happy new year.
Thanks for reading.
Blackman Filter - The Smoother The BetterIntroduction
Who doesn't like smooth things? I'd like a smooth market price for christmas! But i can't get it, instead its so noisy...so you apply a filter to smooth it, such filters are called low-pass filters, they smooth and its great but they have lag, so nobody really use them, but they are pretty to look at.
Its on a childish note that i will introduce this indicator, so what it is all about? I propose a new FIR filter using a blackman function as filter kernel for financial time-series smoothing, do you prefer the childish tone ? Fear not its surprisingly easy!
The Blackman Function
The blackman function look like a bell shaped curve, look:
The blackman function will produce such curve. This function is called a cosine sum function because she is based on the sum of cosine functions, here only 2.
0.42 - 0.5 * cos(2 * pi * k) + 0.08 * cos(4 * pi * k)
Originally you use this function for windowing , what does it means? In signal processing you have a function called sync function , if you use this function as filter kernel you would get the ideal frequency domain response filter, sometime called brickwall filter, it would be extremely smooth.
Above the optimal low pass filter frequency response.
However the sync function has no ending values and goes on forever, therefore we can't use it for convolution, expect if we apply windowing. Filters using windowing are called windowed-sinc filters, i will describe the procedure below :
1 - Create a sync function = sin(pi*n)/(pi*n)
2 - Truncate it = I only keep the first length points of the sync function.
This create a abrupt end, the frequency of a filter using step 1 as kernel would contain ripples in the pass band and stop band, this is bad! The frequency response would look like this :
3 - I multiply my values of step 2 by a window function, it can the blackman window, i no longer have an abrupt end, its smooth!
The frequency response of the filter using this kernel would no longer have ripples! This is the power of windowing functions.
Here we are not using such thing, but we could in the future. Here instead we use the blackman function as filter kernel, because this function is bell shaped this mean that the filter will certainly be smooth (symmetrical weighting is a rule of thumb for kernels when we want really smooth filters).
The Filter
This filter is quite smooth, unlike the gaussian filter this filter give less weights to recent and past values, this is because the blackman function has fatter tails than the gaussian one. I could make a comparison of both, however they are quite alike, if you often use a gaussian filter its up to you to decide which one you prefer.
The filter can do a better job than the moving average when it comes to preserve the frequency components that constitute the cycles/trend.
We can see that the filter has a greater performance when it comes to keep the shape of the market price, thus it has a slightly better fit.
Conclusion
Ok so in this post you learned a bit about the sync function and windowing, those are basic subjects in signal processing, they allow us to approximate the filter with the ideal frequency response, i also showed you that those windowing function could be used as kernel and that they where pretty smooth on their own, there are many others, but the one i prefer is the blackman windowing function.
I know what you are thinking, "we want trailing stops, alerts, colors, arrows!", and i understand you pal, but sometimes its cool to take a break from all this stuff. However i can tell that i'am working on a side project that aim to estimate rolling maximum/minimum as fast as possible, any experiments will be published here, and i can ensure you that those indicators will make your day quite brighter, we will see that soon.
I hope you learned something from this post! I'am a bit tired (look i'am disappearing !)
Thanks for reading !