# Probability of 8 conditions

Hi all

If I have two textlist with two TextSelector , how to combine them ?

``````TextList_above0 = " N\nAB2\nAB4\nAB24\nAB6\nAB26\nAB46\nAB246\nABMAX\nAB2MAX\nAB4MAX\nAB24MAX\nAB6MAX\nAB26MAX\nAB46MAX\nAB246MAX";
TextSelector_above0 = 1 * above_A1 +  2 * above_A2 + 4 * above0_A3 + 8 * above0_A4 ;
TextList_below0 = " N\nBE2\nAB4\nBE24\nAB6\nBE26\nBE46\nBE246\nBEMAX\nBE2MAX\nBE4MAX\nBE24MAX\nBE6MAX\nBE26MAX\nBE46MAX\nBE246MAX";
TextSelector_below0 = 1 * below_A1 +  2 * below_A2 + 4 * below_A3 + 8 * below_A4 ;

TextList_comb =   ; // how to combine TextList_above0 and TextList_below0
TextSelector_comb =   ; // how to combine TextSelector_above0 and TextSelector_below0
``````

there is another way .
as fxshart did

Returning Non Null values of a vector

but can not get more then 5 conditions because the limitation of printif function

and this the code that create by fxshart

``````// this code was create by fxchart from AmiBroker Community Forum  link ( https://forum.amibroker.com/t/returning-non-null-values-of-a-vector/2036/15 )
EnableTextOutput(0) ;

condstr = " AB1 , AB2 ,AB3 , AB4 ,AB5 , AB6 ,AB7 , AB8   " ;

conditions = StrCount(condstr, "," ) +1 ; // number of conditions

sumvar = 0 ;
sep = " & " ; // cond separator
textlist = "" ;
for ( i = 0 ; i < 2^conditions ; i++ ) { // 2^number of conditions
for (n=0 ; n < conditions ; n++ ) { // conditions
var = i & 2^n ;
textlist += WriteIf( var > 0 , StrExtract( condstr, n) , "F" ) + sep ;
if(n == conditions - 1) {
textlist = StrTrim ( textlist , sep ) + "\n" ;

}
}
}

printf( textlist ) ;
``````

Is it possible to send the result to text file ?

thank you all

this what I did
I copy some of the expert code here and I think it is working

``````// create folder for exporting purposes

// open file for writing
// file name depends on currently processed ticker
fh = fopen( "C:\\Users\\Administrator\\Documents\\Probability.txt", "w" );

//fh = fopen( filepath, "a", True );

if ( fh )
{

EnableTextOutput(0) ;

condstr = " AB1 , AB2 ,AB3 , AB4 ,AB5 , AB6 ,AB7 , AB8   " ;

conditions = StrCount(condstr, "," ) +1 ; // number of conditions

sumvar = 0 ;
sep = " & " ; // cond separator
textlist = "" ;
for ( i = 0 ; i < 2^conditions ; i++ ) { // 2^number of conditions
for (n=0 ; n < conditions ; n++ ) { // conditions
var = i & 2^n ;
textlist += WriteIf( var > 0 , StrExtract( condstr, n) , "F" ) + sep ;
if(n == conditions - 1) {
textlist = StrTrim ( textlist , sep ) + "\n" ;

}
}
}

fputs( textlist, fh );
fclose( fh );
}
``````

is it right ?
just to confirm it

thank you

I have result of 256 Probability from 8 conditions

``````TextList_above0 = " N\nAB2\nAB4\nAB24\nAB6\nAB26\nAB46\nAB246\nABMAX\nAB2MAX\nAB4MAX\nAB24MAX\nAB6MAX\nAB26MAX\nAB46MAX\nAB246MAX";
TextSelector_above0 = 1 * above_A1 +  2 * above_A2 + 4 * above_A3 + 8 * above_A4 ;
TextList_below0 = " N\nBE2\nAB4\nBE24\nAB6\nBE26\nBE46\nBE246\nBEMAX\nBE2MAX\nBE4MAX\nBE24MAX\nBE6MAX\nBE26MAX\nBE46MAX\nBE246MAX";
TextSelector_below0 = 1 * below_A1 +  2 * below_A2 + 4 * below_A3 + 8 * below_A4 ;

TextList_comb = " N\nAB2\nAB4\nAB24\nAB6\nAB26\nAB46\nAB246\nABMAX\nAB2MAX\nAB4MAX\nAB24MAX\nAB6MAX\nAB26MAX\nAB46MAX\nAB246MAX\nBE2\nBE2\nBE2"+
" \nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE40\nBE40\nBE40\nBE40\nBE40 "+
"\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE240 \nBE240\nBE240\nBE240\nBE240\nBE240\nBE240 "+
" \nBE240\nBE240\nBE240\nBE240\nBE240\nBE240\nBE240\nBE240\nBE240\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60 "+
" \nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260 "+
" \nBE260\nBE260\nBE260\nBE260\nBE260\nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060\nBE4060 \nBE4060 \nBE4060  "+
" \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060 "+
" \nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX "+
" \nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX "+
" \nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX "+
" \nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX "+
" \nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX "+
" \nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE260MAX\nBE260MAX\nBE260MAX "+
" \nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE4060MAX "+
" \nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX "+
" \nBE4060MAX\nBE4060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX "+
" \nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX";
TextSelector_comb     =  1 * above_A1 +  2 * above_A2 + 4 * above_A3 + 8 * above_A4 + 16 * below_A1 +  32 * below_A2 + 64 * below_A3 + 128 * below_A4 ;

``````

and it is not the right way it is very hard

I tried to use what was written in the link below but I could not
https://www.amibroker.org/userkb/2011/04/22/using-iif-if-and-switch-functions/
I tried to use switch and if functions

thank you

Why don’t you just use AddRow function. It is just simpler.

I try to using

``````TextList = "\n";
TextSelector = 0 ;
for( i = 0; i <= 128; i++) {
switch( i ) {
case 1:

TextList += TextList_above0;
TextSelector +=  TextSelector_above0  ;
break;
case 2:

TextList += TextList_below0;
TextSelector +=  TextSelector_below0  ;
break;

default: break;
}
TextList += "\n";
TextSelector += 0 ;
}
``````

not working as I need it to be

I will check it and try it

thank you

using case based on as example

if macd >=0 then

``````TextList_above0 = " N\nAB2\nAB4\nAB24\nAB6\nAB26\nAB46\nAB246\nABMAX\nAB2MAX\nAB4MAX\nAB24MAX\nAB6MAX\nAB26MAX\nAB46MAX\nAB246MAX";
TextSelector_above0 = 1 * above_A1 +  2 * above_A2 + 4 * above_A3 + 8 * above_A4 ;
``````

if macd <= 0 then

``````TextList_below0 = " N\nBE2\nAB4\nBE24\nAB6\nBE26\nBE46\nBE246\nBEMAX\nBE2MAX\nBE4MAX\nBE24MAX\nBE6MAX\nBE26MAX\nBE46MAX\nBE246MAX";
TextSelector_below0 = 1 * below_A1 +  2 * below_A2 + 4 * below_A3 + 8 * below_A4 ;
``````

both when macd >= 0 or macd<=0 ( both of them will be 8 conditions ) that = 256

``````TextList_comb = " N\nAB2\nAB4\nAB24\nAB6\nAB26\nAB46\nAB246\nABMAX\nAB2MAX\nAB4MAX\nAB24MAX\nAB6MAX\nAB26MAX\nAB46MAX\nAB246MAX\nBE2\nBE2\nBE2"+
" \nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE2\nBE40\nBE40\nBE40\nBE40\nBE40 "+
"\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE40\nBE240 \nBE240\nBE240\nBE240\nBE240\nBE240\nBE240 "+
" \nBE240\nBE240\nBE240\nBE240\nBE240\nBE240\nBE240\nBE240\nBE240\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60 "+
" \nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE60\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260\nBE260 "+
" \nBE260\nBE260\nBE260\nBE260\nBE260\nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060\nBE4060 \nBE4060 \nBE4060  "+
" \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE4060 \nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060 "+
" \nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBE24060\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX "+
" \nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBEMAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX "+
" \nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE2MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX "+
" \nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE40MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX "+
" \nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE240MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX "+
" \nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE60MAX\nBE260MAX\nBE260MAX\nBE260MAX "+
" \nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE260MAX\nBE4060MAX "+
" \nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX\nBE4060MAX "+
" \nBE4060MAX\nBE4060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX "+
" \nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX\nBE24060MAX";
TextSelector_comb     =  1 * above_A1 +  2 * above_A2 + 4 * above_A3 + 8 * above_A4 + 16 * below_A1 +  32 * below_A2 + 64 * below_A3 + 128 * below_A4 ;
``````
``````AddMultiTextColumn(  TextSelector_comb, TextList_comb  , "  both above0   ",1.2 );
AddMultiTextColumn(  TextSelector_above0, TextList_above0 , "    above0    ",1.2 );
AddMultiTextColumn(  TextList_below0, TextList_below0 , "    below0    ",1.2 ) ;

``````

what I meant is stand of using TextList_comb ( that = 256 combination )

I am trying to put TextList_above0 ( that = 8 combination ) and TextList_below0 ( that = 8 combination ) in one ( AddMultiTextColumn )

if I use iff function i will get error and if i use WriteIf function it will return single line

I tried switch function with for but it give me missed result

what i need is to combines both TextList_above0 ( that = 8 combination ) and TextList_below0 ( that = 8 combination )

i wish I clear what I need

thank you

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