In the ProBuilder language, the term Undefined is used to set a variable’s value to an undefined state. By default, a variable that is not explicitly assigned a value is equal to 0. Setting a variable to Undefined makes it invisible and unusable in calculations. This is particularly useful in scenarios where you need to indicate that a variable’s value is not currently set or known.
myvariable = Undefined
Definition and Purpose:
The Undefined keyword is used to explicitly clear a variable’s default value. Since variables are not initialized in ProBuilder and start at 0 by default, assigning Undefined prevents the variable from acting as a 0 initially. Important: Undefined can only be assigned to a variable once, usually at the very beginning of the code. Once the variable is assigned a real numerical value, it cannot be reverted back to Undefined.
myPrice = Undefined
if condition1 then
myPrice = close
endif
// Note: You cannot directly test if a variable equals Undefined.
// Instead, since undefined is treated as 0 in boolean evaluations, you can test if it equals 0.
if myPrice = 0 then
// Perform specific actions when myPrice has not been set yet
endif
In this example, the variable myPrice is initially set to Undefined to avoid it being equivalent to 0 from the start. Depending on a condition (condition1), myPrice may later be assigned the value of the current closing price. Since Undefined cannot be tested directly, the script checks if myPrice is 0 to decide whether to perform certain actions.