fxDreema

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

    Zero divide on restart due to LotStep being changed to zero . .

    Bug Reports
    4
    17
    2314
    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.
    • M
      Mantadiver last edited by

      Hello,

      I had a similar issue 3 years ago but unable to solve on a new EA.

      If EA has a live trade and MT4 restarts for whatever reason it throws a Zero Divide due to "LotStep" being set to "0" on restart.

      a) It doesn't happen if there is no trade.
      b) Manual solution I have found is to add "if(LotStep == 0) LotStep = 0.01;" (my broker step) within the "AlignLots" function manually.

      Question: Any ideas why this is happening and is there a way for me to add a custom block to insert the fix automatically or would it be possible for you to add this line into the system code please because it does seem like a bug.

      Many thanks

      MantaDiver

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

        @mantadiver If LotStep is your variable, (MarketInfo(Symbol(),MODE_LOTSTEP)); as code input in a modify variables block will ensure this value will be in variable and change for each broker.

        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
        • M
          Mantadiver last edited by

          @JSTAP LotStep is created as part of the "System and Custom functions used in the program" area of the standard code. I have tried recreating / writing to / overwriting but I just get errors.

          This is where it first appears:

          double AlignLots(string symbol, double lots, double lowerlots = 0.0, double upperlots = 0.0)
          {
          double LotStep = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
          ...........

          Populates fine on initial startup but changes to a zero value on restart with a live trade.

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

            @mantadiver Is this MT5? Code can be different, although most code can be used in FX via custom code I often find it works better only single lines are uses to compliment other blocks. Put a shared link on here with an explanation of what you are trying to achieve and, I'll have a look and see what can be done.

            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
            • M
              Mantadiver last edited by

              @JSTAP It is MT4 code.

              The reality is I am trying to cover off a situation that is unlikely to occur . . . i.e. Server / MT4 / EA restarts when the EA has a live trade and the EA fails to start due to Zero Divide ewrror and leaves an orphaned trade.

              I have had the same issue with a prior EA build with fxDreema and I would be interested to know if anyone else gets the error when they restart an EA with a trade running.

              Maybe I have done something that has a knock on effect.

              Anyway, given that I have noticed the issue I thought it prudent to put in a fix. My logic says that as it is proven that the system variable LotStep works on startup but changes to zero on restart that either fxdreema might provide a "bug fix" to prevent it happening or someone might offer a fix I can apply.

              From my attemps so far I ahve been unable to interact with and change the value of LotStep.

              Appreciate your time and interest, but at the end of the day it may never happen in live trading !

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

                @mantadiver is double LotStep a variable in FX that you can change? If is put value in a comment and see how you can get it to change.

                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
                • M
                  Mantadiver last edited by

                  I haven't managed to change it. Whenever I reference it I get "LotStep' - undeclared identifier".

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

                    @mantadiver I have tested this code, (MarketInfo(Symbol(),MODE_LOTSTEP)); if I have this in a modify variables block then it throws no error and in a comment block it has the lot step value. Put a shared link on here and what is happening can be assessed, are you sure you have a variable created in FX with the correct name/type? These errors are normally something simple to fix.

                    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
                    • M
                      Mantadiver last edited by Mantadiver

                      Working on it

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

                        1. It all works fine on TIME charts but not on OFFLINE charts. I am using Ovo charts but same issue exists when using the MT4 standard PeriodConverter.

                        2. There are actually two issues involved:-

                        a) LotStep returns zero after mt4 retart when using offline chart and there is an existing trade.

                        b) EA returns a zero divide error on restart (again offline chart & existing trade) in the fxdreema system code AlignLots.

                        I have discovered the reason for the zero divide. On restart I am using the "If Trade" block to detect if there is already a trade with the EA magic number. From what I can tell the "If Trade" block does not detect trades on restart on offline charts. I have tried various blocks and methods but none seem to work.

                        This is a simple project as an example:-

                        It prints the LotStep, Magic Nuymber and trade status to a comment.

                        Simple rule: If no trade then Buy.

                        If the EA is run, no trade is detetcted so it Buys. Restart MT4 and on restart the LotStep returns zero, it still says there is no trade, (even though there is) and in the Experts tab there is a zero divide error relating to LotStep in the AlignLots line [size=MathRound(size/LotStep)*LotStep;]

                        Therefore my take is that the zero divide is caused by the EA trying to take another trade & being met with LotStep zero BUT it should not be trying to take another trade because the "If Trade" should have detected a trade is already present.

                        The solution therefore is to find a way to get fxdreema to detect existing trades on restart when usiung offline charts . . . .

                        https://fxdreema.com/shared/Ckn8OX8wb

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

                          @mantadiver The problem is likely because you used text value, instead of text(code input) value.

                          0_1633782343893_64f929ac-fe5b-4533-bdaf-b1e7f8b58193-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! 😊

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

                            That's weird, when I click on it, it says Numeric.

                            0_1633824976709_b9d97236-d371-4b0a-a816-feef3ac6a15f-image.png

                            Anyway it was only getting the data to display, the issue remains.

                            Are you able to get fxdreema to recognise existing trades from offline charts ?

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

                              @mantadiver The problem is your variable is in as a double not string, do like this and all will work.

                              0_1633865509259_ad216f12-10ea-4c47-b64d-8ebb421af467-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! 😊

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

                                OK, I think I have solved it.

                                The problems being experienced were effects not the cause.

                                The cause is all down to the code running at startup on offline charts BEFORE it has had a chance to read data from the broker.

                                Therefore it was returning no trades when therre were trades and LotStep returned as zero which led to it trying to take another trade which in turn led to a zero divide error.

                                The solution I have used is to add a 3 second delay & change a flag to "true" at the end of initialisation and then check that the flag is "true" when executing code in the On Tick tab.

                                Maybe offline charts need to wait for an additional tick or something but this definitely allows it to report the active trades correctly, reports LotStep correctly and prevents the zero divide.

                                Many thanks for your interest and help @jstap.

                                jstap T 2 Replies Last reply Reply Quote 0
                                • jstap
                                  jstap @Mantadiver last edited by jstap

                                  @mantadiver I'm glad you sorted it, the problem was in the variable being the wrong type, LotStep is a broker number, doesn't rely on an open trade .

                                  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
                                  • T
                                    Tulefi @Mantadiver last edited by

                                    @mantadiver I am fairly new to this but we are having issues with zero divide errors. Please see attached. Is your solution related to this?0_1635504005335_Screen Shot 2021-10-29 at 10.39.57 am.png .
                                    The line of code is to do withe money management where we are calculating lot size related to account balance and SL.
                                    Any help woould be much appreciated.

                                    l'andorrà 1 Reply Last reply Reply Quote 0
                                    • l'andorrà
                                      l'andorrà @Tulefi last edited by

                                      @tulefi Sharing the link to your project would help to review it in depth, is possible.

                                      (English) I will try to help everyone in these fxDreema forums. But if you want to learn how to use the platform in depth or more quickly, I can help you with my introductory fxDreema course in English at https://www.theandorraninvestor.eu.

                                      (Català) Miraré d’ajudar tothom en aquests fòrums d’fxDreema. Tanmateix, si vols aprendre a fer servir la plataforma amb més profunditat o més de pressa, t’hi puc ajudar amb el meu curs d’introducció a fxDeema en català a https://www.theandorraninvestor.eu/ca.

                                      (Español) Intentaré ayudar a todo el mundo en estos foros de fxDreema. Sin embargo, si quieres aprender a usar la plataforma en profundidad o más deprisa, te puedo ayudar con mi curso de introducción a fxDreema en español en https://www.theandorraninvestor.eu/es.

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

                                      Online Users

                                      J
                                      T
                                      J
                                      B
                                      A
                                      T
                                      M

                                      21
                                      Online

                                      146.7k
                                      Users

                                      22.4k
                                      Topics

                                      122.6k
                                      Posts

                                      Powered by NodeBB Forums | Contributors