MQL4 Formula Interpretation

Back to topics list To post a new topic, please log in or register
avatar
19
Tony227 2015.12.08 21:17
 

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]

avatar
Moderator
3419
GumRai 2015.12.08 21:44 #
 
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;

 .

avatar
19
Tony227 2015.12.08 21:53 #
 
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.

avatar
13006
WHRoeder 2015.12.08 22:03 #
 
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;
    
avatar
19
Tony227 2015.12.08 22:31 #
 

 

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) 

avatar
19
Tony227 2015.12.08 22:32 #
 
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.
avatar
Moderator
3419
GumRai 2015.12.08 23:14 #
 
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
Back to topics list  

To add comments, please log in or register