Function Simple Moving Average

Function describing Simple Moving Average
Remove from Favorite Scripts Add to Favorite Scripts
study(title='Function Simple Moving Average', overlay=true)
src = input(close)
length = input(10)

f_sma(_src, _length)=>
    _length_adjusted = _length < 1 ? 1 : _length
    _sum = 0
    for _i = 0 to (_length_adjusted - 1)
        _sum := _sum + _src[_i]
    _return = _sum / _length_adjusted

plot(sma(src, length), color=color(gray, 0), linewidth=5)
plot(f_sma(src, length), color=color(blue, 0), linewidth=1)

Thank you Richard: Why is there an "_" before every variable, function and constant in your formula? Michael
RicardoSantos StockSwinger
just a way to identify local variables inside a function/loop/multiline statement, personal variable naming method.
EN English
EN English (UK)
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
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