Returning Non Null values of a vector


Is there a way beside looping that non null values of a vector can be outputted as a string?


String output in Exploration (i.e. percent sign)
How can I fix a condition and vice versa


Thanks @fxshrat. How would you deal with a situation that you have more than three conditions (lets say 7)?


The same way you deal with three just with the difference that it is seven. What response do you expect? Simply start coding (it doesn’t hurt) and if you get stuck then get back. I’m not going to spoon feed since everything is comprehensibly laid out already. Simply follow the link and examples and adjust to your needs. Easy.


So the logic in the example in the manual:

TextList = "No signal\nBuy Sell\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" );

is self explanatory however if your text list is
TextList = “No signal\nBuy\nSell \nBuy and Sell”;
Then what would be your textselector algorithm (and you can extend the numbe rof conditions to seven?
By the way I have given this quite a bit thought, I don’t know if you have. No spoon feeding is required here.


Probably like this one:

TextSelector = 1 * Cond1 + 2 * Cond2 + 4 * Cond3 + 8 * Cond4 + 16 * Cond5 + 32 * Cond6 + 64 * Cond7; // etc.
/* would give 0 if no signal, 1 if Cond1, 2 if Cond2, 3 if Cond1 and Cond2, 4 if Cond3, 5 if Cond1 and Cond3, 6 if Cond2 and Cond3, 7 if Cond1 and Cond2 and Cond3, 8 if Cond4 ... */

For example take a look at AddToComposite flags numeration:


@Milosz Thanks for your reply. TextSeletor value should correspond with with the position of the string in TextList. The alogoritm that you suggested (the power of 2) needs to converted back to a number between 0 & 6 to be useful with TextList.


What kind of output do you want? Don’t be cryptic!

For seven conditions there multiple number of combinations possible.

Do you want to output text only if single condition is true???
If so then for example create loop like this.

/// @link
/// snippet for AddMultiTextColumn function
/// text output only if single condition of seven is true.
TextList = "";
for( i = 0; i <= 64; i++) {
	switch( i ) {
		case 1:		TextList += "1";	break;
		case 2:		TextList += "2";	break;
		case 4:		TextList += "4";	break;
		case 8:		TextList += "8";	break;
		case 16:	TextList += "16";	break;
		case 32:	TextList += "32";	break;
		case 64:	TextList += "64";	break;
		default: break;
	TextList += "\n";

Replace text within switch statement by your own text.


Why between 0 and 6 in case of 7 conditions? With just 2 conditions (Buy and Sell) the TextList variable contains 4 different messages:

TextList = "No signal\nBuy\nSell\nBuy and Sell";

With 3 conditions (Cond1, Cond2, Cond3) the TextList variable should contain 8 different messages:

TextList = "No signal\nCond1\nCond2\nCond1 and Cond2\nCond3\nCond1 and Cond3\nCond2 and Cond3\nCond1 and Cond2 and Cond3";

… so you can count how many variants there are with 7 conditions …


@Milosz, actually the number unique combinations is factorial, so it is more than 6. However is was trying to point out that the power of 2 algo needs to convert back to the position of the appropriate conditions in textlist.


Did you even bother to analyse my example (actually two examples) above? It looks like you didn’t. You don’t need to convert anything. The value of TextSelector variable (0-7 in case of 3 conditions) points to a unique text in the TextList variable (containing 8 different texts/combinations/variants - in a proper order ) - one unique text for each value. So what do you want to convert?



I seriously do not understand what it is that you do not understand about usage of AddMultiTextColumn.

TextList is a list being put into AddMultiTextColumn as 2nd argument. Type of TextList: string.

The length of TextList is defined by number of possible occurrences of TextSelector (1st argument of AddMultiTextColumn, type: array). TextList is zero-based. So zero is reserved for when TextSelector returns zero (-> no true -> first item of TextList chosen).

If you have conditions that may occur at same time then the number of condition combinations is 2^(number of conditions) (i.e. if 4 conditions then it is 2^4 = 16 combinations). So it is 16 texts separated by “\n” assigned to TextList (TextList is the variable you insert into AddMultiTextColumn as 2nd argument). If one of n-combinations of all conditions is true at bar position then the according substring of TextList is picked by AmiBroker automatically by checking output of TextSelector result (again, TextSelector is 1st argument of AddMultiTextColumn).

Here is my very last detailed try with example of FOUR conditions (there is also example in there where there are 4 conditions not occurring at same time). If it’s still not going to click afterwards then I can’t help further.

Now what does it mean for your case of 7 conditions… if you want to output all possible combinations (and all conditions may occur at same time) then you have to create a string containing 128 occurrences (2^7=128) -> TextList consisting of 128 substrings separated by “\n”.

And TextSelector being

TextSelector = 1 * Cond1 + 2 * Cond2 + 4 * Cond3 + 8 * Cond4 + 16 * Cond5 + 32 * Cond6 + 64 * Cond7;

On the other hand if all 7 conditions can not occur at same time (see 3rd example in upper picture) then you could just use 7+1 substrings only.

TextList = "No true\nC1 true\nC2 true\nC3 true\nC4 true\nC5 true\nC6 true\nC7 true";
TextSelector = 1 * Cond1 + 2 * Cond2 + 3 * Cond3 + 4 * Cond4 + 5 * Cond5 + 6 * Cond6 + 7 * Cond7;


@fxshrat, you made my point for me. In your example of 4 conditions the textlist becomes a list of 16 pieces of strings. As you mentioned with 7 conditions the textlist becomes a list of 128 pieces of strings. So it becomes laborious. So using power of 2 algo we can determine which conditions have fired. We can write the values in a matrix. I have already done all of that. The issue is how to by pass writing a long textlist. How can we cleverly write code to do the tedious job! Programming is a combination of knowledge & art (creativity). I think my only solution is a c++ dll.


@QuantTrader: In this entire thread, I cannot find a concrete example of what you’re trying to achieve. You began by asking:

Later the discussion turned to AddMultiTextColumn and 2^N combinations of N different conditions, etc., but I get the sense that this function may not be the best solution to your problem. You might get a more helpful response if you provided a small working example of sample input and the expected output. As @fxshrat asked earlier:


You are seriously asking how to create TextList programmatically if having a conditions string such as

condstr = "Cond1,Cond2,Cond3,Cond4";

Matrix? DLL? What for?

All you need is one nested loop and bitwise operator (and just AFL).

Here below is one simple solution created within few minutes (if having the proper knowledge,skills,creativity,…).

Basically you can insert any substring into condstr variable representing the output if according condition is true.

“F” in Interpretation window stands for “False” or “No true signal” or “No true condition” or “No farm” or … etc.
"&" is the separator between each condition state. So for example “F & F & F & F” means no true signal of four ones and gets output if TextSelector array variable returns 0 at bar position. “Cond1 & Cond2 & Cond3 & Cond4” would get output if TextSelector returns 16 at bar positions. “Old & MacDonald & had & a farm & E-I-E-I-O” would get output if TextSelector returns 32 for 5 set conditions at bar position. And so on…