fxDreema

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

    when creating code for custom blocks MQL functions do not work. ALSo Loops do not work.

    Questions & Answers
    2
    2
    100
    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.
    • V
      VanceDavid last edited by

      Function examples:
      Example Purpose: Returns the larger of two values.

      Syntax: MathMax(value1, value2)

      double a = 5.0;
      double b = 10.0;
      double max_value = MathMax(a, b); // max_value will be 10.0

      MathMin
      Purpose: Returns the smaller of two values.

      Syntax: MathMin(value1, value2)

      Example:

      mql
      double a = 5.0;
      double b = 10.0;
      double min_value = MathMin(a, b); // min_value will be 5.0

      No Functions work Why. ALSO loops don't work why.

      Here's an example in MQL5 to calculate the largest body bar between bar 1 and bar 5. In this context, the "body" of a bar is the absolute difference between the opening and closing prices of that bar.

      Example Code:

      void OnStart()
      {
      // Arrays to hold the open and close prices of bars
      double openPrices[5], closePrices[5];

      // Assign example prices for bars 1 to 5
      openPrices[0] = 1.1234; closePrices[0] = 1.1244; // Bar 1
      openPrices[1] = 1.1245; closePrices[1] = 1.1210; // Bar 2
      openPrices[2] = 1.1205; closePrices[2] = 1.1230; // Bar 3
      openPrices[3] = 1.1225; closePrices[3] = 1.1215; // Bar 4
      openPrices[4] = 1.1250; closePrices[4] = 1.1280; // Bar 5
      
      // Variable to hold the largest body size
      double largestBodySize = 0;
      int largestBodyIndex = -1;
      
      // Calculate the body size for each bar and find the largest
      for (int i = 0; i < 5; i++)
      {
          double bodySize = MathAbs(closePrices[i] - openPrices[i]);
          if (bodySize > largestBodySize)
          {
              largestBodySize = bodySize;
              largestBodyIndex = i;
          }
      }
      
      // Print the result
      Print("The largest body is at bar ", largestBodyIndex + 1, " with a size of ", largestBodySize);
      

      }

      WHy! or how to get functions and loops to work?

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

        void OnStart() will not work in FX so just delete, when you compile what errors are you getting?

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

        Online Users

        A
        S
        I
        H
        M
        D
        A
        W
        S
        F

        16
        Online

        146.7k
        Users

        22.4k
        Topics

        122.6k
        Posts

        Powered by NodeBB Forums | Contributors