Nested IIF query

Hi, I'm trying to get a Nested IFF statement to work with a "string" output eg A,B,C etc instead on a numeric code eg 1,2,,3 etc. The code below runs ok if the output is numeric but not if it's a string. (it generates an output but ignores the whole Nested IFF conditions. There are No compile errors with AFL with the 'string' output which is most confusing. Any ideas to fix this. Thanks

Filter = 1;

// MFI is Money Flow Index
iMFI = MFI(14);

ModiMFI = IIf(iMFI > 4.12 AND iMFI <= 18.17,'A',
IIf(iMFI > 18.17 AND iMFI <= 26.85,'B',
IIf(iMFI > 26.85 AND iMFI <= 36.42,'C',
IIf(iMFI > 36.42 AND iMFI <= 44.9,'D',
IIf(iMFI > 44.9 AND iMFI <= 53.17,'E',
IIf(iMFI > 53.17 AND iMFI <= 61.3,'F',
IIf(iMFI > 61.3 AND iMFI <= 68.24,'G',
IIf(iMFI > 68.24 AND iMFI <= 73.6,'H',
IIf(iMFI > 73.6 AND iMFI <= 79.58,'I',
IIf(iMFI > 79.58,'J','A'))))))))));

AddColumn(Ref(ModiMFI,-4),"iMFI",1.2);

Please read this thread before posting

It is mandatory rule to insert code via code tags. Watch the animation in first post of that thread.


You have to use formatChar in 3rd argument of AddColumn.

Filter = 1;

// MFI is Money Flow Index
iMFI = MFI(14);

ModiMFI = IIf(iMFI > 4.12 AND iMFI <= 18.17,'A',
IIf(iMFI > 18.17 AND iMFI <= 26.85,'B',
IIf(iMFI > 26.85 AND iMFI <= 36.42,'C',
IIf(iMFI > 36.42 AND iMFI <= 44.9,'D',
IIf(iMFI > 44.9 AND iMFI <= 53.17,'E',
IIf(iMFI > 53.17 AND iMFI <= 61.3,'F',
IIf(iMFI > 61.3 AND iMFI <= 68.24,'G',
IIf(iMFI > 68.24 AND iMFI <= 73.6,'H',
IIf(iMFI > 73.6 AND iMFI <= 79.58,'I',
IIf(iMFI > 79.58,'J','A'))))))))));

AddColumn(Ref(ModiMFI,-4),"iMFI",formatchar);

BTW, e.g. 'A' is not type string but type number

var = 'A';
printf( "Type of var: %s", typeof(var) );

Take a look at Ascii Code table too.

1 Like

Worked a treat, many thanks for taking the time to respond - much appreciated