Matias Ignacio
Matias Ignacio

Reputation: 5

Syntax error in for and array - pine script

I am having a syntax problem, the output is the following:

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

Specifically in this part of the code:

// 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])

Here's the error: Error in the image

the complete code is the following:

//@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")

Fix problem shown in console output.

Upvotes: 0

Views: 79

Answers (1)

vitruvius
vitruvius

Reputation: 21342

You need to use array.set() function to set values of your array.

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

id (array) An array object.
index (integer) The index of the element to be modified.
value (float, string, label, line) The new value to be set.

Upvotes: 0

Related Questions