This is an easy issue for any good programmer. You have to put in mind that when coding any EA don't rely OrdersTotal() command
to count the opened trades because every EA wants to differentiate between his orders and the others ...
Instead, use the following function ...
int CountTrades() { int cnt = 0; for (int i = OrdersTotal() - 1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) if (OrderType() == OP_SELL || OrderType() == OP_BUY) cnt++; } return (cnt); }
Also, an an other example, to check the profit for each EA (magic number) ... use a function such this ...
void SymbolProfit(string smbl){ int cnt, total; BuyProfit = 0; SellProfit = 0; total = OrdersTotal(); for(cnt=0; cnt<total; cnt++){ if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) if(OrderSymbol()==smbl && OrderMagicNumber()==Magic){ if(OrderType()==OP_BUY){ BuyProfit = BuyProfit + OrderProfit() + OrderCommission() + OrderSwap(); } if(OrderType()==OP_SELL){ SellProfit = SellProfit + OrderProfit() + OrderCommission() + OrderSwap(); } } } }
In the second code, we use OrdersTotal() to know the total opened orders in the account then we will check all those orders using
magic number ... so, no harm in that. Actually, we must to do that here.
The bottom line,
ALWAYS use magic number in all functions and try to split your code to as much as separate functions to
do a specific task. This task is easy to use magic number and make your code is easy to read and trace.
This is an easy issue for any good programmer. You have to put in mind that when coding any EA don't rely OrdersTotal() command
...Dear all,
Can somebody point me in the right direction to help me "split" different expert advisors when running on different charts?
The problem is that I currently use the check "if(PositionsTotal() == 0)" as before proceeding to my "OrderSend" section. But I want to split them, so that I can run multiple trades at once.
So in other words: How do I make an EA check that that specific EA currently has an active position?
I suspect I have to use something in the "MqlTradeResult" structure to refer to a deal or magic number, but I haven't been able to figure it out.
Help is very much appreciated!
You have to use PositionSelect().
There is only 1 position by symbol with MT5, if you want to work with multiple "trades" you have to work with deals, which is far from trivial.
Appreciate the feedback guys,
I tried using this article: https://www.mql5.com/en/articles/211
From what I've understand:
I issue an order --> to make a deal --> that results in a position.
But somewhere my SL and TP are stored. Deals cannot be modified, and a position can consist of multiple orders/deals, because everything combines in 1 position (per symbol).
But from what I see I can only modify PENDING orders, not finished ones, is this correct?
Is the trick to recall the volume and other parameters from your MQLTradeResult structure and modify PART of a position with for instance a new stoploss? Should that be a direction I'm looking in?
Thanks as always! =)

- 2011.02.01
- MetaQuotes Software Corp.
- www.mql5.com
Appreciate the feedback guys,
I tried using this article: https://www.mql5.com/en/articles/211
From what I've understand:
I issue an order --> to make a deal --> that results in a position.
But somewhere my SL and TP are stored. Deals cannot be modified, and a position can consist of multiple orders/deals, because everything combines in 1 position (per symbol).
But from what I see I can only modify PENDING orders, not finished ones, is this correct?
Is the trick to recall the volume and other parameters from your MQLTradeResult structure and modify PART of a position with for instance a new stoploss? Should that be a direction I'm looking in?
Thanks as always! =)
I'll try to clarify:
My first EA: EA#1, is creating a position volume EURUSD of 0.5 Lots, with a ST and TP at 20 Pips
Then EA#2 is making it's own trade, let's say 1 Lot EURUSD with a ST and TP at 50 Pips.
What I want to do is make EA#1 run a trailing stop function that modifies the SL of the first 0.5 Lots, without touching the 1Lot that is using the 50Pips value.
I'll try to clarify:
My first EA: EA#1, is creating a position volume EURUSD of 0.5 Lots, with a ST and TP at 20 Pips
Then EA#2 is making it's own trade, let's say 1 Lot EURUSD with a ST and TP at 50 Pips.
What I want to do is make EA#1 run a trailing stop function that modifies the SL of the first 0.5 Lots, without touching the 1Lot that is using the 50Pips value.
It's what I answered you previously :
Forum on trading, automated trading systems and testing trading strategies
Run multiple separate experts at once
Alain Verleyen, 2015.05.27 19:55
There is only 1 position by symbol with MT5, if you want to work with multiple "trades" you have to work with deals, which is far from trivial.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear all,
Can somebody point me in the right direction to help me "split" different expert advisors when running on different charts?
The problem is that I currently use the check "if(PositionsTotal() == 0)" as before proceeding to my "OrderSend" section. But I want to split them, so that I can run multiple trades at once.
So in other words: How do I make an EA check that that specific EA currently has an active position?
I suspect I have to use something in the "MqlTradeResult" structure to refer to a deal or magic number, but I haven't been able to figure it out.
Help is very much appreciated!