TradingView » Looping code snippets
A ‘loop’ is a code construct that repeats a certain piece of code. This makes it possible to do things like, ‘for each of the last 5 bars, calculate this indicator value’.
TradingView Pine has one kind of loop: the
for loop. This loop repeats a piece of code up to a certain number of times.
The snippets below show how to work with those loops, and how we can control them with the
In this article we discuss how the for loop in TradingView works. For statement allows to execute a number of instructions repeatedly.
To have access to and use the for statement, one should specify the version >= 2 of Pine Script language in the very first line of code, for example:
Read this snippet »