# Calculate Average price of Open Positions for Hedge account

hi All,

I need a help in calculating average price of open positions, considering both buy positions and sell positions.

currently i am using two separate functions, buy average price and Sell average price.

i use  reverse martingale system to add positions.

```double CalculateBuyTakeprofit()
{
double result=0;
if(total==1)
{
result = BuyLastEntry + Takeprofit * Point();
}
else if(total>1)
{
double average = 0;
double total_lots = 0;
for(int i=0; i<total; i++)
{
}
double averagePrice = average/total_lots;
result = averagePrice + Takeprofit * Point();
}
return result;
}
//+------------------------------------------------------------------+
double CalculateSellTakeprofit()
{
double result=0;
int total = Total.Total_Sell; // return sell positions
if(total==1)
{
result = SellLastEntry - Takeprofit * Point();
}
else if(total>1)
{
double average = 0;
double total_lots = 0;
ArrayResize(SellTradesLots,total); // for number of lots
for(int i=0; i<total; i++)
{
}
double averagePrice = average/total_lots;
result = averagePrice - Takeprofit * Point();
}
return result;
}```

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
• www.mql5.com
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.

Keith Watford:
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.

gamblerappa #: