fxDreema

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

    Calculate TP (price) for 2 trades of different lot sizes

    Questions & Answers
    4
    16
    1267
    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.
    • General Melchett
      General Melchett last edited by General Melchett

      I have my EA to take profit when TP level is at x pips profit.

      However, this TP is made up of 2 trades, on the same instrument, at different prices and lot sizes from a batch of trades. One trade may even be in DD and the other will be in profit). In other words, it closes out trades in drawdown by taking the oldest and newest trades, and closing them when combined, they are in profit by x pips.

      It's easy enough to tell fxdreema to TP at x pips profit (I can calculate total lot size, and profit in pips from that), but my end goal is to draw a line on the chart to show me visually when I can expect profit to be taken.

      For example, I have 4 trades on the same pair. Let's call them trades A, B, C and D.

      Trade A was a sell taken first with 0.5 lot size.

      Trade B gets taken when DD is at 15 pips, where the EA takes a 2nd trade for 0.55 pips.

      Trade C at 30 pips DD (from trade A at 0.6 lots)

      Trade D at 45 pips DD from first entry, at 0.65 lots.

      As price returns back into profit on trade D, I wish to know when the oldest and newest trades (trades A and D ONLY, other trades are ignored) reach a total of x pips profit, whereas they close out. So trades A and D close when profit reaches x pips with lot size (0.5 + 0.65 = 1.15 lots).

      This is pretty easy to do as currency value (IF profit (A+D) > x pips profit (1.15 lots)), but I can't (I don't know) how to derive the price at which TP would occur so I can draw the line on the chart.

      I've been grinding the maths through my brain and I'm sure it's simple when laid out but I've been thinking about it too much now and just tie myself up in knots. Anyone have any idea on how to calculate this? Or how I should be visualising it?

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

        I'm looking for something similar and I had to accept I need custom code for sure. If I find the solution I will share it here.

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

          ChatGPT has this to say. I'm going to take a look at this closely a little later (it's for a sell):

          (Deleted pic as formula was wrong)

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

            cumulative profit is a single blue block, no? check unrealized profit - mode pips

            General Melchett 1 Reply Last reply Reply Quote 0
            • General Melchett
              General Melchett @TipsyWisdom last edited by

              @TipsyWisdom it is, super easy.

              BUT, I would like to display the TP as a line on the chart, and I can only do this (as far as I know) by calculating the price that the TP line should be.

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

                Nah, OnTrade.

                Id imagine in that tab you can use a pass, connected to a modify variables function, that then defines the value of the variables as at the value of the current TP in price, then do a drawline function, that will draw a line at the new defined variable.

                At least that makes sense to me...let me see if I can try to do it. Perhaps some feature is missing that I am not thinking of

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

                  image.png

                  something like that.

                  or this

                  image.png

                  ?

                  1 Reply Last reply Reply Quote 1
                  • General Melchett
                    General Melchett last edited by General Melchett

                    Never knew you could draw lines straight from TP!

                    But I don't think that'll work - it works on bucket, right? For bucket you can only filter by direction or manual/automated. By loop you could do it (count buys, then only count every (totaltrades -1)) but then you can't calc the aggregated TP of the 2 trades (remember, this could be the first/last trades of a batch of 10+)

                    ChatGPT's approach is to proportionally measure each trade's contribution to profit by point, and take into account the starting price of each, which is how it would've been in my head but I had no idea what formula would be.

                    I've nearly done it but the maths/formula is tripping me up, particularly point size as I want it to work on metals/FX/indices. I'm so close, I have the correct TP now but it's multiplied it by 10 somewhere. I'll post formula when I've cracked it.

                    1 Reply Last reply Reply Quote 0
                    • General Melchett
                      General Melchett last edited by

                      Also remember the TP in pips is of the first/last trades total lot size. The oldest trade is almost certainly in drawdown when it's closed (but the two together close in profit)

                      1 Reply Last reply Reply Quote 0
                      • General Melchett
                        General Melchett last edited by

                        This is bizarre.
                        I have 2 formulas to trace bug on why calc isn't working. One that uses custom pip size (0.0001) and one that uses original (0.00001). Identical formulas bar the 1 decimal place. But fxdreema seems to be unable to calculate the one with the extra decimal place. Just completely ignores it. And it's not the variable, I've tried hardcoding the 0.00001 as well. Very strange.

                        This formula seems to work weirdly I can't get the calculation to work. It simple refuses to multiply by 0.00001. Tried it an MQL5 code block and output to journal. No dice.

                        image.png

                        It's soooo close. The above is the solution but I have spent so long on this now for some visual flair I think I'll just leave it.

                        1 Reply Last reply Reply Quote 0
                        • General Melchett
                          General Melchett last edited by

                          A little more on the formula (buys only)

                          image.png

                          1 Reply Last reply Reply Quote 0
                          • General Melchett
                            General Melchett last edited by General Melchett

                            Be wary of using chatGPT as it took me a while to get to this formula.

                            For example, some of the maths was completely out - I gave it 'real life' figures based on watching strategy tester (as it was working with TP based on profit, rather than price). Then it corrected itself.

                            But you can also just say 'now give it to me as MQL5' and it spits out code for you, so that's pretty handy

                            double CalculateTakeProfitPriceForBuy(double P_A, double P_D, double x_pips)
                            {
                                double lot_size_A = 0.02;
                                double lot_size_D = 0.06;
                                double pip_size = 0.0001;  // Standard pip size for major pairs like EURUSD
                                
                                return (lot_size_A * P_A + lot_size_D * P_D + x_pips * pip_size * (lot_size_A + lot_size_D)) / (lot_size_A + lot_size_D);
                            }
                            
                            // Sample usage:
                            void OnTick()
                            {
                                double P_A = 1.09692;  // Opening price of trade A
                                double P_D = 1.09592;  // Opening price of trade D
                                double x_pips = 3.0;   // Desired profit in pips
                                
                                double TP_Price = CalculateTakeProfitPriceForBuy(P_A, P_D, x_pips);
                                
                                // Use the TP_Price as necessary, e.g., set a take profit order, draw a line on chart, etc.
                                // ... your logic here ...
                            }
                            
                            
                            1 Reply Last reply Reply Quote 0
                            • l'andorrà
                              l'andorrà last edited by

                              Interesting. Would this formula work like this?:

                              1. I've got three open trades right now. Two buys and one sell.
                              2. Each trade has got different lot size.
                              3. I want a line on the chart showing my expected money profit (inserted as input parameter).

                              Not sure this formula would do it.

                              (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.

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

                                @l-andorrà no it will only work for buys, that's a hedged trade, no?

                                But it might be worth asking ChatGPT as it can come up with a calculation/formula for you

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

                                  Ok. Thanks.

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

                                    ........

                                    RGoo

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

                                    Online Users

                                    A
                                    J
                                    D
                                    E

                                    29
                                    Online

                                    146.7k
                                    Users

                                    22.4k
                                    Topics

                                    122.6k
                                    Posts

                                    Powered by NodeBB Forums | Contributors