The TO keyword in ProBuilder language is used as a directional instruction within a FOR loop. It specifies the range through which the loop should iterate, defining the endpoint of the loop’s range.
FOR variable = start_value TO end_value DO
// Code to execute each iteration
NEXT variable
Here is a simple example to demonstrate the use of TO in a FOR loop:
FOR x = 1 TO 20 DO
total = total + close[x] / open[x]
NEXT x
In this example, the loop will iterate from 1 to 20. During each iteration, it calculates the ratio of the closing price to the opening price for the xth bar, and adds this value to a cumulative total.
This structure is particularly useful for iterating over a series of data points, such as financial time series data, where operations need to be repeated across a defined range of values.