fxDreema

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

    MT5 Optimizer not working with many FX Dreema EA - RESOLVED

    Bug Reports
    7
    13
    2641
    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.
    • Q
      QuantEngineer last edited by

      Many times the MT5 optimizer doesn't work with many FXDreema EAs, and that was very limiting to building professional-level trading strategies properly tested.

      I got to the bottom of this bug, and here is what is happening:
      There is a class used to close multiple trades called "MDL_CloseOpened" and this class has a main loop "while (finished == false)" , that keeps doing infinite attempts to close the positions that match the criteria...

      But some brokers have a data feed of prices (candlesticks) during hours when they do NOT allow trade... If the Close block runs during non-trade hours, then the loop will never end... and the backtest never completes... that is why the Optimizer gets stuck...

      To resolve this issue, we need to know if the broker allows trading before using the Close Block... (the blue Block...)
      The MQL5 native function to check on that is SymbolInfoSessionTrade() and can be found on the official documentation on this link:
      https://www.mql5.com/en/docs/marketinformation/symbolinfosessiontrade

      f12f60a4-8ed8-4e79-be51-7d01e360d43e-image.png

      I created this small block called "is Trade Time" to be placed before the Close All block, to prevent this infinite loop.

      Find the source code for FX Dreema Studio below... remember that you will need to create the parameter ttSymbolName (type string) on FX Dreema Studio. Enjoy the solution and happy week.

      //Create string Paramter ttSymbolName
      datetime SessionStart;
      datetime SessionEnd;
      
      datetime SessionTimeNow = StringToTime("1970.01.01 " + TimeToString(TimeTradeServer(), TIME_MINUTES));
      if (ttSymbolName=="") { 
      
      	ttSymbolName = (string)CurrentSymbol();  // Known Issue, function has to be called twice in a row, anyways, not working well, unless opening the chart in advance, for some reason.
      	ttSymbolName = (string)CurrentSymbol(); 
      }   
      //Print( "checking ttSymbolName=" , ttSymbolName , " Symbol=" , Symbol() , " CurrentSymbol()=" , (string)CurrentSymbol() , " Symbol()=" , Symbol() , ", _Symbol=", _Symbol );
      //Print( "checking ttSymbolName is " , ttSymbolName  , " CurrentSymbol()=" , (string)CurrentSymbol() , " Symbol()=" , Symbol()  , ", _Symbol=" , _Symbol );
      
      //Print("Current time is ", TimeToString(TimeTradeServer(), TIME_MINUTES), " SessionTimeNow=", TimeToString(SessionTimeNow));
      int SessionIDLoop = 0;
      bool isthissessionactive = false;
      
      while (SymbolInfoSessionTrade( ttSymbolName , DayOfWeek(TimeTradeServer()) , SessionIDLoop , SessionStart , SessionEnd  ) )
      {
      	//Print("while cycle #", SessionIDLoop, ", on symbol " , ttSymbolName , " on dayofWeek " , DayOfWeek(TimeTradeServer()), ", Now is ", TimeToString(SessionTimeNow, TIME_MINUTES), ", Starting at ", TimeToString(SessionStart, TIME_MINUTES), ", ending at ", TimeToString(SessionEnd, TIME_MINUTES) );
      if (SessionTimeNow>SessionStart && SessionTimeNow < SessionEnd )
      {	
      	isthissessionactive = true;
      	break;
      }	
      	
      	
      SessionIDLoop++;
      }
      
      
      
      
      if (isthissessionactive && TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && MQLInfoInteger(MQL_TRADE_ALLOWED)) {~next~} else {~inext~}
      

      Quant Engineer
      www.abfs.tech

      roar 1 Reply Last reply Reply Quote 2
      • roar
        roar @QuantEngineer last edited by

        @QuantEngineer same bug reported here: https://fxdreema.com/forum/topic/16494/close-positions-when-market-is-closed

        Another workaround: close with the purple positions loop instead of blue close block.

        Need small help? Tag me in your post
        Need big help? https://www.fiverr.com/big_algo/automate-your-winning-strategy-in-mql4-or-mql5

        1 Reply Last reply Reply Quote 0
        • Q
          QuantEngineer last edited by

          That is cool ! thanks for the feedback!

          We have to watch out because the reason why FX DReema creates the infinite loop is that when the EA is attempting to close a large number of positions, many of the commands can get rejected for multiple reasons and that is why it might need to go back and make new attempts to close positions over and over again, until they all close. If people choose to close them with the for loop, it is a good idea to run the loop multiple times on the same group of trades to ensure all the positions close.

          I believe it might be related to the asynchronous close, it works a lot faster than the synchronous close but leaves some positions behind sometimes...

          Quant Engineer
          www.abfs.tech

          1 Reply Last reply Reply Quote 1
          • M
            Mitchp last edited by

            I just started fxdreema. My EA works fine in testing, until I try to optimize. I'm using it in the Forex market, so I don't think this applies to me?

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

              Good day,
              I'm getting an issue compiling this code when it's used in a project. The error states 'DayOfWeek' - cannot convert enum in fxdreema.
              So I went into MetaEditor and it's showing me that this line has the error but I can't figure out what it's issue is.
              image.png
              image.png

              May I please get an assist with this?
              Thanks in advance and I greatly appreciate it!

              roar 1 Reply Last reply Reply Quote 0
              • roar
                roar @BBMess last edited by

                @BBMess I guess DayOfWeek() doesnt accept any parameters, it always uses current time

                Need small help? Tag me in your post
                Need big help? https://www.fiverr.com/big_algo/automate-your-winning-strategy-in-mql4-or-mql5

                B 1 Reply Last reply Reply Quote 0
                • B
                  BBMess @roar last edited by

                  @roar I understand that might have been the issue. I'll test removing the parameter and see what different errors pop up. Perhaps there's a different fix for this that I don't know anything about.

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

                    Does this make sense to those that code projects outside of FXDreema?

                    image.png

                    1 Reply Last reply Reply Quote 0
                    • K
                      KhalelFx last edited by

                      I just want to ask the same question (the topic problem), is this what this content is about?
                      I created a strategy from FxDreema and the EA seems to function well and gives the right signals, however, at some point on the backtesting it pause. Does anyone know why?

                      image.png

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

                        I'm not a programmer, but it looks like any of the project's loops entered into an endless loop execution and that's why it doesn't work. You will need a programemr to find the reason why, I'm afraid.

                        (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
                        • Q
                          QuantEngineer last edited by QuantEngineer

                          Hello Everyone,

                          It just needs a Custom Function to identify the DayOfWeek...
                          Here is the function. It can be copied and pasted into the Custom Functions Section from FX Dreema Studio for MQL5. The path to paste it is:

                          1. Load FX Dreema Studio for MQL5 with this link https://fxdreema.com/studio/MQL5
                          2. Go to the bottom right corner of the page, and find a section with the title "Custom Functions",

                          image.png

                          1. Click on the "New" button
                          2. Paste the function in the window that will open.
                            bc29115c-6dd4-47d9-b373-8f4af70b5f60-image.png
                          3. Click the "Save" button.
                            And here is the function below to be copied:

                          ENUM_DAY_OF_WEEK DayOfWeek(datetime aTime)
                          {
                          MqlDateTime stm;
                          TimeToStruct(aTime,stm);
                          return(stm.day_of_week);
                          }

                          Quant Engineer
                          www.abfs.tech

                          1 Reply Last reply Reply Quote 0
                          • S
                            sktsec last edited by

                            MQL already has this function.

                            https://docs.mql4.com/dateandtime/dayofweek

                            https://docs.mql4.com/dateandtime/timedayofweek

                            1 Reply Last reply Reply Quote 0
                            • Q
                              QuantEngineer last edited by

                              That is MQL4... in MQL5, we need the custom function because MQL5 doesn't have the native function for DayOfWeek, and this is the reason some people are getting the error...

                              Quant Engineer
                              www.abfs.tech

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

                              Online Users

                              L
                              M
                              F
                              B
                              Z
                              J
                              G

                              15
                              Online

                              146.7k
                              Users

                              22.4k
                              Topics

                              122.6k
                              Posts

                              Powered by NodeBB Forums | Contributors