![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, I wrote an EA which can trade 1 to 3 Trades at a time on the same currency pair.
The code snippet below seems to calculate the Open Order profits okay but on close they are out by a few percent.
If I run one trade it is accurate.
Can anyone look at the code below and offer any advice?
for( tradeCount=0; tradeCount < OrdersTotal(); tradeCount++ )
{
if(!OrderSelect(tradeCount,SELECT_BY_POS))continue ;
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber01)TradeProfit01 = OrderProfit() + OrderCommission() + OrderSwap();
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber02)TradeProfit02 = OrderProfit() + OrderCommission() + OrderSwap();
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber03)TradeProfit03 = OrderProfit() + OrderCommission() + OrderSwap();
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber01)TradeProfit01 = OrderProfit() + OrderCommission() + OrderSwap();
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber02)TradeProfit02 = OrderProfit() + OrderCommission() + OrderSwap();
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber03)TradeProfit03 = OrderProfit() + OrderCommission() + OrderSwap();
}
I would like to be able to read the Profit displayed in the MT4 Account History and display it in an Alert().
Many thanks.