WriteIf
- commentary conditional text output

Exploration / Indicators


SYNTAX WriteIf( EXPRESSION, "TRUE TEXT", "FALSE TEXT" )
RETURNS STRING
FUNCTION If EXPRESSION evaluates to "true", then the TRUE TEXT string is displayed within the commentary. If EXPRESSION evaluates to "false", then the FALSE TEXT string is displayed.
EXAMPLE writeif( c > mov(c,200,s), "The close is above the 200-period moving average.","The close is below the 200-period moving average." )
SEE ALSO

Comments:

Tomasz Janeczko
tj --at-- amibroker.com
2004-06-12 05:56:01
WriteIf in fact does not "write" anything. The name is misleading but it is left
for easy translation of MS formulas to AmiBroker.
WriteIf is just "TextIIF" it RETURNS string value depending on condition.

In commentary window, statements evaluating to STRINGS on global level
are displayed in the output window. However if you do the same inside the FUNCTION
it is no longer in global level (it is on LOCAL, FUNCTION level).

To display actual string in this case use PRINTF function:
http://www.amibroker.com/f?printf


function comment(indicator)
{
printf( "\nComment...\n" );

printf( WriteIf(1, "TrueText", "FalseText") );
printf( WriteVal(indicator) + "\n" );
}
Tomasz Janeczko

2005-08-10 06:37:55
Please note that WriteIf returns just single string representing current SelectedValue of the EXPRESSION

References:

The WriteIf function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference