Download MetaTrader 5
To add comments, please log in or register
MQL5 Cloud Network speeds up calculations. Try it!
thili55
113
thili55 2014.05.03 03:26 
How is this possible? I'm getting a few ordermodify error 130 here and there even though I have my stoploss set to 0
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.05.03 03:28  
Show us your code. Please use SRC when posting the code.
thili55
113
thili55 2014.05.03 03:48  
double Pips()
  {
   double pips;
   pips=Point;
   int digit;
   digit=Digits();
   int DR;
   DR=digit%2;
   if(DR==1)
     {
      pips*=10;
     }
   return(pips);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Price()
  {
   string a;
   a=Symbol();
   double b;
   b=MarketInfo(a,MODE_BID);
   int c;
   c=Digits();
   double d;
   d=NormalizeDouble(b,c);
   return(d);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double StopLevel()
  {
   string a;
   a=Symbol();
   double b;
   b=MarketInfo(a,MODE_STOPLEVEL);
   int c;
   c=Digits();
   int d;
   d=c%2;
   double e;
   if(d==1)
     {
      e=b/10;
     }
   else
     {
      e=b;
     }
   return(e);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int SendBuy(double lot)
  {
   string s;
   s=Symbol();
   double l;
   l=lot;
   int ticket;
   ticket=OrderSend(s,OP_BUY,l,Ask,7,0,0,NULL,MagicNumber,0,clrBlue);
   if(ticket!=-1)
     {
      double sl;
      if(RealStopLoss>0)
        {
         double a;
         a=StopLevel();
         double b;
         b=MathMax(RealStopLoss,a);
         double c;
         c=Pips();
         sl=Ask-b*c;
        }
      else
        {
         sl=0;
        }
      double tp;
      if(TakeProfit>0)
        {
         double a;
         a=StopLevel();
         double b;
         b=MathMax(TakeProfit,a);
         double c;
         c=Pips();
         tp=Ask+b*c;
        }
      else
        {
         tp=0;
        }
      if((tp>0) || (sl>0))
        {
         bool a;
         a=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
         if(a==true)
           {
            double b;
            b=OrderOpenPrice();
            bool c;
            c=OrderModify(ticket,b,0,tp,0,clrNONE);
           }
        }
     }
   return(ticket);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int SendSell(double lot)
  {
   string s;
   s=Symbol();
   double l;
   l=lot;
   int ticket;
   ticket=OrderSend(s,OP_SELL,l,Bid,7,0,0,NULL,MagicNumber,0,clrRed);
   if(ticket!=-1)
     {
      double sl;
      if(RealStopLoss>0)
        {
         double a;
         a=StopLevel();
         double b;
         b=MathMax(RealStopLoss,a);
         double c;
         c=Pips();
         sl=Bid+b*c;
        }
      else
        {
         sl=0;
        }
      double tp;
      if(TakeProfit>0)
        {
         double a;
         a=StopLevel();
         double b;
         b=MathMax(TakeProfit,a);
         double c;
         c=Pips();
         tp=Bid-b*c;
        }
      else
        {
         tp=0;
        }
      if((tp>0) || (sl>0))
        {
         bool a;
         a=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
         if(a==true)
           {
            double b;
            b=OrderOpenPrice();
            bool c;
            c=OrderModify(ticket,b,0,tp,0,clrNONE);
           }
        }
     }
   return(ticket);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ModifyTP(double tp)
  {
   double a;
   a=tp;
   int b;
   b=OrdersTotal();
   for(int i=0;i<b;i++)
     {
      bool c;
      c=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(c==true)
        {
         string d;
         d=OrderSymbol();
         int e;
         e=OrderMagicNumber();
         string f;
         f=Symbol();
         bool g;
         g=((d==f) && (e==MagicNumber));
         double h;
         h=OrderTakeProfit();
         bool i2;
         i2=((g==true) && (h!=a));
         if(i2==true)
           {
            int j;
            j=OrderTicket();
            double k;
            k=OrderOpenPrice();
            //double l;
            //l=OrderStopLoss();
            double sl1;
        if(RealStopLoss>0)
        {
         double aa;
         aa=StopLevel();
         double bb;
         bb=MathMax(RealStopLoss,aa);
         double cc;
         cc=Pips();
         sl1=Ask-bb*cc;
        }
        else{
        sl1=0;}
            bool m;
            m=OrderModify(j,k,0,a,0,clrNONE);
           }
        }
     }
  }
thili55
113
thili55 2014.05.03 05:58  
It apparently is a TP issue, not a SL issue.
Keith Watford
Moderator
7958
Keith Watford 2014.05.03 06:01  

Your code is long-winded and very difficult to follow

i2=((g==true) && (h!=a));

You are comparing doubles and we have no idea whether a is normalised or not

Check that they differ by at least 1 Point.

Keith Watford
Moderator
7958
Keith Watford 2014.05.03 07:26  

Your code can be reduced greatly by not re-assigning values of existing variables to different variables. Use the original variable. It is then easier for others to follow. Not only that, but if you come back to the code in a months time, it will be easier for YOU to follow

void ModifyTP(double tp)
  {
   //double a;
   //a=tp;
   //int b;
   //b=OrdersTotal();
   for(int i=0;i<OrdersTotal();i++)
     {
      //bool c;
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      //if(c==true)
        {
         //string d;
         //d=OrderSymbol();
         //int e;
         //e=OrderMagicNumber();
         //string f;
         //f=Symbol();
         //bool g;
         //g=(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber);
         //double h;
         //h=OrderTakeProfit();
         //bool i2;
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && (OrderTakeProfit()!=tp))
         //if(i2==true)
           {
            //int j;
            //j=OrderTicket();
            //double k;
            //k=OrderOpenPrice();
            //double l;
            //l=OrderStopLoss();
            double sl1;
        if(RealStopLoss>0)
        {
         //double aa;
         //aa=StopLevel();
         //double bb;
         double bb=MathMax(RealStopLoss,StopLevel());
         //double cc;
         //cc=Pips();
         sl1=Ask-bb*Pips();
        }
        else{
        sl1=0;}
            bool m;
            m=OrderModify(OrderTicket(),OrderOpenPrice(),0,tp,0,clrNONE);
           }
        }
     }
  }

Not only that, none of the highlighted code is used.

So your many lines of code in the ModifyTP function can be reduced to

void ModifyTP(double tp)
  {
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && (OrderTakeProfit()!=tp))
           {
            bool m;
            m=OrderModify(OrderTicket(),OrderOpenPrice(),0,tp,0,clrNONE);
           }
     }
  }

much easier to read without having to keep looking back to see what variable a,j,k is etc

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.05.03 07:36  
Common logic mistakes. It's ok. I bet when he look at the code when he realized what he have done, he will be ROFL. XD
/
To add comments, please log in or register