how to close specific orders?

 

lets say i have 3 currency pairs eur/usd, usd/jpy and usd/chf and running on them the same EA. how can i close all orders only on 1 chart?

i tried with these code, but didnt work out - it still closes all the orders on all charts...

anybody can help?


void string Symb=Symbol();


if(Total>0)
{for(i=Total-1; i>=0; i--)
{if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == TRUE)
if (OrderSymbol()== Symb){
{Pos=OrderType();
if(Pos==OP_BUY){Result=OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, CLR_NONE);}
if(Pos==OP_SELL){Result=OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, CLR_NONE);}
if((Pos==OP_BUYSTOP)||(Pos==OP_SELLSTOP)||(Pos==OP_BUYLIMIT)||(Pos==OP_SELLLIMIT)){Result=OrderDelete(OrderTicket(), CLR_NONE);}

if(Result!=true){Error=GetLastError();Print("LastError = ",Error);}
else Error=0;

}
}
}
}
return(0);
}

 
please use the [SRC] button to post code snippets here in the forum. It is unreadable if the formatting is messed up like this and you certainly don't want your readers to spend 5 minutes only to decipher and clean up the mess until they can even begin searching for the problem.
 
void string Symb=Symbol();

where do you have this syntax from, what do you expect from putting the void in front of the variable declaration? Does this even compile?

 

I believe you can use MagicNumber with this purpose.

Do the following:

1. Create extern variable ExpertMagicNumber

2. In your check function add code like this:

if ( OrderMagicNumber() == ExpertMagicNumber ) { /*...close position...*/ }
else { continue; }

3. When you open a position with OrderSend function use ExpertMagicNumber to pass a unique value to each expert, for ex:

OrderSend( symbol, cmd, volume, price, slippage, stoploss, takeprofit, NULL, ExpertMagicNumber ) 

4. Now for each instance of you EA use different magic number.

As a result each EA will control only it's own positions.

 
hasayama:

I believe you can use MagicNumber with this purpose.

Do the following:

1. Create extern variable ExpertMagicNumber

2. In your check function add code like this:

3. When you open a position with OrderSend function use ExpertMagicNumber to pass a unique value to each expert, for ex:

4. Now for each instance of you EA use different magic number.

As a result each EA will control only it's own positions.


Thnx hasayama - it works very well.. was a nice idea..