尝试将 pinescript 代码转换为版本 4 时出现"不能调用带有参数的 abs"错误



我正在尝试将pinescript代码转换为版本4。代码低于

Early = abs((close[3] > open[3] and close[2] > open[2] and close[1] > open[1] and close < open) or (close[3] > open[3] and close[2] > open[2] and close[1] < open[1] and close > open) or (close[3] > open[3] and close[2] < open[2] and close[1] > open[1] and close > open) or (close[3] < open[3] and close[2] > open[2] and close[1] > open[1] and close > open) or (close[3] > open[3] and close[2] > open[2] and close[1] > open[1] and close > open))*(low*.9999525)

EarlyD = abs((close[3] < open[3] and close[2] < open[2] and close[1] < open[1] and close > open) or (close[3] < open[3] and close[2] < open[2] and close[1] > open[1] and close < open) or (close[3] < open[3] and close[2] > open[2] and close[1] < open[1] and close < open) or (close[3] > open[3] and close[2] < open[2] and close[1] < open[1] and close < open) or (close[3] < open[3] and close[2] < open[2] and close[1] < open[1] and close < open))*(high*1.00009525)

EarlyTd = abs(close > TL(low, 16) and close < l)*(low*.9999525)
EarlyTu = abs(close < TH(high, 16) and close > h)*(high*1.00009525)

我得到以下错误:

line 113: Cannot call 'abs' with arguments (series[bool]); available overloads: abs(integer) => integer; abs(input integer) => input integer; abs(const integer) => const integer; abs(float) => float; abs(input float) => input float; abs(const float) => const float; abs(series[float]) => series[float];
line 114: Cannot call 'abs' with arguments (series[bool]); available overloads: abs(integer) => integer; abs(input integer) => input integer; abs(const integer) => const integer; abs(float) => float; abs(input float) => input float; abs(const float) => const float; abs(series[float]) => series[float];
line 113: Cannot call 'operator *' with arguments (series[bool], series[float]); available overloads: *(const integer, const integer) => const integer; *(const float, const float) => const float; *(input integer, input integer) => input integer; *(input float, input float) => input float; *(integer, integer) => integer; *(float, float) => float; *(series[integer], series[integer]) => series[integer]; *(series[float], series[float]) => series[float];
line 115: Cannot call 'operator *' with arguments (series[bool], series[float]); available overloads: *(const integer, const integer) => const integer; *(const float, const float) => const float; *(input integer, input integer) => input integer; *(input float, input float) => input float; *(integer, integer) => integer; *(float, float) => float; *(series[integer], series[integer]) => series[integer]; *(series[float], series[float]) => series[float];

您可能正在寻找更像这样的东西。你不能用数值来操作布尔表达式,所以我们分两步来做:首先我们定义条件(布尔值(,然后使用它们来构建价格。

// #1: Build boolean conditions.
EarlyU = (close[3] > open[3] and close[2] > open[2] and close[1] > open[1] and close < open) 
or (close[3] > open[3] and close[2] > open[2] and close[1] < open[1] and close > open) 
or (close[3] > open[3] and close[2] < open[2] and close[1] > open[1] and close > open) 
or (close[3] < open[3] and close[2] > open[2] and close[1] > open[1] and close > open) 
or (close[3] > open[3] and close[2] > open[2] and close[1] > open[1] and close > open)

EarlyD = (close[3] < open[3] and close[2] < open[2] and close[1] < open[1] and close > open) 
or (close[3] < open[3] and close[2] < open[2] and close[1] > open[1] and close < open) 
or (close[3] < open[3] and close[2] > open[2] and close[1] < open[1] and close < open) 
or (close[3] > open[3] and close[2] < open[2] and close[1] < open[1] and close < open) 
or (close[3] < open[3] and close[2] < open[2] and close[1] < open[1] and close < open)

EarlyTd = close > TL(low, 16) and close < l
EarlyTu = close < TH(high, 16) and close > h

// #2: Build prices.
EarlyUVal  = EarlyU  ? low  * 0.9999525  : na
EarlyDVal  = EarlyD  ? low  * 0.9999525  : na
EarlyTdVal = EarlyTd ? high * 1.00009525 : na
EarlyTuVal = EarlyTu ? high * 1.00009525 : na

最新更新