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
2I am using this one.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.
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);
}
- These users thanked the author tannos for the post:
- kyawswarlin
Re: How can get average profit value for buy and sell orders
3thank you bro
what is DBL_EPSILON
example DBL_EPSILON = 15 ??
what is DBL_EPSILON
example DBL_EPSILON = 15 ??
Re: How can get average profit value for buy and sell orders
4Check this link https://docs.mql4.com/constants/namedco ... econstantskyawswarlin wrote: Tue Dec 01, 2020 4:31 am thank you bro
what is DBL_EPSILON
example DBL_EPSILON = 15 ??
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
- These users thanked the author tannos for the post:
- kyawswarlin