fxDreema

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

    Divide by zero bug

    Bug Reports
    6
    11
    4637
    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
      runekeeper last edited by runekeeper

      EA works fine on live trading but I couldn't back test it. MT4 journal says :

      2017.06.14 18:19:03.285	2017.04.18 05:05:00  ZigZag Strategy v1 USDCHF,M30: zero divide in 'ZigZag Strategy v1.mq4' (3696,105)
      

      I peeked into the EA code and found this at exactly 3969'th row.

         else if (mode=="equityRisk")     {size=((value/100)*AccountEquity())/(sl*((TickValue/ticksize)*point)*PipValue(symbol));}
      

      This is from here:

      double DynamicLots(string mode="balance", double value=0, double sl=0, string align="align", double RJFR_initial_lots=0)
      {
         double size=0;
         string symbol=GetSymbol();
         double LotStep=MarketInfo(symbol,MODE_LOTSTEP);
         double LotSize=MarketInfo(symbol,MODE_LOTSIZE);
         double MinLots=MarketInfo(symbol,MODE_MINLOT);
         double MaxLots=MarketInfo(symbol,MODE_MAXLOT);
         double TickValue=MarketInfo(symbol,MODE_TICKVALUE);
         double point=MarketInfo(symbol,MODE_POINT);
         double ticksize=MarketInfo(symbol,MODE_TICKSIZE);
         double margin_required=MarketInfo(symbol,MODE_MARGINREQUIRED);
         
         if (mode=="fixed" || mode=="lots")     {size=value;}
         else if (mode=="block-equity")      {size=(value/100)*AccountEquity()/margin_required;}
         else if (mode=="block-balance")     {size=(value/100)*AccountBalance()/margin_required;}
         else if (mode=="block-freemargin")  {size=(value/100)*AccountFreeMargin()/margin_required;}
         else if (mode=="equity")      {size=(value/100)*AccountEquity()/(LotSize*TickValue);}
         else if (mode=="balance")     {size=(value/100)*AccountBalance()/(LotSize*TickValue);}
         else if (mode=="freemargin")  {size=(value/100)*AccountFreeMargin()/(LotSize*TickValue);}
         else if (mode=="equityRisk")     {size=((value/100)*AccountEquity())/(sl*((TickValue/ticksize)*point)*PipValue(symbol));}
         else if (mode=="balanceRisk")    {size=((value/100)*AccountBalance())/(sl*((TickValue/ticksize)*point)*PipValue(symbol));}
         else if (mode=="freemarginRisk") {size=((value/100)*AccountFreeMargin())/(sl*((TickValue/ticksize)*point)*PipValue(symbol));}
         else if (mode=="fixedRisk")   {size=(value)/(sl*((TickValue/ticksize)*point)*PipValue(symbol));}
      
         else if (mode=="fixedRatio" || mode=="RJFR")
      

      Apparently, "sl" is set to 0 and then used as denominator on equity risk, balancerisk, freemarginrisk, and fixedrisk.

      What is the fix for this? Should I put sl=0.0001 instead or what do I do? is this a fundamental flaw in the code? What should I do?

      EDIT:

      I turned off blocks and found that the error is coming from the BUY/SELL PENDING block. Kindly fix this asap.

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

        Hello. The solution to this error is here: http://fxdreema.com/forum/topic/4712/how-to-fix-critical-runtime-error-503-in-ontick-function/5

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

          With this particular option you must have some SL, because the lot size is calculated from SL. The bigger the SL, the lower the lot size. But with SL = 0 you can't calculate lot size... it should be infinity or something like that. Maybe you need some other MM.

          R 1 Reply Last reply Reply Quote 0
          • R
            runekeeper @fxDreema last edited by

            @fxDreema My sl isn't zero. I noticed that whatever I sl i put, this line of code always appear. SL=0 is always there. try to check your codes. I even tried setting it to something else like 2 or 5 or 0.001 and still nothing.

            1 Reply Last reply Reply Quote 0
            • C
              casebefx last edited by

              When I put zero into Formula block EA stops too. Is it bug in EA or is it "mathematical bug" because it shouldn't divide by zero ?

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

                Well, here is some small example - https://fxdreema.com/shared/O7I9C8GQc I don't have problems with this one 😧

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

                  It is with Custom Price level - Candle - Parameter Candle High or Low - Candle ID 1, which means SL in the minimum or maximum of the previous candle.

                  1 Reply Last reply Reply Quote 0
                  • tcanuto
                    tcanuto @fxDreema last edited by

                    @fxDreema It is with Custom Price level - Candle - Parameter Candle High or Low - Candle ID 1, which means SL in the minimum or maximum of the previous candle.

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

                      For those who still have the issue - there is something I realized: As this app runs in the cloud, sometime there might be hickups... like the connection is not stable enough and so on... this could lead to issues whilst the creation of some blocks. I had the same zero-divide issue and therefore I re-created the buy and sell blocks, afterwards they worked as supposed. of course the SL cannot be 0, but I was looking for the lowest or highes candle of 10 after an EMA cross, hence I knew that the SL was never 0. It could also have been an issue with the highest/lowest function, that provided maybe a 0 as SL - but this function was also part of the buy / sell block. So again, I deleted them and re-created them, and all of a sudded the EA worked as supposed - no zero-divide anymore. No functionallity was changed... sometimes that happens - was not the first time that it took me hours to find an issues and the last solutions was to re-create the block, just to find that it could have worked just fine. I blame it on the connections losses that appear sometimes and I make mayself aware of the blocks that I was creating during that time. ... maybe that solves your issues as well.

                      1 Reply Last reply Reply Quote 1
                      • MMBInvest
                        MMBInvest last edited by

                        Another observation: if the SL is too close, you might get an spread issue ... like if the spread is bigger than you SL, than this might cause a zero-divide. Hence you might want to add the spread to you SL ...

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

                          @MMBInvest Thank you vermy much for sharing.

                          (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

                          C
                          T
                          S
                          A
                          M
                          R
                          G
                          G
                          Y
                          C
                          S
                          S

                          24
                          Online

                          146.7k
                          Users

                          22.4k
                          Topics

                          122.6k
                          Posts

                          Powered by NodeBB Forums | Contributors