How to add a single column that says oversold, overbought and neutral based on the RSI?


How to add a single column that says: oversold, overbought and neutral based on the RSI?


You may use AddMultiTextColumn() for that.
Introduced in AB 6.19 ( there seems to be a formatting error in "TextList" variable in this link's example code, Separator should be "\n")

_rsi = RSI( 15 );

TextList = "Neutral\nOverbought\nOversold";
TextSelector = 1 * (_rsi > 70) + 2 * (_rsi < 30);

Nice and thank you!

That way I want the column!, would you be so kind to share me the complete syntax?

I bought Amibroker on August 29, 2016, I have never updated it, it is recommended that I upgrade it and what version should it be?

Currently it tells me that I have Standard Edition (32bit), version 6.00.2.

My operating system is 64bits.

Thanks and regards

I have mentioned the minimum version in my first post already -> 6.19
beta. So you would need to install most recent final version -> 6.20
at least.

Since you have bought 2016 you would still be within free update
period. So simply download and install mentioned version (no need to
uninstall your current version BTW).

As for entire code… simply use the code of the readme link of my first
post. It is dead easy! You just have to replace/remove lines. Play
around with the code and edit to your needs. You won’t start WWIII if
creating an error. I am trying to teach you how to fish but not
bringing the entire fish down to your feet (even more so if it is so
easy as in this case). If you face problems on your code journey then
come back and feel free to ask…

You are right, thank you, I just started in this world of AFL, I added the function, but I can not find how to assign the different colors for the background (bkcolor)

It follows the same structure as AddColumn(). The 4th and 5th parameters define the colors.


You can find a list of available colors heere:

Yes, but I have never added background colors, I can not understand how to assign, for example blue for neutral, green for overbought and so on

Thank you

What code do you have so far?
Maybe we should start there.

Textselector variable is an array.
Background color is supposed to be dependent on Textselector’s return.
So as for Background color… it is an array too.

TextSelector’s formula is

TextSelector = 1 * (_rsi > 70) + 2 * (_rsi < 30);

So always ask yourself in your mother tongue what is it what you want to achieve in the end, which variables are involved and how do they relate to each other.
What happens with textselector on each check through the entire array?
Which states can it hold element by element?
If it holds this and that state then which color is supposed to be used?
Then translate your mother tongue to code. One baby step after baby step.

See here on understanding how AFL works also

Let’s first start with English language (my mother tongue is not English so expect bugs :-)):

If _rsi is above 70 then the formula’s result is
Textselector -> (1 * true + 2 * false).

(True is equal to 1 while false is equal to 0.)
Textselector -> (1 * 1 + 2 * 0).
Result -> 1.

Next what if _rsi is below 30? Easy!
Textselector -> (1 * false + 2 * true).
Result -> 2.

What if _rsi is neutral?
Well, easy again!
Textselector -> (1 * false + 2 * false);
Result -> 0.

So by applying simple logic using our one…two… brain cells we have found out that there could occur three states returning three different values -> 0, 1, 2.

Since those values are part of an array you have to check for occurrence via array function too.
So in order to check for different states we use array function IIf()
In this case we apply nested Iif().

bgcolor = IIf( Textselector == 0, ....,
               IIf( Textselector == 1, ....,
                    IIf( ..., ..., .... ) ) );

Is it more clear to you now? Still problems? Where?


Well, it is recommended using existing array function but I can show you that you may use looping code as well. Maybe you do understand better then.

// This is only a DEMO code snippet showing a different approach other than applying IIf() array function
// Don't use it! Use IIf() instead! 
/// @link

bir = Status( "BarInRange" ); // check for Analysis bar range status. Variable type: array
cellcolor = -1;  // -1 is equal to colorDefault   
// iterating from 0 to Barcount-1    
for( i = 0; i < BarCount; i++ ) {

	if( bir[i] ) { // if being within set Analysis bar range

		// check TextSelector state
		switch( TextSelector[i] ) { 
			case 0: cellcolor[i] = colorDarkBlue; break; // if TextSelector == 0 -> RSI "neutral" color
			case 1: cellcolor[i] = colorDarkGreen; break; // if TextSelector == 1 -> RSI "overbought" color
			case 2: cellcolor[i] = colorDarkRed; break; // if TextSelector == 2 -> RSI "oversold" color
			default: cellcolor[i] = -1; break; // else use colorDefault



Hello! thank you very much for the support, English is not my native language, sorry if I do not write well (that too I am difficult to understand AFL instructions) until now I have had time to answer.

I already made it clearer with your explanation, as I should indicate in the function AddMultiTextColumn() bkcolor = ???

bkcolor = IIf( Textselector == 0, colorBlue,
               IIf( Textselector == 1, colorGreen,
                    IIf( Textselector == 2, colorRed, colorDefault) ) );
AddMultiTextColumn( TextSelector, TextList,"Estatus",format = 1.2, fgcolor = colorDefault , bkcolor = colorDefault  width = -1 );

Thank you

In your code you are reassigning a different (constant) color (-> colorDefault) to bkcolor variable in AddMultiTextColumn line. Don’t do that if you want to use previously defined bkcolor variable (the one using IIf() function) in AddMultiTextColumn.

So since you want to have a variable cell color correct (example!) line would be:

AddMultiTextColumn( TextSelector, TextList,"Estatus", format = 1.2, fgcolor = colorDefault, bkcolor, width = -1 ); 

In case you want to have a different font color then you have to replace colorDefault of fgcolor also.

BTW, please read here before posting


Finally, I got it, thanks a lots! :blush:

How did you get the dark background in your report?

All you need to do is studying these three sample links: (see field “NoDefaultColumns” ) (see font and cell color arguments) (see font and cell color arguments)

1 Like

There should be possibility to change grid color.

Grid color is provided by the system (OS)

I know this is an old thread but I found it while trying to add the AddMultiTextColumn function to some code.

@fxshrat provided two links and noted the instructions on how to use the TextList parameter was different. The 6.19.0 beta read me says the input should be separated using the new line "\n" symbol and has the following example,

TextList = "No signal\nBuy\nSell\nBuy and Sell";
TextSelector = 1 * Buy + 2 * Sell; /* would give 0 if no signal, 1 if a buy, 2 if a sell, 3 if both buy and sell */
AddMultiTextColumn( TextSelector, TextList, "Which signal" );

while the AFL guide says it should be a space " " symbol and has the following example

TextList = "No signal Buy Sell Buy and Sell";

I started using a space " " as per the AFL guide then started searching and found this thread when my code didn't work. @Tomasz assuming the guide is wrong can it be updated so the next person using the AddMultiTextColumn function doesn't have the same problem?

I'm probably going to use the AddColumn function instead because I want to display some non standard characters but that's a different problem.

The guide isn't wrong. It clearly says:

newline-separated list of texts to be displayed depending on ARRAY value.

It was simply annoying "feature" of php to remove backslashes. The \n characters are those newline separators that user guide talks about and they must be there and they were there until php removed them :frowning:
The generator script was updated to add those php auto-removed backslashes.