这个线性回归是如何计算的?

How is this linear regression calculated?

在尝试翻译 Pine Script 指标时,我卡在了使用 linreg() 计算线性回归的这一行。线性回归公式不是应该接受数组吗?

val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), 20,0)

我想使用 trader_php 扩展中的 trader_linearreg() 函数,但它接受一个数组作为第一个参数。

pinescript 中没有数组。 Pine 中的基本数据类型是值列表,名为 series.

此外,任何包含系列变量的表达式都将被视为系列本身。

参考。 Type System

具有系列类型的变量也包含变量的所有先前值。您可以使用 History Referencing Operator.

访问它

linreg()的签名是:

linreg(source, length, offset) → series[float]

RETURNS
Linear regression curve.

ARGUMENTS
source (series) Source series.
length (integer) Length.
offset (integer) Offset.

在您的示例中,以下计算的结果是系列类型。

source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)), sma(close,lengthKC))

那是因为:

Any expression that contains a series variable will be treated as a series itself.