Follow the specific value if the condition meet

Hi
When u see the below picture, if the Condition1 equals to "1" and Condition3 equals to "1", I want to make that the other values which have Condition == 1 also change the Condition 3 value "0" to "1".

Please consider below picture and let me know how to do.

Thank you

Question

Hi @Harry1

You need to use iif() function
https://www.amibroker.com/guide/afl/iif.html

Below some examples
https://forum.amibroker.com/tag/iif

1 Like

I don't know what you have in mind with Iif function but you do not need Iif .
AFAIU his post1 Condition1 and Condition3 both have to be TRUE at same bar before new condition becomes TRUE and when Condition1 is consecutively TRUE after initial event (-> Condition1 and Condition3 being TRUE).

x[0] = 0;
x[1] = 1;
x[2] = 1;
x[3] = 1;
x[4] = 1;
x[5] = 0;
x[6] = 0;

y[0] = 0;
y[1] = 1;
y[2] = 0;
y[3] = 0;
y[4] = 0;
y[5] = 0;
y[6] = 0;

condition1 = x;
condition3 = y;
combined_cond = condition1 AND condition3;

bars = BarsSince(condition3);
cond = combined_cond OR condition1 AND Sum(condition1, bars) == bars;

Filter = BarIndex() < 7;

AddColumn(condition1, "Condition1", 1);
AddColumn(condition3, "Condition3", 1);
AddColumn(cond, "Cond", 1);
AddColumn(Sum(condition1, bars), "cnt1", 1);
AddColumn(bars, "cnt2", 1);

14


Or if you do not want to include initial event into new condition

x[0] = 0;
x[1] = 1;
x[2] = 1;
x[3] = 1;
x[4] = 1;
x[5] = 0;
x[6] = 0;

y[0] = 0;
y[1] = 1;
y[2] = 0;
y[3] = 0;
y[4] = 0;
y[5] = 0;
y[6] = 0;

condition1 = x;
condition3 = y;
//combined_cond = condition1 AND condition3;

bars = BarsSince(condition3);
cond = /*combined_cond OR*/ condition1 AND Sum(condition1, bars) == bars;

Filter = BarIndex() < 7;

AddColumn(condition1, "Condition1", 1);
AddColumn(condition3, "Condition3", 1);
AddColumn(cond, "Cond", 1);
AddColumn(Sum(condition1, bars), "cnt1", 1);
AddColumn(bars, "cnt2", 1);

14

1 Like

Actually upper one can be written shorter by simply adding +1 to BarsSince(). :roll_eyes:

// ....

condition1 = x;
condition3 = y;

bars = BarsSince(condition3)+1;
cond = condition1 AND Sum(condition1, bars) == bars;

// ....

14

1 Like

It works thank u so much. It is what I want to make