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/
Мои профили:

Отказ от ответственности