0

我正在尝试从 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

谁能指导我想念什么?

谢谢

PS cci0 - 当前蜡烛图 cci, cci1 - 前蜡烛图 cci

4

1 回答 1

0

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

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

我不知道围棋,但这就是逻辑。

于 2021-05-25T00:05:24.840 回答