如何从 Golang 的交易视图中获取相同的 cci 值?

How to get same cci values from Trading view in Golang?

我正在尝试从 golang 中的 pine 脚本 cci() 函数复制值。我找到了这个库 https://github.com/markcheno/go-talib/blob/master/talib.go#L1821 但它给出的值与 cci 函数给出的值完全不同

伪代码我如何使用lib

cci := talib.Cci(latest14CandlesHighArray, latest14CandlesLowArray, latest14CandlesCloseArray, 14)

库给了我以下数据

Timestamp: 2021-05-22 18:59:27.675, Symbol: BTCUSDT, Interval: 5m, Open: 38193.78000000, Close: 38122.16000000, High: 38283.55000000, Low: 38067.92000000, StartTime: 2021-05-22 18:55:00.000, EndTime: 2021-05-22 18:59:59.999, Sma: 38091.41020000, Cci0: -16.63898084, Cci1: -53.92565811,

虽然 TradingView 上的当前 cci 值为:cci0 - -136,cci1 - -49

谁能指导我错过了什么?

谢谢

P.S。 cci0 - 当前蜡烛 cci,cci1 - 前一根蜡烛 cci

PineScript 在寻找函数时有很好的参考,通常甚至提供重新创建它的 pine 代码。

https://www.tradingview.com/pine-script-reference/v4/#fun_cci

没有为 cci 提供代码,但提供了分步说明。 以下是我如何按照参考中的步骤使用 Pine 重新创建 cci 函数:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bajaco

//@version=4
study("CCI Breakdown", overlay=false, precision=16)

cci_breakdown(src, p) =>
    // The CCI (commodity channel index) is calculated as the 
    // 1. difference between the typical price of a commodity and its simple moving average, 
    // divided by the 
    // 2. mean absolute deviation of the typical price. 
    // 3. The index is scaled by an inverse factor of 0.015 
    // to provide more readable numbers

    // 1. diff
    ma = sma(src,p)
    diff = src - ma
    
    // 2. mad
    s = 0.0
    for i = 0 to p - 1
        s := s + abs(src[i] - ma)
    mad = s / p
    
    // 3. Scaling
    mcci = diff/mad / 0.015
    mcci
    
plot(cci(close, 100))
plot(cci_breakdown(close,100))

我不知道平均绝对偏差是什么意思,但至少在他们的实现中,它似乎是在取范围内每个值的平均值的差异,但在返回时不会改变平均值。

我不懂围棋,但逻辑就是这样。