Download MetaTrader 5

Isssue with conditional test

To add comments, please log in or register
Mo
65
Mo  
Hi all,


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

Buy logical:

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) {

buysig=true;

}

The first two work fine, and also the below:

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


btrend=1;

}

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

buysig=true;

}
Mo
65
Mo  
bband value is 20,2
Ian Venner
2584
Ian Venner  
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 ?
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
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.
Mo
65
Mo  

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.





Keith Watford
Moderator
10363
Keith Watford  
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.

Ian Venner
2584
Ian Venner  
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...

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
Yup, there is homework to be done first.
Mo
65
Mo  
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) {

buysig=true;

}
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.
Ian Venner
2584
Ian Venner  

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.

Mo
65
Mo  
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) {

buysig=true;

}
12
To add comments, please log in or register