OPEN-SOURCE SCRIPT

Windowed Volume Weighted Moving Average

Introduction

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.

blackmanMoving Averagessmoothvolumeweightedwindowed

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?


Check out the indicators we are making at luxalgo: tradingview.com/u/LuxAlgo/
또한 다음에서도:

면책사항