0

我在这个论坛上看到很多帖子询问 pinescript 中的这个函数,但到目前为止,没有一个回答如何使用第三个参数“offset”来修改函数内部的计算。

以下是 TradingView 提供的该功能的说明:

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

我发现,如果您在 pinescript 中为 offset 参数提供零值,则输出与 Thinkorswim 上名为“Inertia()”的函数完全相同。TD Ameritrade 提供了如何计算其函数的详细示例。此处列出:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/Inertia

这是该链接中的代码:

script inertiaTS {
    input y = close;
    input n = 20;
    def x = x[1] + 1;
    def a = (n * Sum(x * y, n) - Sum(x, n) * Sum(y, n) ) / ( n * Sum(Sqr(x), n) - Sqr(Sum(x, n)));
    def b = (Sum(Sqr(x), n) * Sum(y, n) - Sum(x, n) * Sum(x * y, n) ) / ( n * Sum(Sqr(x), n) - Sqr(Sum(x, n)));
    plot InertiaTS = a * x + b;
}

input length = 20;
plot LinReg1 = Inertia(close, length);
plot LinReg2 = InertiaTS(close, length);

我的问题是这个。如何修改 Thinkorswim 代码中的公式,使其包含一个与 pinescript 中的“offset”参数等效的参数。

4

0 回答 0