fxDreema

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

    Fixed mql5 code performance bug in custom mql5 code block

    Questions & Answers
    3
    5
    309
    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
      Elham last edited by

      Hello, please help me with the problem
      In this project, I tried to close the transaction in situations where the transaction enters the profit and moves in the opposite direction without encountering the takeProfit before encountering the stoploss and keeping a percentage of the profit.
      The desired code was written by Chat GBT in mql5 language and I tried to introduce the required variables of the code, but the problem in executing the code is that every session is closed exactly at the entry point.

      1 Reply Last reply Reply Quote 0
      • E
        Elham last edited by

        https://fxdreema.com/shared/xho6p6zVb
        As you can see, in this project, the entry point is not important to me at all, but what is important to me is keeping the highest number seen in the profit after 100 pips (for example) and comparing it with the currentProfit and closing the deal after N % of decrease in maxProfit

        1 Reply Last reply Reply Quote 0
        • E
          Elham last edited by

          Write a code in mql5 language
          When a new transaction is opened, whether it is buying or selling, when it enters profit and the profit of the transaction is more than 100 pips, from this tick onward, set the maxProfit variable equal to the highest numerical value of the currentProfit of the transaction, and when the value of the instant profit of the transaction is equal to 62 % of max profit has decreased, activate block 60 and execute this command from the beginning after each transaction is closed at the beginning of a new transaction.

          // Global variables
          double maxProfit = 0.0;
          bool block60Activated = false;

          //+------------------------------------------------------------------+
          //| Expert initialization function |
          //+------------------------------------------------------------------+
          int OnInit()
          {
          // Initialize variables
          maxProfit = 0.0;
          block60Activated = false;

          return(INIT_SUCCEEDED);
          

          }

          //+------------------------------------------------------------------+
          //| Expert deinitialization function |
          //+------------------------------------------------------------------+
          void OnDeinit(const int reason)
          {
          // Reset variables
          maxProfit = 0.0;
          block60Activated = false;
          }

          //+------------------------------------------------------------------+
          //| Expert tick function |
          //+------------------------------------------------------------------+
          void OnTick()
          {
          // Check if a new transaction is opened
          if (OrdersTotal() > 0)
          {
          // Get the ticket of the latest order
          int latestOrderTicket = OrderGetTicket(OrdersTotal() - 1);

              // Check if the order is in profit and profit is more than 100 pips
              if (OrderSelect(latestOrderTicket, SELECT_BY_TICKET) &&
                  OrderProfit() > 0 && OrderProfit() > 100 * Point())
              {
                  // Update maxProfit if current profit is higher
                  if (OrderProfit() > maxProfit)
                      maxProfit = OrderProfit();
                  
                  // Check if the instant profit has decreased by 62% of maxProfit
                  if (OrderProfit() <= (0.62 * maxProfit))
                  {
                      // Activate block 60
                      block60Activated = true;
                      
                      // Perform your desired actions for block 60
                      // ...
                      // ...
                      
                      // Reset maxProfit for the next transaction
                      maxProfit = 0.0;
                  }
              }
          }
          

          }

          This code should be placed in an MQL5 Expert Advisor file (.mq5). It initializes the maxProfit and block60Activated variables in the OnInit() function and resets them in the OnDeinit() function. The OnTick() function is called on every tick, and it checks if a new transaction is opened. If the transaction is profitable and the profit is more than 100 pips, it updates the maxProfit variable if necessary. If the instant profit decreases by 62% of maxProfit, it activates "block 60" and performs the desired actions. Finally, the maxProfit is reset for the next transaction.

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

            AFAIK ChatGPT is very bad in writing MT4/5 code. I'm not a programmer so I' afraid I cannot be of any help here, sorry. I hope someone else can.

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

              You can get the correct code from chatGPT, as @l-andorrà says though it's not very good. Good luck with dismantling what is given to make better.

              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
              • 1 / 1
              • First post
                Last post

              Online Users

              S
              M
              E
              G
              D
              A
              A

              34
              Online

              146.7k
              Users

              22.4k
              Topics

              122.6k
              Posts

              Powered by NodeBB Forums | Contributors