Type/to search
1
Follow
1
Followers
Aide EMA
Help
Created 2021-01-08 00:08:49  Updated 2021-01-08 13:41:42
 6
 1640

pine_ema(src, length) =>
alpha = 2 / (length + 1)
sum = 0.0
sum := na(sum[1]) ? sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])
plot(pine_ema(close,15))

La formule EMA de TV est la suivante:[1]) ? sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])
J'ai du mal à comprendre ce passage, est-ce que quelqu'un peut m'aider à le traduire en pyhton, merci.

Les commentaires:

  1. df['close'].ewm(span=110,adjust = False).mean()
  2. talib.EMA(np.array(close), timeperiod=110)
    Les résultats des tests ne correspondent pas à la TV (moins de 50 est la même probabilité) et plus de 100 est différent.
Related Recommendations
Comment
All comments (6)

    这是 写好的 JavaScript 的 ema 函数,重点需要注意的是,源数组中,索引 与 长度参数 不同条件下的计算方式

    5 years ago

    function ema(src, length) {
    var arr = [];
    var sum = 0;
    var alpha = 2 / (length + 1)

    for(var i in src) {
    if( i<length-1 ) {
    arr[i] = null;
    sum += src[i];
    }

    if( i==length-1 ) {
    arr[i] = (sum+src[i])/length;
    }

    else {
    arr[i] = alpha * src[i] + (1 - alpha) * arr[i-1]
    }
    }
    return arr;
    }

    5 years ago

    ewm算法可以自己写,具体 ewm = alpha*close+(1-alpha)*ewm

    6 years ago

    好像结果跟ewma也不相同
    def EMA(ps,period=5,exp=0.1):
    ewma=pd.Series(0.0,index=ps.index)
    ewma[period-1]=ps[:period].mean()
    for i in range(period,len(ps)):
    ewma[i] =exp*ps[i]+(1-exp)*ewma[i-1]
    return ewma

    6 years ago

    算法不太一样,有细微的区别,可以不用考虑,比如用迭代的方法第一个值应该怎么取,自己选择一个就行

    6 years ago

    嗯。目前是通过修改exp=0.1得到近似值。多谢。

    6 years ago
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)