1 回答

TA貢獻1841條經驗 獲得超3個贊
PineScript在尋找函數時具有非常好的參考,通常甚至提供松樹代碼來重新創建它。
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))
我不知道絕對偏差是什么意思,但至少在它們的實現中,它似乎取了范圍內每個值的平均值的差值,但隨著您返回,并沒有改變平均值。
我不知道圍棋,但這就是邏輯。
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報