Undefined

Category: Constants

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.

Syntax:

  • The syntax for setting a variable to undefined is straightforward: simply use the variable name followed by an equals sign and the keyword Undefined.

Example:

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.

Additional Information:

  • Using Undefined is a good practice to avoid logical errors in scripts where the initialization state of variables matters.
  • It helps in maintaining clean and error-free code, especially in complex conditions and loops.
  • Once a variable is assigned a value after being set to Undefined, it cannot be reverted to Undefined again.
  • Variables set to Undefined are not visible or used in calculations.

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.

Logo Logo
Loading...