'if' 块中的 Pine Script 编译器类型错误
Pine Script compiler type error in 'if' blocks
我正在尝试熟悉 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)
用if actual_price < close_price
代替else
我正在尝试熟悉 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)
用if actual_price < close_price
代替else