fxDreema

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

    Custom MQL Code MathRound

    Questions & Answers
    2
    9
    2324
    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.
    • E
      eklonsousa last edited by

      Hi guys!

      I need to partial close a trade, but I need to use the MathRound function to avoid "invalid volume" error.

      I'm trying something like this and it is not working: (yes, I'm newbie with MQL code)

      alt text

      I've also tried this:
      alt text

      I'm preety sure that is some sintax error.

      Could you please give some help?

      Thank you!

      1 Reply Last reply Reply Quote 0
      • M
        miro1360 last edited by

        try the code like:
        TP1 = NormalizeDouble(TP1, 2);

        Between trading and gambling is a very small gap, be careful.

        E 3 Replies Last reply Reply Quote 0
        • E
          eklonsousa @miro1360 last edited by

          @miro1360 Thanks, Miro! I will try!

          Just let me ask you one more thing: I have some instruments like XTIUSD in Ic Markets that have 0.50 as lot step.
          In case of a 1.50 open trade, the partial close tries to close 0.75 will give the error...will this function work also with this scenario?

          Thank you!

          1 Reply Last reply Reply Quote 0
          • E
            eklonsousa @miro1360 last edited by eklonsousa

            @miro1360 Hi, Miro!

            I think it is working now!

            alt text

            Thank you so much!

            1 Reply Last reply Reply Quote 0
            • E
              eklonsousa @miro1360 last edited by eklonsousa

              @miro1360 Hi Miro!

              It worked with 0.01 lot step instruments.

              How can I made it to work with 0.10 lot step?

              In this case, I've opened 1.50 trade and tried to close 50%. then :alt text

              1 Reply Last reply Reply Quote 0
              • M
                miro1360 last edited by

                for 0.1 format, do this:
                TP1 = NormalizeDouble(TP1, 1);

                Between trading and gambling is a very small gap, be careful.

                E 1 Reply Last reply Reply Quote 1
                • E
                  eklonsousa @miro1360 last edited by eklonsousa

                  @miro1360 Thank you, Miro! It worked for 0.10 lot step.

                  How can I detect the lot step for each instrument?

                  I'll run this EA in FX Pairs (0.01 lot stop) index (0.10 lot step) and also XTIUSD (0.50 lotstep)

                  I'm sure that there will be few Custom SQL Code blocks to split this management. But how can I detect the lot step and make it work automatically?

                  Or there is a way to detect error from "Journal" tab? In order to keep the block flow running and managing that

                  Thank you so much!

                  1 Reply Last reply Reply Quote 0
                  • M
                    miro1360 last edited by miro1360

                    https://docs.mql4.com/constants/environment_state/marketinfoconstants
                    create new variable lot_step, and use this custom code function:
                    lot_step = MarketInfo(Symbol(), MODE_LOTSTEP);

                    there are other lot values which can be achieved:
                    lot_min = MarketInfo(Symbol(), MODE_MINLOT);
                    lot_max = MarketInfo(Symbol(), MODE_MAXLOT);

                    you can get them all and create some custom math for your purposes

                    Between trading and gambling is a very small gap, be careful.

                    E 1 Reply Last reply Reply Quote 1
                    • E
                      eklonsousa @miro1360 last edited by

                      @miro1360 Thank you so much for all your support!

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

                      Online Users

                      S
                      O
                      K
                      M
                      M

                      18
                      Online

                      146.7k
                      Users

                      22.4k
                      Topics

                      122.6k
                      Posts

                      Powered by NodeBB Forums | Contributors