[MX]Moving Average - LibraryLibrary "MA_library"
OVERVIEW
This library contains moving average functions that calculate values for which they do not exist by default in PineScript
Functions
tema(source,length) : Triple Exponencial Moving Average
dema(source,length) : Double Exponencial Moving Average
wwma(source,length) : Welles Wilder Moving Average
gma(source,length) : Geometric Moving Average
Geometricmean
Using The AM/GM Inequality To Estimate VolatilityA volatility indicator derived from the AM/GM inequality. I don't think it will be necessary to describe the usage and interpretation of such indicator, and I don't think it is super useful, however, this is not the case of the script, which contains three ways to compute the geometric mean, with a classic, a simple, and an efficient way. The AM/GM inequality is also a really interesting concept, and I'll try to"prove" it in this post by using DSP. I also added more comments in the script in order to highlight some stuff.
The AM/GM Inequality
When we talk about the mean, we are referring to the "arithmetic" one by default, but there exist more types of means. Two other ones include the "geometric" and "harmonic" means, both are part of the Pythagorean means with the arithmetic mean.
Each one of them as several properties, but the most interesting aspect is their inequality, that is:
HM <= GM <= AM
The arithmetic mean is the one with the highest value, while the harmonic mean is the one with the lowest value. In the case each data point is equal to each other, all the means have the same value.
In our case, the inequality of interest is the inequality between the geometric and arithmetic mean, where the geometric mean is lower or equal than the arithmetic one. Many proofs/explanations exist, I'll try my version using DSP, where instead of thinking about means, we think about rolling means, which allows us to interpret them as low-pass filters. So we end up having the geometric moving average (GMA) and arithmetic moving average (SMA).
We know that GMA <= SMA , the SMA has a unity passband, this implies that the GMA has a passband lower than 1 (for non-equal input values), this explains why the GMA is smaller than the SMA. In order for a FIR filter to have a passband lower than 1, the sum of the filter coefficients must be lower than 1. In order to further proves this consider the following equation:
sqrt(a×b) = k×a + k×b
Here sqrt(a×b) is the geometric mean of a and b , the right-hand side of the equation is a weighted sum between a and b and coefficient k , we want to solve the equation with respect to k , if k×2 < 1 then we have the proof that GMA < SMA . The solution with respect to k is:
k = sqrt(a×b)/(a+b)
which always gives a number lower than 0.5, as such k×2 < 1 and thus the passband is lower than 1. If our input values are equal to each other, we end up with the following solution for k :
k = sqrt(a×a)/(a+a) = a/(2×a) = 0.5
as such the GMA has the coefficients of an SMA as long as the input values are equal to each other.
Because of this inequality, we can subtract the SMA to a GMA and take the square root of the result in order to have a volatility indicator, however, both moving averages are still pretty close to each other, which gives a very small result for the indicator.
Uwu I am a bit tired, better indicators coming up
Log MFI - Money Flow Index The main concept was to make a bound oscillator calculate with a formula that places emphasis on the mean averages. Ideally this would mean that the oscillator won't have a tendency to swing into overbought/oversold condition and cause whipsaw. Using log is a way to increase the signal to noise ratio, with the regular MFI still plotted.
This indicator is best used in confluence with price action swings, where volume would normally be the highest.