help with small modification to this script

 

Hi all,

Currently this code changes TP for all open orders (buy and sell) individually to 10 pips.

Appreciated if someone can modify it,,, to include all pending orders too ... (buy limit, buy stop, sell limit, sell stop)

Your guidance or support is appreciated.

Cheers



#property copyright "Copyright © 2011, Shoqi"
#property link      "s_25_z@hotmail.com"
#property show_inputs

extern bool     UseAverage = true;
extern int      OrderTP=10;
extern int      OrderSL=0;
extern double   OrderBuyTakeProfitPrice=0;
extern double   OrderBuyStopLossPrice=0;
extern double   OrderSellTakeProfitPrice=0;
extern double   OrderSellStopLossPrice=0;

int start()
{
   int x;
   string   OrdSymbol;
   int      OrdTotal;

   double   OrdBuyTotal;
   double   OrdBuyCount    = 0;
   double   OrdBuyAvareg;
   double   OrdBuyTP       = 0;
   double   OrdBuySL       = 0;

   double   OrdSellTotal;
   double   OrdSellCount   = 0;
   double   OrdSellAvareg;
   double   OrdSellTP      = 0;
   double   OrdSellSL      = 0;

   OrdTotal = OrdersTotal();
   
   if(UseAverage == true) 
   {
      for(x=OrdTotal-1 ; x>=0 ; x--)
      {
         OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
      
         if(OrderSymbol() == Symbol())
         {
           if(OrderType() == OP_BUY)
           {
              OrdBuyTotal = OrdBuyTotal + (OrderOpenPrice()*OrderLots());
              OrdBuyCount = OrdBuyCount + OrderLots();
           }
           else if(OrderType() == OP_SELL)
           {
              OrdSellTotal = OrdSellTotal + (OrderOpenPrice()*OrderLots());
              OrdSellCount = OrdSellCount + OrderLots();
           }
         }       
      }

      if(OrdBuyCount > 0)
      {
         OrdBuyAvareg = (OrdBuyTotal/OrdBuyCount);
     
         if(OrderTP!=0)
         OrdBuyTP = OrdBuyAvareg+(OrderTP*Point);
         else
         OrdBuyTP = 0;

         if(OrderSL!=0)
         OrdBuySL = OrdBuyAvareg-(OrderSL*Point);
         else
         OrdBuySL = 0;
      }
    
      if(OrdSellCount > 0)
      {
         OrdSellAvareg = (OrdSellTotal/OrdSellCount);
      
         if(OrderTP!=0)
         OrdSellTP = OrdSellAvareg-(OrderTP*Point);
         else
         OrdSellTP = 0;

         if(OrderSL!=0)
         OrdSellSL = OrdSellAvareg+(OrderSL*Point);
         else
         OrdSellSL = 0;
      }
   }
   else
   {
      OrdBuyTP    = OrderBuyTakeProfitPrice;
      OrdBuySL    = OrderBuyStopLossPrice;
      OrdSellTP   = OrderSellTakeProfitPrice;
      OrdSellSL   = OrderSellStopLossPrice;
   }
    
  // Modify Orders  
  for(x=OrdTotal-1 ; x>=0 ; x--)
  {
    OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
    
    if(OrderSymbol() == Symbol())
    {
      if(OrderType()==OP_BUY)
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdBuySL,OrdBuyTP,0,CLR_NONE);
      }

      if(OrderType()==OP_SELL) 
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdSellSL,OrdSellTP,0,CLR_NONE);
      }
      
    }
  }
  
  return(0);
}

 

Learn to do something self

  // Modify Orders  
  for(x=OrdTotal-1 ; x>=0 ; x--)
  {
    OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
    
    if(OrderSymbol() == Symbol())
    {
      if(OrderType()==OP_BUY)
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdBuySL,OrdBuyTP,0,CLR_NONE);
      }

      if(OrderType()==OP_SELL) 
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdSellSL,OrdSellTP,0,CLR_NONE);
      }
      
    }
  }

It is only modifie the trades with the same symbol as the chart where it is attached

to modifie the pending trades of same symbol you have to select those also and modifie it like the buy and sell

 

oK, I'v modified it, but doesn't do what i want it to do!




#property copyright "Copyright © 2011, Shoqi"
#property link      "s_25_z@hotmail.com"
#property show_inputs

extern bool     UseAverage = true;
extern int      OrderTP=10;
extern int      OrderSL=0;
extern double   OrderBuyTakeProfitPrice=0;
extern double   OrderBuyStopLossPrice=0;
extern double   OrderSellTakeProfitPrice=0;
extern double   OrderSellStopLossPrice=0;


extern double   OrderBuyS_TakeProfitPrice=0;
extern double   OrderBuyS_StopLossPrice=0;
extern double   OrderSellS_TakeProfitPrice=0;
extern double   OrderSellS_StopLossPrice=0;

extern double   OrderBuyL_TakeProfitPrice=0;
extern double   OrderBuyL_StopLossPrice=0;
extern double   OrderSellL_TakeProfitPrice=0;
extern double   OrderSellL_StopLossPrice=0;

int start()
{
   int x;
   string   OrdSymbol;
   int      OrdTotal;

   double   OrdBuyTotal;
   double   OrdBuyCount    = 0;
   double   OrdBuyAvareg;
   double   OrdBuyTP       = 0;
   double   OrdBuySL       = 0;

   double   OrdSellTotal;
   double   OrdSellCount   = 0;
   double   OrdSellAvareg;
   double   OrdSellTP      = 0;
   double   OrdSellSL      = 0;
   
    double   OrdSellLTotal;
   double   OrdSellLCount   = 0;
   double   OrdSellLAvareg;
   double   OrdSellLTP      = 0;
   double   OrdSellLSL      = 0;
   
    double   OrdSellSTotal;
   double   OrdSellSCount   = 0;
   double   OrdSellSAvareg;
   double   OrdSellSTP      = 0;
   double   OrdSellSSL      = 0;
   
    double   OrdBuySTotal;
   double   OrdBuySCount   = 0;
   double   OrdBuySAvareg;
   double   OrdBuySTP      = 0;
   double   OrdBuySSL      = 0;
   
    double   OrdBuyLTotal;
   double   OrdBuyLCount   = 0;
   double   OrdBuyLAvareg;
   double   OrdBuyLTP      = 0;
   double   OrdBuyLSL      = 0;

   OrdTotal = OrdersTotal();
   
   if(UseAverage == true) 
   {
      for(x=OrdTotal-1 ; x>=0 ; x--)
      {
         OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
      
         if(OrderSymbol() == Symbol())
         {
           if(OrderType() == OP_BUY)
           {
              OrdBuyTotal = OrdBuyTotal + (OrderOpenPrice()*OrderLots());
              OrdBuyCount = OrdBuyCount + OrderLots();
           }
           else if(OrderType() == OP_SELL)
           {
              OrdSellTotal = OrdSellTotal + (OrderOpenPrice()*OrderLots());
              OrdSellCount = OrdSellCount + OrderLots();
           }
             else if(OrderType() == OP_SELLLIMIT)
           {
              OrdSellLTotal = OrdSellLTotal + (OrderOpenPrice()*OrderLots());
              OrdSellLCount = OrdSellLCount + OrderLots();
           }
             else if(OrderType() == OP_SELLSTOP)
           {
              OrdSellSTotal = OrdSellSTotal + (OrderOpenPrice()*OrderLots());
              OrdSellSCount = OrdSellSCount + OrderLots();
           }
             else if(OrderType() == OP_BUYLIMIT)
           {
              OrdBuyLTotal = OrdBuyLTotal + (OrderOpenPrice()*OrderLots());
              OrdBuyLCount = OrdBuyLCount + OrderLots();
           }
             else if(OrderType() == OP_BUYSTOP)
           {
              OrdBuySTotal = OrdBuySTotal + (OrderOpenPrice()*OrderLots());
              OrdBuySCount = OrdBuySCount + OrderLots();
           }
           
         }       
      }

      if(OrdBuyCount > 0)
      {
         OrdBuyAvareg = (OrdBuyTotal/OrdBuyCount);
     
         if(OrderTP!=0)
         OrdBuyTP = OrdBuyAvareg+(OrderTP*Point);
         else
         OrdBuyTP = 0;

         if(OrderSL!=0)
         OrdBuySL = OrdBuyAvareg-(OrderSL*Point);
         else
         OrdBuySL = 0;
      }
    
      if(OrdSellCount > 0)
      {
         OrdSellAvareg = (OrdSellTotal/OrdSellCount);
      
         if(OrderTP!=0)
         OrdSellTP = OrdSellAvareg-(OrderTP*Point);
         else
         OrdSellTP = 0;

         if(OrderSL!=0)
         OrdSellSL = OrdSellAvareg+(OrderSL*Point);
         else
         OrdSellSL = 0;
      }
      
      
      
      if(OrdSellSCount > 0)
      {
         OrdSellSAvareg = (OrdSellSTotal/OrdSellSCount);
      
         if(OrderTP!=0)
         OrdSellSTP = OrdSellSAvareg-(OrderTP*Point);
         else
         OrdSellSTP = 0;

         if(OrderSL!=0)
         OrdSellSSL = OrdSellSAvareg+(OrderSL*Point);
         else
         OrdSellSSL = 0;
      }
      
      
      if(OrdSellLCount > 0)
      {
         OrdSellLAvareg = (OrdSellLTotal/OrdSellLCount);
      
         if(OrderTP!=0)
         OrdSellLTP = OrdSellLAvareg-(OrderTP*Point);
         else
         OrdSellLTP = 0;

         if(OrderSL!=0)
         OrdSellLSL = OrdSellLAvareg+(OrderSL*Point);
         else
         OrdSellLSL = 0;
      }
      
       if(OrdBuySCount > 0)
      {
         OrdBuySAvareg = (OrdBuySTotal/OrdBuySCount);
     
         if(OrderTP!=0)
         OrdBuySTP = OrdBuySAvareg+(OrderTP*Point);
         else
         OrdBuySTP = 0;

         if(OrderSL!=0)
         OrdBuySSL = OrdBuySAvareg-(OrderSL*Point);
         else
         OrdBuySSL = 0;
      }
    
       if(OrdBuyLCount > 0)
      {
         OrdBuyLAvareg = (OrdBuyLTotal/OrdBuyLCount);
     
         if(OrderTP!=0)
         OrdBuyLTP = OrdBuyLAvareg+(OrderTP*Point);
         else
         OrdBuyLTP = 0;

         if(OrderSL!=0)
         OrdBuyLSL = OrdBuyLAvareg-(OrderSL*Point);
         else
         OrdBuyLSL = 0;
      }
    
   }
   else
   {
      OrdBuyTP    = OrderBuyTakeProfitPrice;
      OrdBuySL    = OrderBuyStopLossPrice;
      OrdSellTP   = OrderSellTakeProfitPrice;
      OrdSellSL   = OrderSellStopLossPrice;
     
      OrdBuySTP    = OrderBuyS_TakeProfitPrice;
      OrdBuySSL    = OrderBuyS_StopLossPrice;
      OrdSellSTP   = OrderSellS_TakeProfitPrice;
      OrdSellSSL   = OrderSellS_StopLossPrice;
      OrdBuyLTP    = OrderBuyL_TakeProfitPrice;
      OrdBuyLSL    = OrderBuyL_StopLossPrice;
      OrdSellLTP   = OrderSellL_TakeProfitPrice;
      OrdSellLSL   = OrderSellL_StopLossPrice;
   }
    
  // Modify Orders  
  for(x=OrdTotal-1 ; x>=0 ; x--)
  {
    OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
    
    if(OrderSymbol() == Symbol())
    {
      if(OrderType()==OP_BUY)
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdBuySL,OrdBuyTP,0,CLR_NONE);
      }

      if(OrderType()==OP_SELL) 
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdSellSL,OrdSellTP,0,CLR_NONE);
      }
      
      if(OrderType()==OP_SELLLIMIT) 
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdSellLSL,OrdSellLTP,0,CLR_NONE);
      }
      
      if(OrderType()==OP_SELLSTOP) 
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdSellSSL,OrdSellSTP,0,CLR_NONE);
      }
      
      if(OrderType()==OP_BUYLIMIT) 
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdBuyLSL,OrdBuyLTP,0,CLR_NONE);
      }
      
      if(OrderType()==OP_BUYSTOP) 
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),OrdBuySSL,OrdBuySTP,0,CLR_NONE);
      }
      
      
      
      
      
      
    }
  }
  
  return(0);
}

 

This way ???

#property copyright "Copyright © 2011, Shoqi"
#property link      "s_25_z@hotmail.com"
#property show_inputs

//extern bool     UseAverage = true;     //Why is this needed
extern string prefix_currency = "";      //==> for Symbols like  xxxEURUSD
extern string suffix_currency = "";      //==> for Symbols like     EURUSDxxx
extern int      OrderTP=10;
extern int      OrderSL=0;
extern double   OrderBuyTakeProfitPrice=0;
extern double   OrderBuyStopLossPrice=0;
extern double   OrderSellTakeProfitPrice=0;
extern double   OrderSellStopLossPrice=0;


//extern double   OrderBuyS_TakeProfitPrice=0;
//extern double   OrderBuyS_StopLossPrice=0;
//extern double   OrderSellS_TakeProfitPrice=0;
//extern double   OrderSellS_StopLossPrice=0;

//extern double   OrderBuyL_TakeProfitPrice=0;
//extern double   OrderBuyL_StopLossPrice=0;
//extern double   OrderSellL_TakeProfitPrice=0;
//extern double   OrderSellL_StopLossPrice=0;

int start()
{
   int x;
   double   Points;         //insert this
   
   int      OrdTotal;   
   
/*   string   OrdSymbol;
   int      OrdTotal;

   double   OrdBuyTotal;
   double   OrdBuyCount    = 0;
   double   OrdBuyAvareg;
   double   OrdBuyTP       = 0;
   double   OrdBuySL       = 0;

   double   OrdSellTotal;
   double   OrdSellCount   = 0;
   double   OrdSellAvareg;
   double   OrdSellTP      = 0;
   double   OrdSellSL      = 0;
   
    double   OrdSellLTotal;
   double   OrdSellLCount   = 0;
   double   OrdSellLAvareg;
   double   OrdSellLTP      = 0;
   double   OrdSellLSL      = 0;
   
    double   OrdSellSTotal;
   double   OrdSellSCount   = 0;
   double   OrdSellSAvareg;
   double   OrdSellSTP      = 0;
   double   OrdSellSSL      = 0;
   
    double   OrdBuySTotal;
   double   OrdBuySCount   = 0;
   double   OrdBuySAvareg;
   double   OrdBuySTP      = 0;
   double   OrdBuySSL      = 0;
   
    double   OrdBuyLTotal;
   double   OrdBuyLCount   = 0;
   double   OrdBuyLAvareg;
   double   OrdBuyLTP      = 0;
   double   OrdBuyLSL      = 0;
*/   
   
   
   string  eurusd = (prefix_currency+"EURUSD"+suffix_currency);
   int digits=MarketInfo(eurusd,MODE_DIGITS);
      if(digits==5){Points=10;} else{Points=1;}   
   

   OrdTotal = OrdersTotal();
/*   
   if(UseAverage == true) 
   {
      for(x=OrdTotal-1 ; x>=0 ; x--)
      {
         OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
      
         if(OrderSymbol() == Symbol())
         {
           if(OrderType() == OP_BUY)
           {
              OrdBuyTotal = OrdBuyTotal + (OrderOpenPrice()*OrderLots());
              OrdBuyCount = OrdBuyCount + OrderLots();
           }
           else if(OrderType() == OP_SELL)
           {
              OrdSellTotal = OrdSellTotal + (OrderOpenPrice()*OrderLots());
              OrdSellCount = OrdSellCount + OrderLots();
           }
             else if(OrderType() == OP_SELLLIMIT)
           {
              OrdSellLTotal = OrdSellLTotal + (OrderOpenPrice()*OrderLots());
              OrdSellLCount = OrdSellLCount + OrderLots();
           }
             else if(OrderType() == OP_SELLSTOP)
           {
              OrdSellSTotal = OrdSellSTotal + (OrderOpenPrice()*OrderLots());
              OrdSellSCount = OrdSellSCount + OrderLots();
           }
             else if(OrderType() == OP_BUYLIMIT)
           {
              OrdBuyLTotal = OrdBuyLTotal + (OrderOpenPrice()*OrderLots());
              OrdBuyLCount = OrdBuyLCount + OrderLots();
           }
             else if(OrderType() == OP_BUYSTOP)
           {
              OrdBuySTotal = OrdBuySTotal + (OrderOpenPrice()*OrderLots());
              OrdBuySCount = OrdBuySCount + OrderLots();
           }
           
         }       
      }

      if(OrdBuyCount > 0)
      {
         OrdBuyAvareg = (OrdBuyTotal/OrdBuyCount);
     
         if(OrderTP!=0)
         OrdBuyTP = OrdBuyAvareg+(OrderTP*Point);
         else
         OrdBuyTP = 0;

         if(OrderSL!=0)
         OrdBuySL = OrdBuyAvareg-(OrderSL*Point);
         else
         OrdBuySL = 0;
      }
    
      if(OrdSellCount > 0)
      {
         OrdSellAvareg = (OrdSellTotal/OrdSellCount);
      
         if(OrderTP!=0)
         OrdSellTP = OrdSellAvareg-(OrderTP*Point);
         else
         OrdSellTP = 0;

         if(OrderSL!=0)
         OrdSellSL = OrdSellAvareg+(OrderSL*Point);
         else
         OrdSellSL = 0;
      }
      
      
      
      if(OrdSellSCount > 0)
      {
         OrdSellSAvareg = (OrdSellSTotal/OrdSellSCount);
      
         if(OrderTP!=0)
         OrdSellSTP = OrdSellSAvareg-(OrderTP*Point);
         else
         OrdSellSTP = 0;

         if(OrderSL!=0)
         OrdSellSSL = OrdSellSAvareg+(OrderSL*Point);
         else
         OrdSellSSL = 0;
      }
      
      
      if(OrdSellLCount > 0)
      {
         OrdSellLAvareg = (OrdSellLTotal/OrdSellLCount);
      
         if(OrderTP!=0)
         OrdSellLTP = OrdSellLAvareg-(OrderTP*Point);
         else
         OrdSellLTP = 0;

         if(OrderSL!=0)
         OrdSellLSL = OrdSellLAvareg+(OrderSL*Point);
         else
         OrdSellLSL = 0;
      }
      
       if(OrdBuySCount > 0)
      {
         OrdBuySAvareg = (OrdBuySTotal/OrdBuySCount);
     
         if(OrderTP!=0)
         OrdBuySTP = OrdBuySAvareg+(OrderTP*Point);
         else
         OrdBuySTP = 0;

         if(OrderSL!=0)
         OrdBuySSL = OrdBuySAvareg-(OrderSL*Point);
         else
         OrdBuySSL = 0;
      }
    
       if(OrdBuyLCount > 0)
      {
         OrdBuyLAvareg = (OrdBuyLTotal/OrdBuyLCount);
     
         if(OrderTP!=0)
         OrdBuyLTP = OrdBuyLAvareg+(OrderTP*Point);
         else
         OrdBuyLTP = 0;

         if(OrderSL!=0)
         OrdBuyLSL = OrdBuyLAvareg-(OrderSL*Point);
         else
         OrdBuyLSL = 0;
      }
    
   }
   else
   {
      OrdBuyTP    = OrderBuyTakeProfitPrice;
      OrdBuySL    = OrderBuyStopLossPrice;
      OrdSellTP   = OrderSellTakeProfitPrice;
      OrdSellSL   = OrderSellStopLossPrice;
     
      OrdBuySTP    = OrderBuyS_TakeProfitPrice;
      OrdBuySSL    = OrderBuyS_StopLossPrice;
      OrdSellSTP   = OrderSellS_TakeProfitPrice;
      OrdSellSSL   = OrderSellS_StopLossPrice;
      OrdBuyLTP    = OrderBuyL_TakeProfitPrice;
      OrdBuyLSL    = OrderBuyL_StopLossPrice;
      OrdSellLTP   = OrderSellL_TakeProfitPrice;
      OrdSellLSL   = OrderSellL_StopLossPrice;
   }
*/    
  // Modify Orders  
  for(x=OrdTotal-1 ; x>=0 ; x--)
   {
    OrderSelect(x,SELECT_BY_POS,MODE_TRADES);    
    if(OrderSymbol() == Symbol())
    {
      double OrdSL=0;
      double OrdTP=0;
      double pointt=(MarketInfo(OrderSymbol(),MODE_POINT)*Points);
      if((OrderType()==OP_BUY)||(OrderType()==OP_BUYLIMIT)||(OrderType()==OP_BUYSTOP))
         {
          if(OrderSL>0){OrdSL=OrderOpenPrice()-(OrderSL*pointt);}
          if(OrderTP>0){OrdTP=OrderOpenPrice()+(OrderTP*pointt);}
         }
      if((OrderType()==OP_SELL)||(OrderType()==OP_SELLLIMIT)||(OrderType()==OP_SELLSTOP)) 
         {
          if(OrderSL>0){OrdSL=OrderOpenPrice()+(OrderSL*pointt);}
          if(OrderTP>0){OrdTP=OrderOpenPrice()-(OrderTP*pointt);}      
         }
      if(OrderTakeProfit()!=OrdTP||OrderStopLoss()!=OrdSL)
         {OrderModify(OrderTicket(),OrderOpenPrice(),OrdSL,OrdTP,0,CLR_NONE);}      
    }
   }  
return(0);
}