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"); }
-
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. -
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 - 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 - Your two if statements only apply to the Alert("");
-
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. -
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 -
Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum #2 2013.06.07 - Your two if statements only apply to the Alert("");
who said they were doubles, clearly they are integers,
it was just an illustration....
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
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.
-
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 - Irwan Adnan: Nothing wrong with this code exept Alert part which is empty. Perhaps other part of code contains error(s). IMO.Really? Only the first “Alert Statement” is connected to the if.
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 ...
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); } }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.