Guys... i have a strategy... but i need to understand how to calcular the AVERAGE PRICE... can you help me?
For exemple below all are BUY ORDERS, ok?
LOTS PRICE
0,01 1.01850
0.01 1.01800
0.02 1.01750
0.02 1.01700
0.03 1.01650
I would like to understand how I calculate how many pips my last order should make a pullback for me to get to BREAKEVEN.
Thanks
if you have n positions
avg = { sum(position(i).price x position(i).lote) for i from 1 to n } / { sum(position(i).lote) for i from 1 to n }
if that is not clear, try reading that.
https://www.indeed.com/career-advice/career-development/how-to-calculate-weighted-average

- www.indeed.com
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!
Forum on trading, automated trading systems and testing trading strategies
calculate tp for a basket of positions
Fernando Carreiro, 2022.04.17 18:44
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:
- vi = volume of individual position
- oi = open price of individual position
- ci = close price of individual position
- Vn = total volume for a basket of positions
- On = net mean open price for a basket of positions
- Cn = net mean close price for a basket of positions
- PLn = profit/loss for a basket of positions
Guys... when i am calculating the AVERAGE PRICE... i need put together SPREAD value to each order?
Spread is irrelevant when calculating the net average price of positions that are in the same direction.
Even when dealing with positions in both directions on the same symbol, it is only of relevance when considering any floating closing prices, not yet established, but not pre-defined stops prices.
Guys... i have a strategy... but i need to understand how to calcular the AVERAGE PRICE... can you help me?
For exemple below all are BUY ORDERS, ok?
LOTS PRICE
0,01 1.01850
0.01 1.01800
0.02 1.01750
0.02 1.01700
0.03 1.01650
I would like to understand how I calculate how many pips my last order should make a pullback for me to get to BREAKEVEN.
Thanks
It is easy to put them into an array and use the standard MathMean function.
Regarding your point about calculating how many pips for your last order to get breakeven, you need more info, like the profit/loss of the positions so you know what you are aiming for.
#include <Math\Stat\Stat.mqh> //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { double priceArray[] = {1.01850, 1.01800, 1.01750, 1.01700, 1.01650}; ArrayPrint(priceArray); PrintFormat("Ave = %.4f", MathMean(priceArray)); } //+------------------------------------------------------------------+
Output:
2022.08.11 23:08:18.904 1.01850 1.01800 1.01750 1.01700 1.01650
2022.08.11 23:08:18.905 Ave = 1.0175

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Guys... i have a strategy... but i need to understand how to calcular the AVERAGE PRICE... can you help me?
For exemple below all are BUY ORDERS, ok?
LOTS PRICE
0,01 1.01850
0.01 1.01800
0.02 1.01750
0.02 1.01700
0.03 1.01650
I would like to understand how I calculate how many pips my last order should make a pullback for me to get to BREAKEVEN.
Thanks