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 or initialize a variable’s value. By assigning Undefined to a variable, you ensure that the variable does not hold any previous data and is not used in calculations, which can be crucial for avoiding errors or incorrect data processing in your trading algorithms.
Price = Undefined
if condition1 then
Price = close
endif
// Note: You cannot test if Price = Undefined
if Price = 0 then
// Perform specific actions when Price is not set or is zero
endif
In this example, the variable Price is initially set to Undefined. Depending on a condition (condition1), Price may later be assigned the value of the current closing price (close). Since Undefined cannot be tested, the script checks if Price is zero to decide whether to perform certain actions, which is useful in cases where Price should only be used if it has been explicitly set.
Understanding and using Undefined effectively can help in managing the flow of data and conditions within your ProBuilder scripts, ensuring that your trading algorithms perform as expected without unintended interference from residual data in variables.