TO

Category: Instructions

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.

Syntax:

FOR variable = start_value TO end_value DO
    // Code to execute each iteration
NEXT variable

Example:

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.

Additional Information:

  • The TO keyword is essential for defining the upper limit of the loop.
  • Ensure that the variable used in the FOR loop (in this case, x) is initialized before the loop starts and is incremented in each iteration unless manually controlled within the loop body.
  • The loop will execute the block of code between the DO and NEXT keywords for each value of the variable from the start value to the end value inclusively.

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.

Logo Logo
Loading...