Pine 脚本代码 - 如何修复输入时的语法错误'='问题



我对这部分代码temp_x[j] = data[i - window_size + j]有问题,控制台说:错误en 16:0输入'='语法错误

我试图通过替换下面提到的代码来解决它,但它一直给出错误,这个问题的可能解决方案是什么?

我该如何修复它?

完整代码pine脚本:

//@version=4
study(title="Trend Prediction", shorttitle="Trend Prediction", overlay=true)
// Input variables
window_size = input(title="Window Size", type=input.integer, defval=10)
train_size = input(title="Train Size", type=input.integer, defval=70)
test_size = input(title="Test Size", type=input.integer, defval=30)
// Load data
data = close
x = array.new_float(0)
y = array.new_int(0)
for i = window_size to bar_index
temp_x = array.new_float(window_size)
for j = 0 to window_size - 1
temp_x[j] = data[i - window_size + j]
x := array.push(x, temp_x[0], temp_x[1], temp_x[2], temp_x[3], temp_x[4], temp_x[5], temp_x[6], temp_x[7], temp_x[8], temp_x[9])
y := array.push(y, data[i] > data[i - 1] ? 1 : 0)
// Split into train and test sets
split_index = round(array.size(x) * train_size / 100)
x_train = array.slice(x, 0, split_index)
y_train = array.slice(y, 0, split_index)
x_test = array.slice(x, split_index + 1, array.size(x))
y_test = array.slice(y, split_index + 1, array.size(y))
// Train decision tree model
model = ml_decision_tree(x_train, y_train, max_depth=3)
// Predict trend
predictions = ml_predict(model, x_test)
trend = array.new_bool(0)
for i = 0 to array.size(predictions) - 1
trend := array.push(trend, predictions[i] == 1)
// Plot trend
plot(trend ? data[split_index + 1] : na, color=color.green, style=plot.style_circles, linewidth=3, title="Bullish Trend")
plot(not trend ? data[split_index + 1] : na, color=color.red, style=plot.style_circles, linewidth=3, title="Bearish Trend")

我试着用:Temp_x [j] = data[i - window_size + j]

但仍有问题

在pinescript中,您不能像在python中那样对数组进行寻址。
要检索值,必须使用:

MyValue = array.get(NameOfMyArray, IndexOfTheValueInTheArray)

要记录一个值,必须使用:

array.set(NameOfMyArray, IndexOfTheValueInTheArray, Myvalue)

所以你必须改变:

temp_x[j] = data[i - window_size + j]

array.set(temp_x, j, data[i - window_size + j])

最新更新