fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Help for Write custom block Mql Code: Condition + modify variables

    Questions & Answers
    2
    7
    1622
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      Bocadeangu last edited by Bocadeangu

      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, Pass

      If Variable2> 0, Variable2 = Variable2 * Constant, Pass
      If Variable2 <= 0, Pass

      If Variable3> 0, Variable3 = Variable3 * Constant, Pass
      If Variable3 <= 0, Pass

      https://fxdreema.com/shared/NkUHSeMUd

      M 1 Reply Last reply Reply Quote 0
      • M
        miki @Bocadeangu last edited by

        @bocadeangu connect the blocks as in the picture

        0_1618902714235_Immagine.png

        1 Reply Last reply Reply Quote 0
        • B
          Bocadeangu last edited by

          @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.

          M 1 Reply Last reply Reply Quote 0
          • M
            miki @Bocadeangu last edited by miki

            @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.

            1 Reply Last reply Reply Quote 0
            • B
              Bocadeangu last edited by

              @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;}

              1 Reply Last reply Reply Quote 0
              • B
                Bocadeangu last edited by

                @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;}

                M 1 Reply Last reply Reply Quote 0
                • M
                  miki @Bocadeangu last edited by

                  @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

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post

                  Online Users

                  A
                  R
                  E
                  M
                  M
                  U
                  S
                  9
                  S

                  16
                  Online

                  146.7k
                  Users

                  22.4k
                  Topics

                  122.6k
                  Posts

                  Powered by NodeBB Forums | Contributors