mcbw_

Generalized Moving Average Kernels

Utbildning
mcbw_ Uppdaterad   
DJ:DJI   Dow Jones Industrial genomsnittsindex

A moving averages is a very simple concept that traders often take for granted and do not consider the inner mechanics of. In a very generalized sense a moving average for the last n periods is something that combines the past n values with unique weightings for each value. The real power of a moving average is in how those weightings are chosen. In a larger sense our choice of weightings is called a "kernel" or an "envelope". So if we consider a simple moving average all the weightings are the same, which means that our calculation equally considers past price action and current price action, this has a flat kernel. A weighted or linear moving average (wma) has a kernel that is shaped like a line and is decreasing as the distance from the current bar increases that takes the form of y = mx+b. This means that the weighting is higher for more recent bars and less for historic bars; increasing the slope (the value "m") of this will make this kernel more sensitive to recent bars than past bars. The exponential moving average (ema) is theoretically just like the wma but with an exponential term, aka y = ax^2 + mx + b. increasing the value of "a" will make the average exponentially more sensitive to recent price action than past bars. These are just 3 examples of the most common kernels. However the choice in kernels can be entirely your choice, and this is what I am presenting to the tradingview community. These methods are rather common in the field of signal processing and hopefully trading sometime soon.

Here I have built 3 new kernels for everyone in an indicator I will release soon.

1. The generalized polynomial kernel (blue)

Whereas the wma is defined by y = mx + b, the ema by y = ax^2 + mx + b, the generalized polynomial kernel can take in an eighth order polynomial as a kennel function: y = sum (rx ^ i) where i ranges from 0 to 8 and the user has 9 coefficients "r". To make a wma here one just sets the last 6 values of r to zero, or to make an ema the user sets the last 5 values of r to zero. If you are curious what shape your polynomial makes you can just plug it into wolfram or google to see it. This is the blue line on the chart above with all coefficients set to 1 by default.

2. The gaussian kernel (red)

This option sets the moving average kernel to a gaussian. The important thing here to consider is where it is centered, and how broad it is. If the width of the gaussian is sufficiently larger than the moving average window size then you will start to approximate a simple moving average, however if the width of the gaussian is incredibly narrow you are basically sampling the bars from however long ago that your gaussian is centered, like creating an offset. If the centering is done closer to the recent bars then there is essentially a smooth drop off in weightings with a negative concavity. This is the red line on the chart.

3. The noise kernel (green)

The idea of this one is simple, to just make a random kernel. Any value of the kernel can have a vastly different weight than the neighboring kernels. As tradingview has no random number generator I used a quasi random one that multiplies the unix time with the price and takes the sine function of that. For being totally random it also appears to be useful. This is the green line on the chart.

The script for this will be coming soon, I just have to clean it up for everyone. Keep in mind that this indicator is not ready to just apply to the charts, it is designed for people to customize and mess with first.

If anyone has any ideas to test with this I am incredibly interested to explore this deeper. I am using this general idea to move onto very interesting and potentially powerful applications, if anyone wants to talk about the technicalities of these please feel free to message me.
Kommentera:
Here are the scripts for all interested. The source code is free and public, anybody that cares to develop their own kernel can use the settings that are built into the a) polynomial function kernel, b) gaussian function kernel, or c) the linear random kernel. Should none of these satisfy your curiosity I also made the script very easy to edit. To insert your own weighting function you only need to alter one line, the variable "temp_(blabla)weight".




happy trading :)
Frånsägelse av ansvar

Informationen och publikationerna är inte avsedda att vara, och utgör inte heller finansiella, investerings-, handels- eller andra typer av råd eller rekommendationer som tillhandahålls eller stöds av TradingView. Läs mer i Användarvillkoren.