expert trading more than one

 

can someone please help; how do i change the code below so that it only look at order in the market that it placed. so if i do other trades or another expert that it doesn't influence the expert below



SEma = iMA(NULL, 0, ShortEma, 0, MODE_EMA, PRICE_CLOSE, 0);
LEma = iMA(NULL, 0, LongEma, 0, MODE_EMA, PRICE_CLOSE, 0);
//----
static int isCrossed = 1;
isCrossed = Crossed (LEma, SEma);
//----
total = OrdersTotal();
if(total < 1)

{
if(isCrossed == 1)

{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 5, Ask - StopLoss*Point,
Ask + TakeProfit*Point, "Buy", 12345, 0, Green); prtAlert("GBP/USD: Buying");
if(ticket > 0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("BUY order opened : ", OrderOpenPrice());
}
else
Print("Error opening BUY order : ", GetLastError());
return(0);
}
if(isCrossed == 2)
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 5, Bid + StopLoss*Point,
Bid - TakeProfit*Point, "Sell", 12345, 0, Red); prtAlert("GBP/USD: Selling");
if(ticket > 0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("SELL order opened : ", OrderOpenPrice());
}
else
Print("Error opening SELL order : ", GetLastError());
return(0);
}
return(0);
}
//----
for(cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY)
{

if(TrailingStop > 0)
{
if(Bid - OrderOpenPrice() > Point*TrailingStop)
{
if(OrderStopLoss() < Bid - Point*TrailingStop)
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Bid - Point*TrailingStop,
OrderTakeProfit(), 0, Green);
return(0);
}
}
}
}
else
{

if(TrailingStop > 0)
{
if((OrderOpenPrice() - Ask) > (Point*TrailingStop))
{
if((OrderStopLoss() > (Ask + Point*TrailingStop)) ||
(OrderStopLoss() == 0))
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + Point*TrailingStop,
OrderTakeProfit(), 0, Red);
return(0);
}
}
}
}
}
}
//----
return(0);
}

 
You have to use "Magic Number". You are opening orders passing 12345 as "Magic Number". This number helps you to identify the expert advisor. So you have to use this sequence wherever you check opened orders:

...
   for (int i = 0; i < OrdersTotal(); i++) {
      if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == false ) continue;
      if ( OrderSymbol() != Symbol() || OrderMagicNumber() != 12345 ) continue;
      ...