I have one question, pls help me.

1552

Hello all, I would like to know how to solve following problem.

1. One EA working on 20 Pair. EA open position with EAMagicNumber=5000. EA open only one position on lifetime. For example, If EA open one position ( EAMagicNumber=5000 ) on XAUUSD, then other pair can't open position with EAMagicNumber=5000. EA don't allow open position on other pair

I attach following code. But that code doesn't work. How do I solve that problem?

```for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
int chkA=OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if(OrderMagicNumber()==EAMagicNumber)
{
notAllow=true;
}
}
for(int j=OrdersTotal()-1;j>=0;j--)
{
if(OrderMagicNumber()==EAMagicNumber)
{
notAllow=true;
}
}```
23973

Erdenebayar Lamjav:

Hello all, I would like to know how to solve following problem.

1. One EA working on 20 Pair. EA open position with EAMagicNumber=5000. EA open only one position on lifetime. For example, If EA open one position ( EAMagicNumber=5000 ) on XAUUSD, then other pair can't open position with EAMagicNumber=5000. EA don't allow open position on other pair

I attach following code. But that code doesn't work. How do I solve that problem?

is this a separate function that returns the notAllow ?

1552

Lorentzos Roussos:

is this a separate function that returns the notAllow ?

No, I think notAllow is public variable. So it doesn't require return value.

```void FirstPositions()
{
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
int chkA=OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if(OrderMagicNumber()==EAMagicNumber)
{
notAllow=true;
}
}
for(int j=OrdersTotal()-1;j>=0;j--)
{
if(OrderMagicNumber()==EAMagicNumber)
{
notAllow=true;
}
}
}```
23243

So, once the global variable is set to true, it remains so forever.
1552

Yes, EA of other pair must disagree open more position. But still open position on all pair. I don't need multiple position each on of pairs. I need one single position during all pair on lifetime.
23973

William Roeder:
So, once the global variable is set to true, it remains so forever.

this .

try

```void FirstPositions()
{
static bool Allow=true;
//note : does OrdersHistoryTotal return entire history  ?
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
bool select=OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if(select){
if(OrderMagicNumber()==EAMagicNumber)
{
Allow=false;
}
}
}
for(int j=OrdersTotal()-1;j>=0;j--)
{
if(select){
if(OrderMagicNumber()==EAMagicNumber)
{
Allow=false;
}
}
}
}```
OrdersHistoryTotal - Trade Functions - MQL4 Reference
• docs.mql4.com
The number of closed orders in the account history loaded into the terminal. The history list size depends on the current settings of the "Account history" tab of the terminal.
23243

Lorentzos Roussos:

this .

try

1. Same thing; once the static is set to false, it remains that way forever. The static is internal to the function and can't ever be seen, thus is useless.
2. Delete the static and make the function return the result.
23973

William Roeder:
1. Same thing; once the static is set to false, it remains that way forever. The static is internal to the function and can't ever be seen, thus is useless.
2. Delete the static and make the function return the result.

indeed .

I did not know that .

The fact i could not use it outside its function should have given me a hint .

Thanks

3939

Lorentzos Roussos:

indeed .

I did not know that .

The fact i could not use it outside its function should have given me a hint .

Thanks

You search orders in history :)

so you can Just open One order with this magic number.

you have to search magic number in your opening orders/positions

```for ( int i = OrdersTotal() - 1; i >= 0; i--)
{
...
...```
1552

Tick movement very fast, so many position opened synchronization. Above code work only tick movement slowly. But I guess thank you your responses.
23973

Faeze Bakhshayesh:

You search orders in history :)

so you can Just open One order with this magic number.

you have to search magic number in your opening orders/positions

one loop ?