Download MetaTrader 5
To add comments, please log in or register
Copy the deals of successful traders. Subscribe to signals!
treasure1949
39
treasure1949 2015.12.08 20: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]

Keith Watford
Moderator
7986
Keith Watford 2015.12.08 20: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;

 .

treasure1949
39
treasure1949 2015.12.08 20: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.

whroeder1
13641
whroeder1 2015.12.08 21: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;
    
treasure1949
39
treasure1949 2015.12.08 21: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) 

treasure1949
39
treasure1949 2015.12.08 21: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.
Keith Watford
Moderator
7986
Keith Watford 2015.12.08 22: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
/
To add comments, please log in or register