# MQL4 Formula Interpretation

To add comments, please log in or register
39

Hi there,

if(Close[1]>Open[1]&& Close[2]<Open[2]&& MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-close[2]&&Close[1]>Open[2]))BullishEngulfing = true;

else if (Close[1]<Open[1]&& Close[2]>Open[2]&& MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2]&&Close[1]<Open[2]))BearishEngulfing = true;

I wrote the above two lines by mistake when what I really meant to write was the following

if(Close[1]>Open[1]&& Close[2]<Open[2]&& MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2])&&Close[1]>Open[2])BullishEngulfing = true;

else if (Close[1]<Open[1]&& Close[2]>Open[2]&& MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2])&&Close[1]<Open[2])BearishEngulfing = true;

Strangely, the first two incorrect lines give me a better result than the correct ones on back testing!

Can someone tell me how MQL4 would interpret my incorrect lines please.

Put it simply, how do you think MQL4 would interpret the following incorrect formula:

MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2]&&Close[1]>Open[2])

which was meant to be written as:

MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2])&&Close[1]>Open[2]

Moderator
10614

Tony227:

Put it simply, how do you think MQL4 would interpret the following incorrect formula:

MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2]&&Close[1]>Open[2])

which was meant to be written as:

MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2])&&Close[1]>Open[2]

MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2]&&Close[1]>Open[2])

MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2])&&Close[1]>Open[2]

I don't see any difference between the 2 lines of code except the missing final ")" in the 2nd line

Please use the SRC button when posting code and it may help to present it in a more reader friendly style

eg.

if(Close[1]>Open[1] && Close[2]<Open[2] && MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-close[2] && Close[1]>Open[2]))
BullishEngulfing = true;
else
if (Close[1]<Open[1] && Close[2]>Open[2] && MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-Close[2] && Close[1]<Open[2]))
BearishEngulfing = true;

.

39

GumRai:

I don't see any difference between the 2 lines of code except the missing final ")" in the 2nd line

Please use the SRC button when posting code and it may help to present it in a more reader friendly style

eg.

.

Thanks for the response. It is not a missing bracket but the bracket in the wrong place. As a result it gives a warning on compiling and strangely a better result on back testing. Thanks for letting me know about the SRC button. Will use it next time.

Cheers.

16105

Tony227:

if(Close[1]>Open[1]&& Close[2]<Open[2]&& MathAbs(Open[1]-Close[1])>MathAbs(Open[2]-close[2]&&Close[1]>Open[2]))BullishEngulfing = true;

1. Are you resetting the boolean variables to false.
2.  make your conditions readable. bool isUp     = Close[1] > Open[1]; bool wasDown  = Close[2] < Open[2]; bool isLarger = MathAbs(Open[1]-Close[1]) > MathAbs(Open[2]-close[2]); bool isMoving = Close[1]>Open[2]); BullishEngulfing =  isUp &&  wasDown && isLarger &&  isMoving; BearishEngulfing = !isUp && !wasDown && isLarger && !isMoving;
39

It is like writing

(a)   MathAbs(A-B)> MathAbs(C-D && E>F)

instead of

(b)      MathAbs(A-B) >MathAbs(C-D) && (E>F)

How would MQL4 interpret (a)

39

WHRoeder:
1. Are you resetting the boolean variables to false.
2.  make your conditions readable.
Yes, at the beginning of the function I make them both false.
Moderator
10614

Tony227:

Thanks for the response. It is not a missing bracket but the bracket in the wrong place. As a result it gives a warning on compiling and strangely a better result on back testing. Thanks for letting me know about the SRC button. Will use it next time.

Cheers.

Ah, I see it now, it also helps if you highlight the differences
To add comments, please log in or register