## How can get average profit value for buy and sell orders

Moderators: xard777, mrtools, Banzai

### How can get average profit value for buy and sell orders

#1
when multiple open buy and sell orders..need to close buy order by average takeprofit value and sell orders also.
How can get average profit value for buy and sell orders.
Not average value for all.
Buy average profit and sell average profit.
Thanks you coders.

### Re: How can get average profit value for buy and sell orders

#2
kyawswarlin wrote:
Fri Nov 13, 2020 8:45 pm
when multiple open buy and sell orders..need to close buy order by average takeprofit value and sell orders also.
How can get average profit value for buy and sell orders.
Not average value for all.
Buy average profit and sell average profit.
Thanks you coders.
I am using this one.

Code: Select all

``````
for (int i = OrdersTotal() - 1; i >= 0; i--) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == _Symbol && OrderMagicNumber() == MagicNumber) {
_profit = OrderProfit() + OrderSwap() + OrderCommission();
if (OrderType() == OP_BUY) {
sum_lot_b += OrderLots();
sum_price_b += OrderOpenPrice() * OrderLots();
sum_profit_b += _profit;
}
if (OrderType() == OP_SELL) {
sum_lot_s += OrderLots();
sum_price_s += OrderOpenPrice() * OrderLots();
sum_profit_s += _profit;
}
}
}
if (sum_price_b > DBL_EPSILON) {
sum_price_b /= sum_lot_b;
ave_price_b = NormalizeDouble( (sum_profit_b/(MathAbs(sum_lot_b*MarketInfo(Symbol(),MODE_TICKVALUE)))*MarketInfo(Symbol(),MODE_TICKSIZE)), _Digits);
}
if (sum_price_s > DBL_EPSILON) {
sum_price_s /= sum_lot_s;
ave_price_s = NormalizeDouble( (sum_profit_s/(MathAbs(sum_lot_s*MarketInfo(Symbol(),MODE_TICKVALUE)))*MarketInfo(Symbol(),MODE_TICKSIZE)), _Digits);
}
``````

### Re: How can get average profit value for buy and sell orders

#3
thank you bro
what is DBL_EPSILON
example DBL_EPSILON = 15 ??

### Re: How can get average profit value for buy and sell orders

#4
kyawswarlin wrote:
Tue Dec 01, 2020 4:31 am
thank you bro
what is DBL_EPSILON
example DBL_EPSILON = 15 ??
Check this link https://docs.mql4.com/constants/namedco ... econstants
DBL_EPSILON is only the difference between 1 and the next value of 1 sse it like this DBL_EPSILON = minimum positive number such that 1.0 + DBL_EPSILON != 1.0.

You can use 0 where I put DBL_EPSILON

1. ### Similar Topics

1. #### How to calculate average price for open orders

0 Replies 446 Views

by jack19, Mon May 31, 2021 8:15 am in cTrader Forum

0 Replies
446 Views
2. #### Buffer 11 from "Step one more average 2.3 mtf" gives signal 1 for buy and signal -1 for sell, need to trade signal cross

5 Replies 966 Views

by hobbytrader, Sun Aug 09, 2020 2:06 am in Coding Help

5 Replies
966 Views
3. #### Take Profit with defined lot size - script - not EA

4 Replies 512 Views

by Black Art, Sat Mar 06, 2021 1:14 am in MT4 Indicators

4 Replies
512 Views