if(ordersell_1 == true) { double x = 123; } else { double x = 321; }
Ahmed Hussain:
if(ordersell_1 == true) { double x = 123; } else { double x = 321; }
It is no good declaring the variable inside the braces as it will not exist outside of the braces.
Thanks.
Ill try and figure it out from there.
Needs to exist outside the brackets, but you gave me a start.
-
if(ordersell_1 == true)
You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.
-
Declaration outside, assignment inside.
- Or:
double x = ordersell_1 ? 123 : 321; // Ternary
-
You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.
-
Declaration outside, assignment inside.
- Or:
Thanks William.
Makes absolute sense. Thanks for taking the time to explain. Much appreciated.
Kind regards.
![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
Good day all.
Is there someone that can assist me with a small piece of code. I know it is probably easy but I am new to mql4 and struggling.
I need a piece of code that does the following:
When a specific order, lets say "ordersell_1" is triggered, I need a "true" statement
when the specific order "ordersell_1" is not triggered, I need a "false" statement.
When it is "true" double x = 123
when it is "false" double x = 321
I know it is something to do with a bool.
Please help.