for和array - pine脚本中的语法错误



我有一个语法问题,输出如下:

Error en 12:0 Syntax error at input '='.

特别是在这部分代码中:

// Calculate EMA values
ema_periods = input(title="EMA Periods", type=input.integer, defval=string(9, 21, 50, 100, 200))
ema_values = array.new_float(size = array.size(ema_periods))
for i = 0 to array.size(ema_periods) - 1 
ema_values[i] = ema(close, ema_periods[i])

错误如下:图片错误

完整代码如下:

//@version=4
study("Solfeggio Waves Dashboard")
// Define Solfeggio waves frequencies
var int[] frequencies = array.from(174, 285, 396, 417, 528, 639, 741, 852, 963)
// Calculate EMA values
ema_periods = input(title="EMA Periods", type=input.integer, defval=string(9, 21, 50, 100, 200))
ema_values = array.new_float(size = array.size(ema_periods))
for i = 0 to array.size(ema_periods) - 1 
ema_values[i] = ema(close, ema_periods[i])
// Calculate the percentage of positive and negative Solfeggio waves
var float[] positive_percents = array.new_float(size = array.size(frequencies))
var float[] negative_percents = array.new_float(size = array.size(frequencies))
for i = 0 to array.size(frequencies) - 1
positive_count = 0
negative_count = 0
for j = 0 to array.size(ema_values) - 1
if crossover(level_[frequencies[i]], ema_values[j])
positive_count := positive_count + 1
else if crossunder(level_[frequencies[i]], ema_values[j])
negative_count := negative_count + 1
positive_percents[i] := 100 * positive_count / array.size(ema_values)
negative_percents[i] := 100 * negative_count / array.size(ema_values)
// Plot the dashboard
plot(negative_percents[0], color=color.rgb(255, 235, 59, 66), style=plot.style_area, title="Negative 174 Hz")
plot(positive_percents[0], color=color.yellow, style=plot.style_area, title="Positive 174 Hz")
plot(negative_percents[1], color=color.rgb(255, 82, 82, 66), style=plot.style_area, title="Negative 285 Hz")
plot(positive_percents[1], color=color.red, style=plot.style_area, title="Positive 285 Hz")
plot(negative_percents[2], color=color.rgb(33, 149, 243, 64), style=plot.style_area, title="Negative 396 Hz")
plot(positive_percents[2], color=color.blue, style=plot.style_area, title="Positive 396 Hz")
plot(negative_percents[3], color=color.rgb(76, 175, 79, 68), style=plot.style_area, title="Negative 417 Hz")
plot(positive_percents[3], color=color.green, style=plot.style_area, title="Positive 417 Hz")
plot(negative_percents[4], color=color.rgb(155, 39, 176, 74), style=plot.style_area, title="Negative 528 Hz")
plot(positive_percents[4], color=color.purple, style=plot.style_area, title="Positive 528 Hz")
plot(negative_percents[5], color=color.rgb(255, 153, 0, 69), style=plot.style_area, title="Negative 639 Hz")
plot(positive_percents[5], color=color.orange, style=plot.style_area, title="Positive 639 Hz")
plot(negative_percents[6], color=color.rgb(136, 14, 79, 73), style=plot.style_area, title="Negative 741 Hz")
plot(positive_percents[6], color=color.maroon, style=plot.style_area, title="Positive 741 Hz")
plot(negative_percents[7], color=color.rgb(0, 187, 212, 75), style=plot.style_area, title="Negative 852 Hz")
plot(positive_percents[7], color=color.aqua, style=plot.style_area, title="Positive 852 Hz")
plot(negative_percents[8], color=color.rgb(0, 230, 119, 79), style=plot.style_area, title="Negative 963 Hz")
plot(positive_percents[8], color=color.lime, style=plot.style_area, title="Positive 963 Hz")

修复控制台输出中显示的问题。

您需要使用array.set()函数来设置数组的值。

array.set(id, index, value) → void

id(数组)数组对象。
index (integer)要修改的元素的索引。
value (float, string, label, line)要设置的新值。

最新更新