DOWNTO

Category: Instructions

Definition and Purpose:

The DOWNTO keyword in ProBuilder language is used within a FOR/NEXT loop to specify that the loop should iterate in a descending order. This is particularly useful when you need to process elements from a higher index to a lower index, which is common in various programming scenarios, including data analysis and algorithm implementation in trading systems.

Syntax:

FOR variable = startValue DOWNTO endValue DO
    // Loop body
NEXT

Example:

Here is a simple example to demonstrate the use of DOWNTO in a FOR/NEXT loop. The following script calculates the number of times the closing price is less than the opening price in a descending order from the 20th bar to the 0th bar on a chart:

Value = 0
FOR i = 20 DOWNTO 0 DO
    IF (Close[i] < Open[i]) THEN
        Value = Value + 1
    ELSE
        BREAK
    ENDIF
NEXT
RETURN Value

Additional Information:

  • The DOWNTO keyword is crucial for scenarios where the order of processing is important, such as when analyzing data from the most recent to the oldest in financial charts.
  • The loop will terminate early if the BREAK statement is executed, which in this example occurs if the condition (Close[i] >= Open[i]) is met.
  • It is important to ensure that the start value is greater than the end value when using DOWNTO, otherwise, the loop will not execute.

This keyword enhances the control over loop execution and is a fundamental aspect of looping constructs in the ProBuilder programming language.

Related Instructions:

  • BREAK instructions
  • DO instructions
  • FOR instructions
  • NEXT instructions
  • TO instructions
  • Logo Logo
    Loading...