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/06/geometricmean.asp
Remove from Favorite Scripts Add to Favorite Scripts
//@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)

United States
United Kingdom
India
Deutschland
France
España
Italia
Polska
Türkiye
Россия
Brasil
Indonesia
Malaysia
ประเทศไทย
Việt Nam
日本
한국
简体
繁體
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Contact Support Ideas Published Followers Following Private Messages Chat Sign Out