CS1052
error ChartScript does not support this form of for loop: use for (let i = a; i < b; i++), for (const x of list) or while.
#What it means
ChartScript accepts one shape of counting loop: one variable, a condition comparing that variable with <, <=, > or >=, and a step on the same variable (i++, i--, i += s, i -= s). This loop has another shape, such as two variables, && in the condition or a step on another variable.
#Typical cause
- Two loop variables, as in
for (let i = 0, j = 1; ...). - A condition with
&&or||, or a condition about another variable. - A loop head with parts missing.
#How to fix it
Write for (let i = a; i < b; i++), for (const x of list) to walk a collection, or a while loop for anything else. See Loops.
#Example
//@chartscript 1
indicator("Sum")
let s = 0.0
for (let i = 0, j = 1; i < 10; i++) {
s += close[i]
}
plot(s)Fixed
//@chartscript 1
indicator("Sum")
let s = 0.0
for (let i = 0; i < 10; i++) {
s += close[i]
}
plot(s)#Related
- CS2702 — A loop over the items of a list needs an array.