Trailling pending order EA's comflicting

 

Hi there

I have the 4 ea's that performing the same function, which is trail pending orders(they follow the open price).each one an order at specified distance the type of orders are the buy stop, sell stop, sell limit and buy limit.

Now if i launch one (e.g trail buy limit) EA of them on the chart it function properly, however if i launch another one it could be any (eg traill buy stop or trail buy limit or another trail buy limit) it now starts to malfunction, either the stop orders jump around or stay still.

may you please help me

Kind regards

Hloni

 

//+------------------------------------------------------------------+
//|                                           Trailing buy limit.mq4 |
//+------------------------------------------------------------------+
#property copyright    "R. Syam"
#property description  "Berbagi Strategi Forex Trading II"
#property description  "https://www.facebook.com/groups/397846790402999/"
#property description  "Empower Your Heart. Think Positively"
#property description  "Empower Your Life. Give Generously"

//--- input parameters
extern int       Distance     = 75;
extern double    Lots         = 0.01;
extern int       TakeProfit   = 150;
extern int       Slipage      = 30;
extern double    Magic        = 8932;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
    int i,cnt,ticketLong1;
    double targetLong1,_sl,_tp;
    cnt = OrdersTotal();
    ticketLong1    = 0;
    targetLong1    = 0;
    if (Distance != 0) targetLong1=Ask-Distance*Point;   
       
    for (i=0;i<cnt;i++)
    {
       if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
       {
          if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
          { 
            if (OrderType() == OP_BUY)
            {

               ticketLong1 = -1; // running order, do not make new one
            }
            
            if (OrderType() == OP_BUYLIMIT)
            {
                ticketLong1 = OrderTicket();
            
           }
         }
       }
    }
    
    //Print("Ticket Long = "+ticketLong+" ticketShort="+ticketShort);
   // Print("Target="+target+" ticket="+ticket);
    _tp = 0;
    if (Distance != 0)
    {
      if (ticketLong1 == 0)
      {
          if (TakeProfit != 0) _tp = targetLong1+TakeProfit*Point;     
           Print("OrderSend BUY LIMIT: price="+targetLong1+" SL="+_sl+" tp="+_tp);
          ticketLong1 = OrderSend(Symbol(),OP_BUYLIMIT,Lots,targetLong1,Slipage,_sl,_tp,"Follow",Magic,0,CLR_NONE);
          if (ticketLong1 < 0) Print("Order Failed with");
      }
      if (ticketLong1 != -1)
      {
       if (targetLong1 > OrderOpenPrice())
       {
           if (TakeProfit != 0) _tp = targetLong1+TakeProfit*Point;     
           Print("Modify BUY LIMIT: price="+targetLong1+" SL="+_sl+" tp="+_tp);
           ticketLong1 = OrderModify(ticketLong1,targetLong1,_sl,_tp,OrderExpiration(),CLR_NONE);
           if (ticketLong1 < 0) Print("Order Failed with ");
       }
      }
      }


       
    
    //Print("Profit = "+totalProfit      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                            Trailing sell limit.mq4 |
//+------------------------------------------------------------------+
#property copyright    "R. Syam"
#property description  "Berbagi Strategi Forex Trading II"
#property description  "https://www.facebook.com/groups/397846790402999/"
#property description  "Empower Your Heart. Think Positively"
#property description  "Empower Your Life. Give Generously"

//--- input parameters
extern int       Distance     = 75;
extern double    Lots         = 0.01;
extern int       TakeProfit   = 150;
extern int       Slipage      = 30;
extern double    Magic        = 12356;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
    int i,cnt,ticketShort2;
    double targetShort2,_sl,_tp;
    cnt = OrdersTotal();
    ticketShort2   = 0;
    targetShort2   = 0;
    if (Distance != 0) targetShort2=Bid+Distance*Point;
    
       
    for (i=0;i<cnt;i++)
    {
       if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
       {
          if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
          { 
            if (OrderType() == OP_SELL)
            {

               ticketShort2 = -1; // running order, do not make new one
            }
            if (OrderType() == OP_SELLLIMIT)
            {
               ticketShort2 = OrderTicket();
               
            }

         }
       }
    }
    
    //Print("Ticket Long = "+ticketLong+" ticketShort="+ticketShort);
   // Print("Target="+target+" ticket="+ticket);
    _tp = 0;
   if (Distance != 0)
   {
      if (ticketShort2 == 0)
      {
          if (TakeProfit != 0) _tp = targetShort2-TakeProfit*Point;     
          Print("OrderSend SELL LIMIT: price="+targetShort2+" SL="+_sl+" tp="+_tp);
          ticketShort2 = OrderSend(Symbol(),OP_SELLLIMIT,Lots,targetShort2,Slipage,_sl,_tp,"Follow",Magic,0,CLR_NONE);
          if (ticketShort2 < 0) Print("Order Failed with");
      }
      else
      {
         if (ticketShort2 != -1)
         {
           if (targetShort2 < OrderOpenPrice())
           {
               if (TakeProfit != 0) _tp = targetShort2-TakeProfit*Point;     
               Print("Modify SELL LIMIT: price="+targetShort2+" SL="+_sl+" tp="+_tp);
               ticketShort2 = OrderModify(ticketShort2,targetShort2,_sl,_tp,OrderExpiration(),CLR_NONE);
               if (ticketShort2 < 0) Print("Order Failed with");
           }
         }
      }
       
    }
    
    //Print("Profit = "+totalProfit      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                            Trailing Buy Stop.mq4 |
//+------------------------------------------------------------------+
#property copyright    "R. Syam"
#property description  "Berbagi Strategi Forex Trading II"
#property description  "https://www.facebook.com/groups/397846790402999/"
#property description  "Empower Your Heart. Think Positively"
#property description  "Empower Your Life. Give Generously"

//--- input parameters
extern int       Distance     = 225;
extern double    Lots         = 0.01;
extern int       TakeProfit   = 9000;
extern int       Slipage      = 30;
extern double    Magic        = 85629;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
    int i,cnt,ticketLong6;
    double targetLong6,_sl,_tp;
    cnt = OrdersTotal();
    ticketLong6    = 0;
    targetLong6    = 0;
    if (Distance != 0) targetLong6=Bid+Distance*Point;
       
    for (i=0;i<cnt;i++)
    {
       if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
       {
          if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
          { 
            if (OrderType() == OP_BUY)
            {

               ticketLong6 = -1; // running order, do not make new one
            }
            
            if (OrderType() == OP_BUYSTOP)
            {
                ticketLong6 = OrderTicket();
            
           }
         }
       }
    }
    
    //Print("Ticket Long = "+ticketLong+" ticketShort="+ticketShort);
   // Print("Target="+target+" ticket="+ticket);
    _tp = 0;
   if (Distance != 0)
   {
      if (ticketLong6 == 0)
      {
           if (TakeProfit != 0) _tp = targetLong6+TakeProfit*Point;     
           Print("OrderSend BUY STOP: price="+targetLong6+" SL="+_sl+" tp="+_tp);
           ticketLong6 = OrderSend(Symbol(),OP_BUYSTOP,Lots,targetLong6,Slipage,_sl,_tp,"Follow",Magic,0,CLR_NONE);
           if (ticketLong6 < 0) Print("Order Failed with ");
       }
      if (ticketLong6 != -1)
      {
       if (targetLong6 < OrderOpenPrice())
       {
           if (TakeProfit != 0) _tp = targetLong6+TakeProfit*Point;     
           Print("Modify BUY STOP: price="+targetLong6+" SL="+_sl+" tp="+_tp);
           ticketLong6 = OrderModify(ticketLong6,targetLong6,_sl,_tp,OrderExpiration(),CLR_NONE);
           if (ticketLong6 < 0) Print("Order Failed with ");
       }
      }
       
    }
    
    //Print("Profit = "+totalProfit      
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
Maybe you combine it all into one and then select in the input parameter box which orders need to be handled that way you wont have 4 separare (conflicting) ea running at the same time.
 
Marco vd Heijden:
Maybe you combine it all into one and then select in the input parameter box which orders need to be handled that way you wont have 4 separare (conflicting) ea running at the same time.

Hi marco

at first i did combine and they conflicted, so i separated them and tried to vary the magic numbers and some parameters.the codes is prdefined similar i reckon there's one small twitch thats causing the conflict, but im having trouble identifying it hence the post.

Reason: