if conditions not met, and order opens!!!

 

I am trying to create an EA, and encounter a problem where all if conditions are not satisfied and it still process the code to open the order.

//for Buy
if(emaT_Slowl > emaT_Slowestl)
{
  if((Close[2] > bb_MainLower2) && (Close[1] < bb_MainLower1))
    if(get_VolumeIndicator > 0)
      Alert("");
      newOrder_OnStrongTrend(0);
}
// for Sell
if(emaT_Slowl < emaT_Slowestl)
{
  if((Close[2] > bb_MainUpper2) && (Close[1] < bb_MainUpper1))
    if(get_VolumeIndicator < 0)
      Alert("");
      newOrder_OnStrongTrend(1);
}

my code and strategy tester report is attached where i have highlighted the problem area.

please help me to locate the real cause of problem.

Visualize a Strategy in the MetaTrader 5 Tester
Visualize a Strategy in the MetaTrader 5 Tester
  • www.mql5.com
We all know the saying "Better to see once than hear a hundred times". You can read various books about Paris or Venice, but based on the mental images you wouldn't have the same feelings as on the evening walk in these fabulous cities. The advantage of visualization can easily be projected on any aspect of our lives, including work in the...
Files:
Error_001a.jpg  570 kb
 
Please edit your post and copy and paste the actual code, don't post an image,
use the code button (Alt+S) when pasting code
 
Anil Varma:

I am trying to create an EA, and encounter a problem where all if conditions are not satisfied and it still process the code to open the order.

my code and test report is attached where i have highlighted the problem area.

please help me to locate the real cause of problem.

You cannot just put a list of statements after an IF and expect it to know they are a group, unless you actually group them

trust this helps

// only the first print statement belongs to the IF
// so if IF is false  statement 2 and 3 will still process

if( Val1 == Val2)
   Print("statement 1");
   Print("statement 2");
   Print("statement 3");

// all statements belong to the IF
if( Val1 == Val2)
{
   Print("statement 1");
   Print("statement 2");
   Print("statement 3");
}
 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. Paul Anscombe: You cannot just put a list of statements after an IF and expect it to know they are a group, unless you actually group them

    Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

  4. Your two if statements only apply to the Alert("");
 
William Roeder:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

  4. Your two if statements only apply to the Alert("");

who said they were doubles, clearly they are integers,

it was just an illustration....

 
I will move this topic to the MQL4 and Metatrader 4 section.

 
Keith Watford:
I will move this topic to the MQL4 and Metatrader 4 section.

Thanks Keith, I am still new to this forum and this was my first post. Will look to see how can I avoid this mistake in future.
 
Paul Anscombe:

You cannot just put a list of statements after an IF and expect it to know they are a group, unless you actually group them

trust this helps

Thanks for reply Paul. However, my script already have conditions in a group. below is the replica ...

if(emaT_Slow > emaT_Slowest)                          ... this condition was passed to true

{

if(Close[2] > BBMainLower2 && Close[1] < BBMainLower1)          ... first part of this was true where as second part was false, yet the order was placed

if(VolumeIndicator > 0 )                                                    ... in first order this was true, second order it was false, yet the order was placed

Alert Statements ...

} ... group of statement

 
Anil Varma:

I am trying to create an EA, and encounter a problem where all if conditions are not satisfied and it still process the code to open the order.

my code and strategy tester report is attached where i have highlighted the problem area.

please help me to locate the real cause of problem.

Nothing wrong with this code exept Alert part which is empty. Perhaps other part of code contains error(s). IMO.

 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. Irwan Adnan: Nothing wrong with this code exept Alert part which is empty. Perhaps other part of code contains error(s). IMO.
    if(Close[2] > BBMainLower2 && Close[1] < BBMainLower1) // ... first part of this was true where as second part was false, yet the order was placed
    if(VolumeIndicator > 0 )                               // ... in first order this was true, second order it was false, yet the order was placed
    
    Alert Statements ...
    Really? Only the first “Alert Statement” is connected to the if.
 
Anil Varma:

Thanks for reply Paul. However, my script already have conditions in a group. below is the replica ...


  No they are not all in groups as I stated before. You need to group the statements under each if  to clarify they belong to the if....


//for Buy
if(emaT_Slowl > emaT_Slowestl)
{
  if((Close[2] > bb_MainLower2) && (Close[1] < bb_MainLower1))
    if(get_VolumeIndicator > 0)
    {
      Alert("");
      newOrder_OnStrongTrend(0);
    }
}


Reason: