Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
There is no direct equivalent to OrderProfit() in MQL5 that would give you the profit instantly like in MQL4. Here is a rewritten MQL5 function does the same by collecting the required parameters.
double calculateOrderProfit(int orderTicket) { double openPrice = 0, closePrice = 0, volume = 0; int orderType; if (HistorySelect(OrderGetInteger(ORDER_TIME_SETUP), TimeCurrent())) { if (OrderSelect(orderTicket)) { openPrice = OrderGetDouble(ORDER_PRICE_OPEN); closePrice = OrderGetDouble(ORDER_PRICE_CURRENT); volume = OrderGetDouble(ORDER_VOLUME); orderType = OrderGetInteger(ORDER_TYPE); double profit = OrderCalcProfit( orderType, OrderGetString(ORDER_SYMBOL), volume, openPrice, closePrice ); return profit; } } return 0; } string formatOrderArrowInfo(int orderTicket) { double profit = calculateOrderProfit(orderTicket); return(StringConcatenate( OrderGetString(ORDER_COMMENT), " (", OrderGetInteger(ORDER_MAGIC), ")\nP/L: ", DoubleToStr(profit + OrderGetDouble(ORDER_SWAP) + OrderGetDouble(ORDER_COMMISSION), 2), " ", AccountInfoString(ACCOUNT_CURRENCY), " (", DoubleToStr(MathAbs(OrderGetDouble(ORDER_PRICE_OPEN) - OrderGetDouble(ORDER_PRICE_CLOSE)) / (SymbolInfoDouble(OrderGetString(ORDER_SYMBOL), SYMBOL_POINT) * pointsPerPip()), 2), " pips)" )); }
There is no direct equivalent to OrderProfit() in MQL5 that would give you the profit instantly like in MQL4. Here is a rewritten MQL5 function does the same by collecting the required parameters.
thanks so much woow i hope in next update metatrader introduce the funcion thanks
Hi
Orders MT5 are different things than in MT4 (https://www.mql5.com/en/articles/211) so when you want to get orderProfit from orders it’s always “zero” since those are only pending orders.
I believe you might be looking for profit from positions, so opened market trades(buy/sell) then you can get those values by using PositionSelect and PositionGetDouble (POSITION_PROFIT)
Have a nice day👍📊
- www.mql5.com
- 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 guys i have this part of code (is free and is not mine )
order profit in mql4 exist , in mql5 i find this oreder_calc_profit but for call this function i must pass many things but i not have in this function how can doit ? exist somthing similar o library that do this ? thanks