OrderModify error 130

 

I'm getting the 130 error on and off with the below code. I still can't wrap my head around the SL. My stoploss is based on high/low calculation at the time the order is placed, so I have to recalculate it by pulling up the order. My TakeProfit is 2 times my original Stoploss, hence TPMultiplier. Once the price passes the number of pips of the original StopLoss I'd like it to be reset to the openprice+1. It's a breakeven strategy to secure my positions. Any idea why this is erroring?


int TPMultiplier=2

int ticket=ReturnFirstTicket(Magic);

OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
if(OrderType()==OP_BUY)
{
if(TPMultiplier==2)
{
double buybreakeven1 = (((OrderTakeProfit() - OrderOpenPrice())*10000)/2);
if(Bid-OrderOpenPrice()>Point*buybreakeven1 && OrderStopLoss()!=OrderOpenPrice()+1*Point)
{
{
// -1 for Zulu so as to stop out with 1 pip profit
OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+1*Point,OrderTakeProfit(),0,Blue);
return(0);
}
}
}
 

i guess that a stoploss can only be a LOSS, not a Profit.

 
meikel:

i guess that a stoploss can only be a LOSS, not a Profit.

Er, surely not? A stop-loss or take-profit is ultimately just an order in the opposite direction to the opening order. The stop-loss level can be at any price relative to the open, above or below, subject to things like MODE_STOPLEVEL. For example, the basis of any vanilla trailing stop is to take out orders at a profit, using a stop-loss, if the order is currently in profit but the price then retraces by a certain amount.


The above code is somewhat obscured by the lack of indenting, and the fact that the number of { doesn't match the number of closing }. But, leaving that aside, I can't immediately see a problem with it. If I'm not missing something, then the problem seems likely to be in occasional situations where the "high/low calculation at the time the order is placed" leads to a very tight s/l and t/p, and the criteria for calling OrderModify() get triggered to within MODE_STOPLEVEL of the current price.

 
jjc:

Er, surely not? A stop-loss or take-profit is ultimately just an order in the opposite direction to the opening order. The stop-loss level can be at any price relative to the open, above or below, subject to things like MODE_STOPLEVEL. For example, the basis of any vanilla trailing stop is to take out orders at a profit, using a stop-loss, if the order is currently in profit but the price then retraces by a certain amount.


The above code is somewhat obscured by the lack of indenting, and the fact that the number of { doesn't match the number of closing }. But, leaving that aside, I can't immediately see a problem with it. If I'm not missing something, then the problem seems likely to be in occasional situations where the "high/low calculation at the time the order is placed" leads to a very tight s/l and t/p, and the criteria for calling OrderModify() get triggered to within MODE_STOPLEVEL of the current price.

OrderStopLoss()!=OrderOpenPrice()+1 tests if the stoploss is not exactly equal to the open price plus 1. Is that what you really want to test or do you want a greater than/less than test here? Just thinking out loud...

 

OrderStopLoss()!=OrderOpenPrice()+1 tests if the stoploss is not exactly equal to the open price plus 1. Is that what you really want to test or do you want a greater than/less than test here? Just thinking out loud...

Actually it was testing against one Point exactly. Floating point values may not be exact, so the test may fail, while OrderStopLoss() > OrderOpenPrice() would not.

Further on a 5 digit broker a point is 1/10 pip. Your *10000 will not work for JPY. Your X*Point wont work on 5 digit brokers if X is in pips.

OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+1*Point,OrderTakeProfit(),0,Blue);

This will fail as MODE_STOPLEVEL is usually like 3 pips (=30 IBFX 5 digit)

 
jjc:

Er, surely not?

thanks for the detailed explanation.

i dont use SL/TP in an ordersend (stealthmode etc), but your mentioning of mode_stoplevel is in the dricetion of what i am guessing.

Reason: