error 4051 modify error

 
sir i got  A ERROR modify error 4051 in this...
int start()
  {
  int ticket;
if(OrdersTotal()==1)
{
   if(OrderSelect(0,SELECT_BY_POS))
   {     
      if(OrderType()==OP_BUYSTOP ||OrderType()==OP_SELLSTOP)
      OrderDelete(OrderTicket());
    } 
}

if(OrdersTotal()==0)
ticket=OrderSend(Symbol(),pot,0.01,Ask,3,0,0);

tp=OrderOpenPrice()+tpp*Point;   //int tpp=10,slp=20;
buyl=OrderOpenPrice();
selll=OrderOpenPrice()-tpp*Point;
sl=OrderOpenPrice()-slp*Point;


if(OrderSelect(0,SELECT_BY_POS))
{
OrderModify(ticket,OrderOpenPrice(),sl,tp,0,0);   <<<<here problem lies
}
 
ankit29030:
sir i got  A ERROR modify error 4051 in this...

If this fails . . .

ticket = OrderSend(Symbol(), pot, 0.01, Ask, 3, 0, 0);

 . . .  what happens with the following code ?

 

READ THIS and USE IT :   What are Function return values ? How do I use them ?

 
int start(){
  int ticket;

  if(OrdersTotal()==0) ticket=OrderSend(Symbol(),pot,0.01,Ask,3,0,0);

  OrderModify(ticket,OrderOpenPrice(),sl,tp,0,0);   <<<<here problem lies
  1. The first time through you open an order. Maybe.You DON'T CHECK. What are Function return values ? How do I use them ? - MQL4 forum
  2. The next time through OrdersTotal will be nonzero, so ticket REMAINS equal to zero and modify fails.
  3. Not adjusting for 4/5 digit brokers (tp, sl, AND slippage)
 
RaptorUK:

If this fails . . .

 . . .  what happens with the following code ?

 

READ THIS and USE IT :   What are Function return values ? How do I use them ?

 


invalid stoploss for order modify function..but my sl is 20pips down and take profit is 10 pips up..that is the thing..
 
WHRoeder:
  1. The first time through you open an order. Maybe.You DON'T CHECK. What are Function return values ? How do I use them ? - MQL4 forum
  2. The next time through OrdersTotal will be nonzero, so ticket REMAINS equal to zero and modify fails.
  3. Not adjusting for 4/5 digit brokers (tp, sl, AND slippage)

orderstotal is non zero as it places a buy order-i have checked that in journal...

should i place another variable instead of ticket??


and for most brokers minimum distance is 5 pips

Reason: