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.
FOR variable = startValue DOWNTO endValue DO
// Loop body
NEXT
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
This keyword enhances the control over loop execution and is a fundamental aspect of looping constructs in the ProBuilder programming language.