RicardoSantos

Function Geometric Moving Average

Using a formula that is generally used for calculating investment over time to check gains on a commodity.

Geometric mean as described here: http://www.investopedia.com/ask/answers/...
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Want to use this script on a chart?
//@version=2
study(title='Function Geometric Moving Average', overlay=true)
//  ||-----------------------------------------------------------------------------------------||
//  ||---   As described here:
//  ||      http://www.investopedia.com/ask/answers/06/geometricmean.asp
//  ||-----------------------------------------------------------------------------------------||

src = input(close)
length = input(10)

f_gma(_src, _length)=>
    _length_adjusted = _length < 1 ? 0 : _length
    _perc_change = change(_src) / _src
    _sum = 1
    for _i = 0 to (_length_adjusted)
        _sum := _sum * (1 + _perc_change[_i])
    _return = nz(_return[1], _src) + _src * (pow(_sum, (1 / _length_adjusted)) - 1)

//plot(ema(src, length), color=color(gray, 0), linewidth=5)
plot(f_gma(src, length), color=color(blue, 0), linewidth=1)

Comments

This is actually real cool. Just messing with settings on 4hr btc all time chart... there are some interesting potential models that can be derived already. I'll have to mess with this a bit and see if I can produce any attractive models just to see if they hold up in the future as an experiment. Seems like a weird formula to derive models from but I feel there is something here... I'm a noob though maybe its obvious haha
Reply