fxDreema

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

    Help - Custom MQL Code

    Questions & Answers
    8
    30
    4242
    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.
    • J
      jonatassantanacaje last edited by

      Does anyone know any MQL code to be included in my project through (Custom MQL Code)?

      Any of the 3 functions will serve:

      • Turn off Automated Trading.
      • Close all graphics windows.
      • Or even close the MT4 platform completely.

      I have an EA that works on several different pairs at the same time, and if the DD reaches a certain amount of losses (Equity), this protector of mine will close all trades and prevent new trades from being opened.

      My Project: I actually copied it from another project here on the forum and I'm modifying it...

      https://fxdreema.com/shared/rTREhxBTb

      1 Reply Last reply Reply Quote 0
      • J
        jonatassantanacaje last edited by jonatassantanacaje

        @jstap @l-andorrà @fxDreema

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

          These are standard MQL code, search google and you will find, turning off AUTO trading is more difficult.

          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! 😊

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

            @jstap

            //--- importing required dll files
            #include <WinUser32.mqh>
            #import "user32.dll"
            int GetAncestor(int, int);
            #define MT4_WMCMD_EXPERTS  33020
            #import
            
            //+------------------------------------------------------------------+
            //|                                                                  |
            //+------------------------------------------------------------------+
            void SetAlgoTradingTo(bool trueFalse) {
                //--- getting the current status
                bool currentStatus = IsTradeAllowed();
                //--- if the current status is equal to input trueFalse then, no need to toggle auto-trading
                if(currentStatus != trueFalse) {
                    //--- Toggle Auto-Trading
                    int main = GetAncestor(WindowHandle(Symbol(), Period()), 2/*GA_ROOT*/);
                    PostMessageA(main, WM_COMMAND,  MT4_WMCMD_EXPERTS, 0 );//Toggle Expert Advisor button
                }
            }
            
            1 Reply Last reply Reply Quote 2
            • l'andorrà
              l'andorrà @jonatassantanacaje last edited by

              @jonatassantanacaje I'm afraid that goes beyond my capabilities, sorry.

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

                Toggling AutoTrading can't be done with a basic mql code block, it requires to be done with a dll. As you can see at the top of the code, it's including files. FXDreema doesn't do this unless you make a custom block so you can include in the global variables. Here is how you would set up a block to use to toggle the AutoTrading button off. You can click it whenever you want to resume trading. Keep in mind this would disable ALL EAs. I tested this with a basic project and it does work but it has to be done correctly.

                Screenshot_1.png

                In the project, I just had it enter a large lot with a very very low equity drawdown since this can't be done in the backtester. Then, used the block after closing trades and the AutoTrading was turned off.
                https://fxdreema.com/shared/klNJARKgb

                However, I feel like if you're just trying to prevent new trades after a certain amount of loss, there are other easier ways to do it. Just terminate the EA with the terminate block or something, why do you need to toggle the AutoTrading button? It achieves the same thing pretty much. Hope this helps.

                J jstap 2 Replies Last reply Reply Quote 0
                • J
                  jonatassantanacaje @willramsey last edited by

                  @willramsey Hello, thank you for your attention, I need to turn off ALGOTRADING, because I have about 5 robots open at the same time on different charts, and all of them have to stop trading at the same time.

                  willramsey 1 Reply Last reply Reply Quote 0
                  • willramsey
                    willramsey @jonatassantanacaje last edited by willramsey

                    @jonatassantanacaje I see, if that's the case you would need to create the custom block. Then wherever you pass and use the block, it will disable autotrading. If you don't know code then it'll probably be quite confusing.

                    You'll also have to create some code to close all pairs open in the account. I think the close trades block will only close current EA and manual trades. This would work since it loops all orders on any pair. After they close then it gets disabled.

                    Screenshot_2.png

                    if (OrdersTotal() > 0){

                    for (int i = OrdersTotal() - 1; i >= 0; i--) {
                    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
                    OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5 /slippage/, clrRed);
                    }
                    }
                    }

                    J 1 Reply Last reply Reply Quote 0
                    • J
                      jonatassantanacaje @willramsey last edited by

                      @willramsey I don't need all the functions working, I just gave examples, whichever is easier to do will be ideal for me.

                      Turn off automation or close all windows

                      1 Reply Last reply Reply Quote 0
                      • J
                        jonatassantanacaje last edited by

                        Thank you very much @willramsey
                        Everything is working properly 🙏

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

                          You get code to do all that, but can take a lot of work, why don't you use a variable to start/stop trading, use a terminal (global) variable to stop and close trades on all charts?

                          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
                          • J
                            joemarkey6 last edited by

                            @jonatassantanacaje
                            Im trying to do the same thing that you managed to achieve, did you do it with one mql block?
                            If so would you mind sharing the code thats required in the block please

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

                              @joemarkey6
                              Check above posts, one included the whole code

                              1 Reply Last reply Reply Quote 0
                              • J
                                joemarkey6 last edited by

                                I tried all the above and always get errors, Id appreciate it if someone could upload the block.

                                Cheers

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

                                  @willramsey Do you mind having a look at this, and seeing if you can work out why I am getting this error? faeac98e-0aab-4d78-9848-c85c7a1365a0-image.png
                                  f62c8b7b-0a0b-4e6d-9891-d2447ac791a8-image.png

                                  Code used is:
                                  Functions:
                                  void SetAlgoTradingTo(bool trueFalse) {

                                  bool currentStatus = IsTradeAllowed();
                                  
                                  if(currentStatus != trueFalse) {
                                  	
                                  	int main = GetAncestor(WindowHandle(Symbol(), Period()), 2/*GA_ROOT*/);
                                     PostMessageA(main, WM_COMMAND, MT4_WMCMD_EXPERTS, 0 );
                                  
                                  }
                                  

                                  }

                                  Global variables:
                                  #include <WinUser32.mqh>
                                  #import "user32.dll"
                                  int GetAncestor(int, int);
                                  #define MT4_WMCMD_EXPERTS 33020
                                  #import

                                  Than you.

                                  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
                                  • J
                                    joemarkey6 last edited by

                                    Ok great thanks, I never come accross the FXDreema Studio before, I thought that you could simply paste code straight into the MQL block. Ill have to work out how to use it and give it a go.

                                    Cheers

                                    willramsey 1 Reply Last reply Reply Quote 0
                                    • willramsey
                                      willramsey @joemarkey6 last edited by

                                      I have seen a few people say they are getting errors so I just decided to make a quick tutorial over it. The video is about 8 minutes. If it still doesn't work, then I really wouldn't have a clue. If it works on my end, it should work on yours. Hope this helps.
                                      https://youtu.be/xjMN9KzBqB8

                                      jstap willramsey OntradingX 3 Replies Last reply Reply Quote 0
                                      • jstap
                                        jstap @willramsey last edited by jstap

                                        @willramsey Thanks for the video

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

                                          I have worked out why it did not work as expected, was to do with, on FX sometimes if you save something wrong, it then won't work when correct, so I closed/deleted, and started from fresh. This time all worked, I then recreated and changed a few words to be able to switch Algo Trading back on, I will add this code below.

                                          1 = SetAlgoTradingFo(true);

                                          2=#include <WinUser32.mqh>
                                          #import "user32.dll"
                                          int GetAncestor(int, int);
                                          #define MT4_WMCMD_EXPERTS 33020
                                          #import

                                          (this is the same deactivate)

                                          3= void SetAlgoTradingFo(bool falseTrue) {
                                          //--- getting the current status
                                          bool currentStatus = IsTradeAllowed();
                                          //--- if the current status is equal to input falseTrue then, no need to toggle auto-trading
                                          if(currentStatus != falseTrue) {
                                          //--- Toggle Auto-Trading
                                          int main = GetAncestor(WindowHandle(Symbol(), Period()), 2/GA_ROOT/);
                                          PostMessageA(main, WM_COMMAND, MT4_WMCMD_EXPERTS, 0 );//Toggle Expert Advisor button
                                          }
                                          }

                                          (is slightly different to disable and I called this block a different name)

                                          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 1
                                          • willramsey
                                            willramsey @willramsey last edited by willramsey

                                            I messed with creating it a different way and this worked just as well with less code . The if statement just checks the current status and if its on, then it toggles the button. Otherwise it does nothing. There is no custom function to make or anything.

                                            Screenshot 2023-12-11 084504.png

                                            // Global Variables, includes
                                            
                                            #include <WinUser32.mqh>
                                            #import "user32.dll"
                                            int GetAncestor(int, int);
                                            #define MT4_WMCMD_EXPERTS 33020
                                            #import
                                            
                                            //  Main Code
                                            
                                            if (IsTradeAllowed()){
                                            int main = GetAncestor(WindowHandle(Symbol(), Period()), 2/*GA_ROOT*/);
                                            PostMessageA(main, WM_COMMAND, MT4_WMCMD_EXPERTS, 0);
                                            }
                                            
                                            
                                            J 1 Reply Last reply Reply Quote 1
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post

                                            Online Users

                                            P
                                            T
                                            I
                                            B
                                            A
                                            H
                                            E

                                            19
                                            Online

                                            146.7k
                                            Users

                                            22.4k
                                            Topics

                                            122.6k
                                            Posts

                                            Powered by NodeBB Forums | Contributors