Help for Write custom block Mql Code: Condition + modify variables
-
Goodnight. I already apologize for my English. I'm using google translator. @fxDreema @miro1360
I would like to write in the block "CUSTOM MQL CODE" but I don't know anything about MQL5 programming.
I need to write code that checks for 1 condition. If the condition is true, change a variable. If it is false, skip to check the next condition.
I have 3 variables that will be checked. If the condition is true, the variable will be multiplied by a constant. If the condition is false, check the next variable.
Example:
If Variable1> 0, Variable1 = Variable1 * Constant, Pass
If Variable1 <= 0, PassIf Variable2> 0, Variable2 = Variable2 * Constant, Pass
If Variable2 <= 0, PassIf Variable3> 0, Variable3 = Variable3 * Constant, Pass
If Variable3 <= 0, Pass -
@bocadeangu connect the blocks as in the picture

-
@miki Thanks for commenting. With blocks, I know how to make logic.
But I would like to write in MQL5 code because I have to make these comparisons with 132 variables.
I made the example with blocks just to serve as a reference about what I want to write in the "CUSTOM MQL Code" block.
-
@bocadeangu not knowing your project and what you actually you have to do, the only thing that i can say you in custom block you can write so:
if (Variable1> 0) { Variable1= Variable1 * Constant ; Pass=true ; }
else if (Variable2> 0) {Variable2= Variable2 * Constant ; Pass=true}
and so on... but remember that all these variables sooner or later must be reset. -
@miki I managed to pass the block with writing as follows:
if (Variable1> 0) {Variable1 = Variable1 * Constant;}
else if (Variable1 <= 0) {Variable1 = Variable1;}if (Variable2> 0) {Variable2 = Variable2 * Constant;}
else if (Variable2 <= 0) {Variable2 = Variable2;} -
@miki Thanks a lot for the help.
In what I need to program, I don't need to confirm that the condition is false. If it is not true, you can move on to the next comparison.
If I write the way below is there a problem ???
if (Variable1> 0) {Variable1 = Variable1 * Constant;}
if (Variable2> 0) {Variable2 = Variable2 * Constant;}
if (Variable3> 0) {Variable3 = Variable3 * Constant;}
if (Variable4> 0) {Variable4 = Variable4 * Constant;} -
@bocadeangu said in Help for Write custom block Mql Code: Condition + modify variables:
@miki Thanks a lot for the help.
In what I need to program, I don't need to confirm that the condition is false. If it is not true, you can move on to the next comparison.
If I write the way below is there a problem ???
if (Variable1> 0) {Variable1 = Variable1 * Constant;}
if (Variable2> 0) {Variable2 = Variable2 * Constant;}
if (Variable3> 0) {Variable3 = Variable3 * Constant;}
if (Variable4> 0) {Variable4 = Variable4 * Constant;}If you use only "if" all variables are checked, if you use "else if" the next variable is checked if the previous is not true. However it would be faster to create an array and loop with a "for" but it would be difficult to explain