ELSIF

Category: Instructions

ELSIF is a conditional statement in the ProBuilder programming language, used as part of a control flow structure. It allows the programmer to specify a new condition to test, if the previous if condition fails. The ELSIF statement provides a way to check multiple conditions sequentially within the same if statement block.

Syntax:

IF (condition1) THEN
    [statements]
ELSIF (condition2) THEN
    [statements]
ELSE
    [statements]
ENDIF

Example:

myDPO = DPO[21](typicalprice)
IF (myDPO < 0) THEN
    result = result - 1
ELSIF (myDPO > 0) THEN
    result = result + 1
ELSE
    result = result
ENDIF
RETURN result
COLOURED(124,252,0)

In this example, the ELSIF statement is used to check if myDPO is greater than 0 after the initial IF condition (myDPO < 0) fails. If myDPO is indeed greater than 0, it increments the result by 1. If neither condition is met, the ELSE part executes, which in this case, leaves the result unchanged.

  • The DPO (Detrended Price Oscillator) indicator is used here to measure the difference between the past price and a moving average, helping to identify cycles and overbought/oversold conditions in a market.
  • The COLOURED function is used to set the color of the output, enhancing visual representation in charts or indicators.

This structure is particularly useful in scenarios where multiple conditions might dictate different actions or outputs, allowing for clear and organized decision-making processes in trading algorithms.

Related Instructions:

  • ELSE instructions
  • ENDIF instructions
  • IF instructions
  • THEN instructions
  • Logo Logo
    Loading...