How can handle stopp loss with multi pairs for 4 open order at the same time?

 

Hi,

I have created a good working EA for 5 currency pairs. In general it works well, the EA open more then one order correctly with the right open, stop and take profit price. But if more then one order is open at the same time and the EA use the trailing function the SL was changed autom. in the wrong price from the other currency. I use in the trailing function the sub function marketinfo() to select the right pair and additonal the magic number.

For my understanding, the marketinfo() give not the correct ASK and BID price back, depending from the orderselection through the magic nummer.

WHAT I WILL DO IS TO CHANGE THE STOP LOSS WITH THE TRAILING STOP FROM THE CORRECT CURRENCY PAIR WHEN I HAVE MRE THEN ONE ORDER OPEN!

Can anyone help me?

void TrailingStairsEURJPYEP(int ticket,int trldistance)
{
if(OrderMagicNumber()==MagicNumberEURJPYEP || OrderSymbol()=="EURJPY")
{
double myAsk = MarketInfo(OrderSymbol(),MODE_ASK);
double myBid = MarketInfo(OrderSymbol(),MODE_BID);
int Spred=myAsk - myBid;

if (OrderType()==OP_BUY && OrderMagicNumber()==MagicNumberEURJPYEP)
{
if((myBid-OrderOpenPrice())>(Point*trldistance))
{
if(OrderStopLoss()<myBid-Point*trldistance || (OrderStopLoss()==0))
{
if (OrderSymbol()=="EURJPY")
{
OrderModify(OrderTicket(),OrderOpenPrice(),myBid-Point*trldistance,OrderTakeProfit(),0,Green);
}
}
}
}
if (OrderType()==OP_SELL && OrderMagicNumber()==MagicNumberEURJPYEP)
{
if((OrderOpenPrice()-myAsk)>(Point*trldistance))
{
if((OrderStopLoss()>(myAsk+Point*trldistance)) || (OrderStopLoss()==0))
{
if (OrderSymbol()=="EURJPY")
{
OrderModify(OrderTicket(),OrderOpenPrice(),myAsk+Point*trldistance,OrderTakeProfit(),0,Red);
}
}
}
}
}
}

 

S

Not sure how its working even on one pair - the order has to be selected by position or ticket

So usually you loop through the orders and check each one for 'what it is'

Try something like this - OTTOMH

int CheckActiveTradesForStopLoss(int iMagic, string strSymbol, int TrailingStop)
{
int icnt, itotal;
int max=0;

itotal=OrdersTotal();

   for(icnt=0;icnt<itotal;icnt++) 
     {                               // order loop boundary
      OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
       // check for opened position, symbol & MagicNumber
      if(OrderType()==OP_SELL && OrderSymbol()==strSymbol  && OrderMagicNumber()==iMagic)  
        { 
         if (OrderTicket()>max)  max=OrderTicket(); // Check for latest open ticket
         
         if (OrderStopLoss()==0)
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
             }    
        

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

        }
        
        
       if(OrderType()==OP_BUY && OrderSymbol()==strSymbol  && OrderMagicNumber()==iMagic)  
        { 
         if (OrderTicket()>max)  max=OrderTicket(); // Check for latest open ticket
            if (OrderStopLoss()==0)
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
             }
             
             if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                    }
                 }
              
        }

     }  // order loop boundary

return(max);
     
}

And call it with

CheckActiveTradesForStopLoss(MagicNumberEURJPYEP, "EURJPY", trldistance);

Good Luck

-BB-

 
BarrowBoy wrote >>

S

Not sure how its working even on one pair - the order has to be selected by position or ticket

So usually you loop through the orders and check each one for 'what it is'

Try something like this - OTTOMH

And call it with

Good Luck

-BB-

Ok Thanks, I changed the coding which you suggest. I will start testing again when market is open on moday because it is not possible to make backtest in MT4 for 5 currency pairs simultaneous which 3 open orders at the same time.

Regards

Christian

 

If you have no luck otherwise, PipBoxer.Com has a number of such small utilities that can work either on their own or in conjunction with other EAs to do things like this:

http://www.pipboxer.com/comparison.php

Reason: