Skip to content
Algo Trade Analytics Docs

for...in - Pine Script Keyword

The for…in structure allows the repeated execution of a number of statements for each element in an array. It can be used with either one argument: array_element, or with two: [index, array_element]. The second form doesn’t affect the functionality of the loop. It tracks the current iteration’s index in the tuple’s first variable.

[var_declaration =] for array_element in array_id
statements | continue | break
return_expression
[var_declaration =] for [index, array_element] in array_id
statements | continue | break
return_expression
//@version=6indicator("`for ... in` matrix Example")// Create a 2x3 matrix with values `4`.matrix1 = matrix.new<int>(2, 3, 4)sum = 0.0// Loop through every row of the matrix.for rowArray in matrix1    // Sum values of the every row    sum += array.sum(rowArray)plot(sum)