calculate tp for a basket of positions

Lots weighted average price is your open price. (Op)
Lots Weighted Average Price = ∑ ^{op}(i) × ^{lot}(i) ÷ ∑ ^{lot}(i). This is the break even price of all orders combined.
Figuring out how to reopen several positions after forcibly closing them  Expert Advisors and Automated Trading  MQL5 programming forum #1 (2022)Your profit is ( ^{C}p  ^{O}p) * Lots * ^{T}v / ^{T}s
Do NOT use TickValue by itself  DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
MODE_TICKVALUE is not reliable on nonfx instruments with many brokers  MQL4 programming forum (2017)
Is there an universal solution for Tick value?  Currency Pairs  General  MQL5 programming forum (2018)
Lot value calculation off by a factor of 100  MQL5 programming forum (2019) 
Hedging, grid trading, same as Martingale.
Martingale, Hedging and Grid : MHG  General  MQL5 programming forum (2016)Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions)  MQL5 programming forum (2015)Why it won't work:
Calculate Loss from Lot Pips  MQL5 programming forum (2017)
THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy  YouTube (2020)

Lots weighted average price is your open price. (Op)
Your profit is ( ^{C}p  ^{O}p) * Lots * ^{T}v / ^{T}s

Hedging, grid trading, same as Martingale.
Martingale, Hedging and Grid : MHG  General  MQL5 programming forum (2016)Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions)  MQL5 programming forum (2015)Why it won't work:
Calculate Loss from Lot Pips  MQL5 programming forum (2017)
THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy  YouTube (2020)
Thank you for your reply. I don't quite understand what you mean by " Your profit is ( ^{C}p  ^{O}p) * Lots * ^{T}v / ^{T}s". Would you care to show what you mean in mq5 language? That would be highly appreciated.
I tried using your formula for lots weighted avarage in this way:
double BuyTp = NormalizeDouble((AvaregeBuyEntryPrice * TotalBuyLotsOpen())/TotalBuyLotsOpen(),_Digits);I must have used your formula wrong, as with this the output becomes the average price of open orders and does not adjust for varying lot sizes of the different orders. So the tp level is not the break even point of all orders, but merely the average entry point of all orders.. Would appreciate it if you can show me how you would write the function in mq5.
 ^{C}p = Close price of position
 ^{O}p = Open price of position
 Lots = Volume of position
 ^{T}v = Tick value
 ^{T}s = Tick size
See also the following:
Forum on trading, automated trading systems and testing trading strategies
Any great idea about HEDGING positions welcome here
Fernando Carreiro, 2018.09.17 21:17
For those of you that want to learn to see the "light" and not fall into the trap of "hedging" and Grid strategies, here is the basic math:
:
Learn to do your research properly! Do not be blinded by false promises. Do the math!
Thank you Fernando, but I don't know what the variables on that sheet are referring to. Can you please explain?
I have been working on solving this issue for 5 hours using the formulas presented by William Roeder, but still I have no success in getting either the cummilative break even price or the cummilative tp price based on a money profit value.
If anyone would share how they would go about it in mq5 language that would be highly appreciated.
Thanks
There is no exact MQL code to give you, because it varies depending on the strategy and what information needs to be calculated. That is why I gave you the math instead for you to implement depending on your requirements.
The math is self explanatory, but if you are having difficulty with it, then I doubt you will be able to implement it in code, but here are the variables anyway:
 ^{v}i = volume of individual position
 ^{o}i = open price of individual position
 ^{c}i = close price of individual position
 ^{V}n = total volume for a basket of positions
 ^{O}n = net mean open price for a basket of positions
 ^{C}n = net mean close price for a basket of positions
 ^{PL}n = profit/loss for a basket of positions
There is no exact MQL code to give you, because it varies depending on the strategy and what information needs to be calculated. That is why I gave you the math instead for you to implement depending on your requirements.
The math is self explanatory, but if you are having difficulty with it, then I doubt you will be able to implement it in code, but here are the variables anyway:
 ^{v}i = volume of individual position
 ^{o}i = open price of individual position
 ^{c}i = close price of individual position
 ^{V}n = total volume for a basket of positions
 ^{O}n = net mean open price for a basket of positions
 ^{C}n = net mean close price for a basket of positions
 ^{PL}n = profit/loss for a basket of positions
 Free trading apps
 Over 8,000 signals for copying
 Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I am trying to calculate the price level for take profit for a basket/group of positions. It is for a martingale system. The tp should be placed at the price level where cumulative profit of all buy orders is xx in account currency. It seems my calculation is wrong. Can someone see what I am doing wrong?