# Isssue with conditional test

65

Hi all,

Rudimentary issue for a rudimentary programmer.. Trying to take buy and sell signals off series of bbands forming in a zigzag fashion.

bband breaks down, bband breaks up, bband breaks down, final take a buy at the 2 bband break to the upside.

(switch order for sell signal)

I can't get this to work, all 4 conditions:

```if (bb_b3<0 && bb_b3>0 && bb_b3<0 && bb_b3>0) {

btrend=1;

}

if (btrend>0) {

}```

The first two work fine, and also the below:

```if (bb_b3<0 && bb_b3>0) {

btrend=1;

}

if (btrend>0 && bb_b3<0) {

}```
65

bband value is 20,2
2584

`if (bb_b3<0 && bb_b3>0 && bb_b3<0 && bb_b3>0) `
How could bb_b3 be less than zero and bigger than zero at the same time and what is the point of having that same condition twice ?
1401

```Buy logical:

bband breaks down, bband breaks up, bband breaks down, final take a buy at the 2 bband break to the upside.```
Must be common mistake in logical conditions.
65

Logical is sound, I thing syntax is wrong. As stated before the conditions work fine with two or there conditions as coded above (2nd example).

Question is how do I get all four to work.

Moderator
10363

zzdream:

Logical is sound, I thing syntax is wrong. As stated before the conditions work fine with two or there conditions as coded above (2nd example).

Question is how do I get all four to work.

Logic is NOT sound.

Read SDC's post and this time actually pay attention to it.

2584

zzdream:

Logical is sound, I thing syntax is wrong. As stated before the conditions work fine with two or there conditions as coded above (2nd example).

Question is how do I get all four to work.

You have not read the basics of how MT4 and MQL4 works. Your conditions are all tested at the same time so the result of what you have coded is the same as saying,

IF my age is younger than 30 AND my age is older than 30...

1401

Yup, there is homework to be done first.
65

ok I understand this make no sense to an experienced 'eye' . I understand 'age is younger than 30 AND my age is older than 30...' is not clear. But doing the below evaluates true:

2 bband settting : bb_b3=20 bb_b4=10

```if (bb_b3>0 && bb_b4<0) {

btrend=1;

}

if (btrend>0 && bb_b4>0) {

}```
So in essence I am still saying ie 'age is younger than 30 AND my age is older than 30...' for bb_b4. Why is this the case ? The way the code is split? How would you guys split up the code for all 4 conditions to evaluate true ? Sorry for the ignorance... went over the mq4 doc for conditional tests + google search . Not getting this.
2584

You are now using two sepearate variables in your condition so to stay with the same analogy you are now saying if MY age is less than 30 and HIS age is more than 30. That obviously is a reasonable condition that could be true. You original condition was testing the same variable for two different states at the same time and could never be true.

65

Yes I understand why the first if condition is evaluating true, but why is the second condition also evaluating true? I am still referencing bb_b4 (same bband value).
```if (btrend>0 && bb_b4>0) {