What is wrong with WriteIf in my code

it only show the "FALSE TEXT" in the exploration

RSI_IND=RSI(14);


testind = WriteIf(RSI_IND < 50,"Long", "Short");

       
       Filter=1;
    
  AddTextColumn(testind, "test", 1.0, colorDefault, colorDefault);

thank you

i try this code below for exploration with different condition using WriteIf

RSI_IND=RSI(14);

testind = WriteIf( RSI_IND < 25 AND (Ref(RSI_IND,-1) >25) ,"Long1" ,
        WriteIf( RSI_IND < 20 AND (Ref(RSI_IND,-1) >20 ) ,"Long2" ,
        WriteIf( RSI_IND < 20 AND (RSI_IND  > Ref(RSI_IND,-1) ," Long3" ,
        WriteIf (RSI_IND < 20 , "Long4" ," Short"))));
       
       Filter=1;
       AddColumn(RSI_IND,"rsi",1.2,colorDefault,colorDefault);
       AddTextColumn(testind, "test", 1.0, colorDefault, colorDefault,100);
  

thank you

For a single symbol, the value from AddTextColumn will be the same for every output row in an Exploration. You may be able to use AddMultiTextColumn instead.

RSI_IND=RSI(14);

s1=RSI_IND < 25 AND (Ref(RSI_IND,-1) >25);
s2= RSI_IND < 20 AND (Ref(RSI_IND,-1) >20 );
s3=  RSI_IND < 20 AND (RSI_IND  > Ref(RSI_IND,-1);
s4= RSI_IND < 20 ;
    

       TextList = "No signal\nLong1 yes\nLong2 yes2\nLong3 yes3\nLong4 yes4";
       TextSelector = 1 * s1 + 2 * s2 + 3 * s3 + 4 * s4; 
       Filter=1;
       
  AddMultiTextColumn(TextSelector, TextList  ,"test", 1.0, colorDefault, colorDefault,100);

as the AB (TextList = "No signal\nBuy\nSell\nBuy and Sell"; )

I add one more but not show in the exploration(4 * s4)

is (TextList ) limited to only 4 ?

thank you

No, the text list is not limited to 4 items. For testing purposes, I suggest you output s1, s2, s3, and s4 in your Exploration so that you can verify that s4 actually occurs.

Also, I don't think you've consider what happens when more than one condition is true at a time. For example if s3 and s4 are both true, then your text selector will have a value of 7.

As usual, you understand what i need and the answers are clear
Thanks

for more about Text List

Really reading the manual is REQUIRED before you do anything.

If you read the manual on WriteIf
https://www.amibroker.com/f?writeif

you would read this:

Please note that WriteIf returns just single string representing current SelectedValue of the EXPRESSION

1 Like

you are right
i read it many times but what can i say.

now i see the word ( current )

thank you

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