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
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)

EN English
EN English (UK)
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
SV Svenska
TR Türkçe
RU Русский
PT Português
ID Bahasa Indonesia
MS Bahasa Melayu
TH ภาษาไทย
VI Tiếng Việt
JA 日本語
KO 한국어
ZH 简体中文
ZH 繁體中文
AR العربية
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