Inline IF and converting conditions to indicators
These functions allow you to convert Boolean (true or false) results into numeric results.
The Personal Criteria Formula Language is designed for creating formulas and isn't a full scripting or programming language, but it still has the inline IF function available to use a condition to choose between two different numeric results.
IIF(C > O, C, O) would return the close if the close is above the open and the open otherwise. You can nest multiple IIF() functions in order to get results relying on a chain of multiple conditions.
The CountTrue(), SinceTrue(), and TrueInRow() functions all return numeric values based on how many times or when conditions were true over a span of bars (which must be specified and cannot be left open ended).
Putting a Boolean formula inside parentheses or an ABS() function can also be used to return numeric values, but is largely a more limited way of implementing the IIF() function.
returns t if b is true and f if b is false |
IIF(b, t, f) |
b =Boolean, t =Numeric, f =Numeric |
returns the number of times Boolean formula was true in the period |
CountTrue(b, x) |
b =Boolean, x =Period |
returns -1 if Boolean Formula was not true in period, or bars since it was true, 0 being the current bar, and period-1 the max it will return |
SinceTrue(b, x) |
|
SinceTrue() alternative which returns the period as a numeric value instead of -1 if the Boolean Formula was not true in period |
TrueInRow(NOT(b), x) |
|
returns a value between 0 and period that is how many times the Boolean formula was true in a row |
TrueInRow(b, x) |
|
returns -1 if b is true and 0 if b is false |
(b) |
b =Boolean |
returns 1 if b is true and 0 if b is false |
ABS(b) |