fxDreema

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

    Round the number / Remainder division

    Questions & Answers
    3
    13
    560
    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.
    • R
      ramin1768 last edited by

      Hi everyone,

      I've been trying to find information on two specific topics but couldn't locate any relevant blocks.

      Rounding a variable:
      I'm interested in rounding a number stored in a variable. Is it possible to achieve this using custom MQL code, or are there other ways to do it?

      Performing remainder division in custom MQL code:
      I have three variables named "First," "Second," and "result." I'm trying to find a way to calculate the remainder of the division between "First" and "Second" and store the result in the "result" variable. Could someone please guide me on how to write "First % Second" in "result"?

      Thank you so much for your help in advance!

      1 Reply Last reply Reply Quote 0
      • jstap
        jstap last edited by

        Yes it's possible something like this will put the result in to the variable, if (First>Second) {result=First-Second}
        else {result=Second-First;}

        This code will cut the number of 0.000 from the decimel, DoubleToString(variable,2);

        Learn fxDreema Without the Wait!

        My comprehensive book, available on Amazon, is packed with examples and invaluable insights to help you fast-track your learning journey.

        The paperback and hardback editions include MT4 & MT5 QR codes for easy access to all prebuilt projects and robots, including my latest gold trading robot!

        Don’t miss out

        Click here➡️ https://mybook.to/fxDreema to get your copy today!

        Enjoy! 😊

        P R 3 Replies Last reply Reply Quote 0
        • P
          Pheaktra Capo @jstap last edited by Pheaktra Capo

          @jstap add on brother jstap, i can share some example
          DoubleToString(AccountEquity(),2)

          This will round the result number into 2decimal. If you need 3 decimal, use DoubleToString(AccountEquity(),3)

          1 Reply Last reply Reply Quote 0
          • R
            ramin1768 @jstap last edited by

            @jstap said in Round the number / Remainder division:

            Yes it's possible something like this will put the result in to the variable, if (First>Second) {result=First-Second}
            else {result=Second-First;}

            This code will cut the number of 0.000 from the decimel, DoubleToString(variable,2);

            Would you please check below project regarding remainder of division between 2 variables. I copied the code in "custom mql code" block but it didn't work.
            Also I guess the code passes first minus second & vice versa but I need remainder of division between 2 variables. Example: remainder of division between 10 & 4 is 2.
            https://fxdreema.com/shared/PwUgOSQlb

            1 Reply Last reply Reply Quote 0
            • R
              ramin1768 @jstap last edited by

              @jstap said in Round the number / Remainder division:

              This code will cut the number of 0.000 from the decimel, DoubleToString(variable,2);

              @Pheaktra-Capo said in Round the number / Remainder division:

              @jstap add on brother jstap, i can share some example
              DoubleToString(AccountEquity(),2)
              This will round the result number into 2decimal. If you need 3 decimal, use DoubleToString(AccountEquity(),3)

              Also this code doesn't work when I add it to "custom mql code" block.
              could you check below project & guide me what is the mistake:
              https://fxdreema.com/shared/4AcP0ko3b

              1 Reply Last reply Reply Quote 0
              • jstap
                jstap last edited by

                You just need to add the semi colon:
                image.png

                Learn fxDreema Without the Wait!

                My comprehensive book, available on Amazon, is packed with examples and invaluable insights to help you fast-track your learning journey.

                The paperback and hardback editions include MT4 & MT5 QR codes for easy access to all prebuilt projects and robots, including my latest gold trading robot!

                Don’t miss out

                Click here➡️ https://mybook.to/fxDreema to get your copy today!

                Enjoy! 😊

                R 1 Reply Last reply Reply Quote 1
                • R
                  ramin1768 @jstap last edited by

                  @jstap said in Round the number / Remainder division:

                  You just need to add the semi colon:
                  image.png

                  Thanks a lot. another problem is the result of variable "numbers" through the comment block is the same as before & not affected by custom mql code.
                  How can I replace the result of DoubleToString(numbers,2); to "numbers" variable?

                  1 Reply Last reply Reply Quote 0
                  • jstap
                    jstap last edited by

                    How do you mean?

                    Learn fxDreema Without the Wait!

                    My comprehensive book, available on Amazon, is packed with examples and invaluable insights to help you fast-track your learning journey.

                    The paperback and hardback editions include MT4 & MT5 QR codes for easy access to all prebuilt projects and robots, including my latest gold trading robot!

                    Don’t miss out

                    Click here➡️ https://mybook.to/fxDreema to get your copy today!

                    Enjoy! 😊

                    1 Reply Last reply Reply Quote 0
                    • P
                      Pheaktra Capo last edited by

                      image.png

                      1 Reply Last reply Reply Quote 0
                      • P
                        Pheaktra Capo last edited by

                        This is how it work

                        1 Reply Last reply Reply Quote 0
                        • P
                          Pheaktra Capo last edited by

                          No need Custom MQL block. Use Pass block instead of Custom MQL block. Put the DoubleToString in Text(code input)

                          R 1 Reply Last reply Reply Quote 0
                          • R
                            ramin1768 @Pheaktra Capo last edited by

                            @Pheaktra-Capo Thank you. It solved my problem.

                            1 Reply Last reply Reply Quote 0
                            • R
                              ramin1768 last edited by

                              Final results are:
                              1-For rounding a variable:
                              Use code : DoubleToString(variable,2);
                              2- For finding remainder division
                              Use code: MathMod(variable1,variable2);

                              For using codes in block: Use "Value" & "Text(code input)"

                              Thanks everyone for helping me.

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

                              Online Users

                              B
                              A
                              J
                              D
                              E

                              15
                              Online

                              146.7k
                              Users

                              22.4k
                              Topics

                              122.6k
                              Posts

                              Powered by NodeBB Forums | Contributors