fxDreema

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

    Calculate Weight Average Open Price

    Questions & Answers
    7
    9
    1142
    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.
    • T
      tumnoyi last edited by

      Hi,

      I would like to calculate weight average open price of active orders. For Example, there are 2 active orders. 1st Order have open price at 1.0000 with 1 LOT.
      2nd order have open price at 1.5000 with 4 LOT. The weight average open price of these 2 orders will be 1.4000.
      Please suggest me that how can I code EA to calculate this value.

      Regards,

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

        I surrender at this. It's not impossible, but the solution will be ugly I think. But why do you need this? In "Trailing stop (group of trades)" this is something that happens in the block. If you want it for something else, maybe there is a better alternative. I think that, because I don't remember someone asking the same question before.

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

          @fxdreema Hello Sir I want to calculate the average price of open buy trades so that i can set Tp of all open trades.
          I use formulas for calculation of avg open price but its working wrong when a trade is close

          Kindly make a block for Average price calculator. Or
          Calculate a weighted average block.

          Thanks.

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

            @muhawat I think this is what you want to do, you will have to multply SL value depending on asset, (not worked out how to do it on auto), you can copy to do same with TP, this will give you the current price if stop is hit. https://fxdreema.com/shared/WRFjFb2Hd

            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
              johnsteynberg last edited by johnsteynberg

              Hi @muhawat

              I think I had a similar question and I played around today and manage to do this. https://fxdreema.com/shared/1rWwBHYWb
              It calculates the average price of all open trades so that you can get a BreakEven price. I hope this helps.

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

                Unfortunately after testing thoroughly I found that the values returned is not correct. I'll continue trying and post the update here asap.

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

                  //| Fonction pour calculer le prix moyen pondéré par le volume       |
                  //+------------------------------------------------------------------+
                  double CalculateVolumeWeightedPrice()
                  {
                      double totalVolume = 0.0;      // Volume total des transactions
                      double totalValue = 0.0;       // Valeur totale pondérée par le volume
                  
                      // Parcourir toutes les transactions de la position actuelle
                      for (int i = 0; i < PositionsTotal(); i++)
                      {
                          // Sélectionner la position
                          if (PositionGetTicket(i))
                          {
                              double volume = PositionGetDouble(POSITION_VOLUME); // Volume de la transaction
                              double price = PositionGetDouble(POSITION_PRICE_OPEN); // Prix d'ouverture de la transaction
                  
                              // Ajouter au volume total et à la valeur totale
                              totalVolume += volume;
                              totalValue += volume * price;
                          }
                      }
                  
                      // Éviter une division par zéro
                      if (totalVolume == 0.0)
                      {
                        
                          return 0.0;
                      }
                  
                      // Calculer le prix moyen pondéré par le volume
                      double volumeWeightedPrice = totalValue / totalVolume;
                      return volumeWeightedPrice;
                  }
                  1 Reply Last reply Reply Quote 0
                  • B
                    biez6900 last edited by biez6900

                    `thanks deepseek, create a function here : https://fxdreema.com/studio and use that

                    J 1 Reply Last reply Reply Quote 0
                    • J
                      jxlibin1987 @biez6900 last edited by

                      @biez6900 How to operate specifically? Can you be more detailed? I happen to need this too, thank you dear friend

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

                      Online Users

                      N
                      S
                      T

                      19
                      Online

                      146.7k
                      Users

                      22.4k
                      Topics

                      122.6k
                      Posts

                      Powered by NodeBB Forums | Contributors