【问题标题】:Pine Script compiler type error in 'if' blocks“if”块中的 Pine 脚本编译器类型错误
【发布时间】:2021-06-20 22:17:26
【问题描述】:

我正在尝试熟悉 pine 脚本。
为此,我正在尝试编写一个简单的策略,它将在图表上放置框。
但我收到以下错误,也许您可​​以帮我解决这个问题。
编译器错误信息说:

lines 31:45: Return type of one of the 'if' blocks is not compatible with return type of other block(s) (series[box]; void)

对我来说,很难理解错误消息的含义。 我检查了缩进和类型以进行比较。
你对此有什么想法吗?

代码如下:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
strategy("My Script", overlay=true)

// run on daily chart

// globals
var box[] up_boxes = array.new_box(0)
var float[] up_boxes_closes = array.new_float(0)

var box[] down_boxes = array.new_box(0)
var float[] down_boxes_closes = array.new_float(0)


// check for new boxes
// upper
if (low > high[1])
    array.push(up_boxes, box.new(left=bar_index[1], top=high[1], bottom=low, right=bar_index))
    array.push(up_boxes_closes, high[1])
// lower
else if (high < low[1])
    array.push(down_boxes, box.new(left=bar_index[1], top=low[1], bottom=high, right=bar_index))
    array.push(down_boxes_closes, low[1])


// check if boxes can be removed (no longer updated)
for i = 0 to array.size(up_boxes) - 1
    // reomve from the array, if our price is higher, else extend it
    float close_price = array.get(up_boxes_closes, i)
    float actual_price = high[0]
    if (actual_price >= close_price)
        array.remove(up_boxes_closes, i)
        array.remove(up_boxes, i)
    else
        id = array.get(up_boxes, i)
        box.set_right(id, bar_index)

// check if boxes can be removed (no longer updated)
//for j = 0 to array.size(down_boxes) - 1
//    // reomve from the array, if our price is lower, else extend it
//    if (low < array.get(down_boxes_closes, j))
//        array.remove(down_boxes_closes, j)
//        array.remove(down_boxes, j)
//    else
//        box.set_right(array.get(down_boxes, j), bar_index)

【问题讨论】:

  • 您的 ifelse 块需要返回相同的类型。首先是 array.remove() => void();第二个是系列[框]。正如 rumpypumpydumpy 提到的,使用不同的 if 块。
  • @StarrLucky 等待:是的,谢谢,经过澄清,这些文档现在对我来说确实有意义。

标签: pine-script


【解决方案1】:

if actual_price &lt; close_price 代替else

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2020-03-26
    相关资源
    最近更新 更多