Exploration result is improper

The exploration result of my below code is not proper. kinldy requesting the experts what mistake I made in my code.

Below is my exploration code

price_status = WriteIf(Close > Ref(Close, -1), "Bullish","Bearish");

//exploration
Filter=1;

AddColumn(Close, "Close", 1.2);
AddColumn(Ref(Close, -1), "Prev. Close", 1.2);
AddColumn(Close - Ref(Close, -1), "Diff", 1.2);
AddColumn(Close > Ref(Close, -1), "condition", 1);
AddTextColumn(price_status,"Status");

but the exploration result shows only one text for all condition.
The screen shot is as below

exploration

Try:

price_status = IIf(Close > Ref(Close, -1), "Bullish","Bearish");

https://www.amibroker.com/guide/afl/iif.html

Sir, Thanks for your reply.

the IIF function throws error.

In my explorer image the output STRING is same for TRUE and FALSE condtion using writeif.

For TRUE condition, it should show "Bullish"
For FALSE condition, it should show "Bearish"

I can't able to find, we I gone wrong in my code

WriteIf function output result for single element of array (if "Expression" is array type). It does not output array. There is not array of strings in AFL.

It is clearly mentioned in manual what WriteIf does (so it works properly according to its purpose) and has been posted several times already.

16

Also AddTextColumn() function does not output array of strings.


And IIf() function is for numerical input/output values but not for stings.You even posted the link to manual.

17


Long story short... for conditional string output on historical numeric array in explorer you have to use AddMultiTextColumn().

//exploration
Filter=1;

AddColumn(Close, "Close", 1.2);
AddColumn(Ref(Close, -1), "Prev. Close", 1.2);
AddColumn(Close - Ref(Close, -1), "Diff", 1.2);
AddColumn(condition = Close > Ref(Close, -1), "condition", 1);
color = IIf(condition,colorGreen,colorRed);
AddMultiTextColumn(condition,"Bearish\nBullish", "Status", 1, color, -1);

17

1 Like

Thanks sir @fxshrat ,

Now understood and problem solved

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.