WriteIf is working AS DOCUMENTED, was: not working as I expect

Using:

AddTextColumn( WriteIf(IFU,"Up","Down"), "Index", 1.3, IIf(IFU,colorGreen,colorRed), 2, 40);
AddColumn(IFU,"IFU",1.0);

I see this:
2020-08-03 15_45_39-AmiBroker - Analysis3
The items boxed in red should display 'Up' and not 'Down' I believe. Where am I going wrong with the text output for WriteIf(IFU,"Up","Down") ?

WriteIf only returns single string for current selected value.

See WriteIf.

1 Like

There is no array of strings in AFL

But you may use AddMultiTextColumn to output string on array in Explorer.

Version(6.20);

IFU = C > MA(C,20);

Filter = 1;

// if IFU returns 0 or 1
AddMultiTextColumn(IFU,"Down\nUp", "Index", 1.3, IIf(IFU,colorGreen,colorRed), 2, 40);
AddColumn(IFU,"IFU",1.0);
2 Likes

Did you read the manual:
http://www.amibroker.com/guide/afl/writeif.html

It very clearly says:

Please note that WriteIf returns just single string representing current SelectedValue of the EXPRESSION

Yes. I did not know what that meant.

To me it made sense, as IFU returns a value for every row in the Exploration, that a function that consumes IFU should do the same, but it does not. I am more familiar with the C# and T-SQL; AFL is different. Hence the #newbie tag on this post.