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 关注
- 89 浏览
添加回答
举报