Download MetaTrader 5
To add comments, please log in or register
Track all payments in your profile. It is easy!
fly7680 2016.07.24 09:27 

I enter the condition in the candle 2 if Red or Green with I cover more than 0.2 pips

I have this error: check operator precedence for possible error; use parentheses to clarify precedenc

help me solve please?

&&(Open[2+i] < Close[2+i]  && MathAbs(Close[2+i]-Open[2+i]) > 0.2  * myPoint || Open[2+i] > Close[2+i]  && MathAbs(Open [2+i]-Close[2+i]) > 0.2  * myPoint)
Drazen Penic
Drazen Penic 2016.07.24 11:02  

This is not an error, but a warning that you are mixing "&&" and "||" in the same boolean expression.  

Although it may be what you want, there is a huge chance that you may have a bug in there. 

Your expression, as is, will be evaluated in this order:

bool b1 = Open[2+i] < Close[2+i]  && MathAbs(Close[2+i]-Open[2+i]) > 0.2  * myPoint;
bool b2 = b1  || Open[2+i] > Close[2+i];
bool b3 = b2  && MathAbs(Open [2+i]-Close[2+i]) > 0.2  * myPoint;


 You probably want it to be evaluated: "left side" || "right side".  If so, use parenthesis. If not, again, use parenthesis, to explain to the compiler what exactly you want.

 Also, you should consider chopping up this expression into meaningful pieces to make the code more readable.

bool bullishCandle = Open[2+i] < Close[2+i];
double candleBodySize  = MathAbs(Close[2+i]-Open[2+i]);
bool candleHighEnough  = candleBodySize > (0.2 * myPoint);

// which leads to expression:
bool result = (bullishCandle && candleHighEnough) || (!bullishCandle && candleHighEnough);

// which is equivalent to:
bool result = candleHighEnough && (bullishCandle || !bullishCandle);

// since "(bullishCandle || !bullishCandle)" is always true, above is equivalent to:
bool result = candleHighEnough;

fly7680 2016.07.24 19:26  
Thanks for helping me, I have integrated your code and it works perfectly.
To add comments, please log in or register