ELSIF
ELSIF in ProBuilder tests a new condition when the preceding IF condition fails, letting one block check several exclusive conditions in strict sequence.
Syntax
IF (condition1) THEN
// runs when condition1 is true
ELSIF (condition2) THEN
// runs when condition1 is false and condition2 is true
ELSE
// runs when no condition matched
ENDIFHow it works
Conditions in an IF/ELSIF chain are evaluated top to bottom. The first one that is true wins: its block runs and every remaining branch, including ELSE, is skipped. When none of the conditions is true, the ELSE block runs if present, otherwise the whole statement does nothing.
An IF statement can carry any number of ELSIF branches, each with its own condition and its own THEN. This produces a flat multi-way branch that is easier to read than the equivalent nested IF statements, and it needs only a single ENDIF.
Order matters. Because evaluation stops at the first match, broader conditions placed early will shadow narrower ones placed later. Put the most specific tests first.
Examples
Example 1, Scoring an oscillator in three states (Indicator)
myDPO = DPO[21](typicalprice)
IF (myDPO < 0) THEN
// negative oscillator lowers the score
result = result - 1
ELSIF (myDPO > 0) THEN
// positive oscillator raises the score
result = result + 1
ELSE
// exactly zero leaves the score unchanged
result = result
ENDIF
RETURN result
COLOURED(124,252,0)The ELSIF branch is reached only when the Detrended Price Oscillator is not negative. A positive reading increments the running score, a reading of exactly zero falls through to ELSE.
Example 2, RSI zone filter (ProScreener)
r = RSI[14](close)
// map the RSI reading onto three zones
IF r < 30 THEN
zone = -1
ELSIF r > 70 THEN
zone = 1
ELSE
zone = 0
ENDIF
SCREENER[zone <> 0] (r AS "RSI 14")Each instrument lands in exactly one zone. The screener keeps only the oversold and overbought cases and displays the raw RSI value.
Example 3, Trend regime with graded position size (ProOrder)
DEFPARAM CumulateOrders = false
fast = Average[20](close)
slow = Average[50](close)
// grade the trend from strong to absent
IF fast > slow AND close > fast THEN
size = 2
ELSIF fast > slow THEN
size = 1
ELSE
size = 0
ENDIF
IF size > 0 AND NOT onmarket THEN
BUY size CONTRACT AT MARKET
ENDIFThe specific case, price above a rising average stack, is tested before the broader one. Reversing the two branches would make the strong-trend block unreachable.
Common errors and gotchas
- Missing THEN after the ELSIF condition. Every ELSIF requires its own THEN, exactly like IF.
ELSIF (a > b)on its own line without THEN does not compile. - Spelling it ELSEIF. The keyword is ELSIF, with one E. Variants from other languages, such as ELSEIF or ELIF, are rejected by the compiler.
- Unreachable branches. Evaluation stops at the first true condition. An early broad test such as
r > 50prevents a laterr > 70branch from ever running, with no warning. - ELSIF placed after ELSE. ELSE must be the final branch. Any ELSIF following it is a syntax error, so keep the chain in the order IF, ELSIF, ELSE, ENDIF.
Related instructions
IF, opens the conditional chain.ELSE, unconditional fallback after all ELSIF branches.ENDIF, closes the whole chain, one per IF regardless of branch count.THEN, required after each IF and ELSIF condition.AND, builds compound conditions inside a branch test.OR, alternative conditions inside a branch test.
