Why this Ordermodify() not working?

 

Dear Friend,

I use below function for add Stoploss to my orders. Sometimes it work and add stoploss & sometime not working



double SL=100;

for (int l_pos_2 = OrdersTotal() - 1; l_pos_2 >= 0; l_pos_2--) {

OrderSelect(l_pos_2, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol()) {

if ( OrderSymbol() == Symbol() && OrderMagicNumber() == MgNumber ) {

if (OrderStopLoss()==0){

double SL1=Bid-Point*SL;

OrderModify(OrderTicket(), OrderOpenPrice(),SL1, OrderTakeProfit(),0,Blue);

Alert("10","symble1=", Symbol());

}

}

}

}


---------------------------------------------------------------------------------

This line not working always " OrderModify(OrderTicket(),

OrderOpenPrice(),SL1, OrderTakeProfit(),0,Blue);"


I add one Alert that shows my function working normally but ordermodify not modify my order.


Please help me for solve this problem.

Thanks.

 

Try this and see what error is reported.

double SL=100;

double SL1;

int error;

for (int l_pos_2 = OrdersTotal() - 1; l_pos_2 >= 0; l_pos_2--) {

OrderSelect(l_pos_2, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol()) {

if ( OrderMagicNumber() == MgNumber ) {

if (OrderStopLoss()==0){

if(OrderType() == OP_BUY){

SL1=Ask-SL*Point;

OrderModify(OrderTicket(), OrderOpenPrice(),SL1, OrderTakeProfit(),0,Blue);

error = GetLastError();

if(error != 0) Alert("Error at set stop loss for Long = ", error);

}

if(OrderType() == OP_SELL){

SL1=Bid+SL*Point;

OrderModify(OrderTicket(), OrderOpenPrice(),SL1, OrderTakeProfit(),0,Blue);

error = GetLastError();

if(error != 0) Alert("Error at set stop loss for Short = ", error);

}

}

}

}

}

 
If your broker uses 5 digit precision SL*Point will give you a 10 pip stoploss. Use MarketInfo(Symbol(),MODE_STOPLEVEL). If your stoploss is less than the stoplevel then you will not be able to place the new stop.
 
fxcourt:
If your broker uses 5 digit precision SL*Point will give you a 10 pip stoploss. Use MarketInfo(Symbol(),MODE_STOPLEVEL). If your stoploss is less than the stoplevel then you will not be able to place the new stop.

Let's follow Phy's advice and not jump the gun regarding the precise error. Yes, it may be a 130. However, if the SL were out by the factor of 10, we shouldn't really see it "working sometimes" as the original poster stated.


CB

 
fxcourt:
If your broker uses 5 digit precision SL*Point will give you a 10 pip stoploss. Use MarketInfo(Symbol(),MODE_STOPLEVEL). If your stoploss is less than the stoplevel then you will not be able to place the new stop.

Let's follow Phy's advice and not jump the gun regarding the precise error. Yes, it may be a 130. However, if the SL were out by the factor of 10, we shouldn't really see it "working sometimes" as the original poster stated.


CB