ModifyOrder()

 
i am using a "Switch" function to modify the open order at each profit level,(each case # represents the amount of profit) however for some reason the ModifyOrder() function is not working, i have the order selected properly and i am entering the case function properly becuase when i take the actual modifyOrder operator that is supposed to change the stoploss and replace it with a Alert() the Alert() is working, so i am able to deduce that everything is working properly except for the way that i am using the ModifyOrder() function.

this is what my switch function from the EA i wrote looks like:


if(OrdersTotal() > 0 && OrderSelect(0, SELECT_BY_POS)==true && A==1)
{
switch(OrderProfit())
{
case 0 : OrderModify(OrderTicket(),OrderOpen Price(),OrderStopLoss()-4,OrderTakeProfit(),0,Blue); break;
case 1 : Alert ("profit is 1"); break;
case 2 : Alert ("profit is 2"); break;
case 3 : Alert ("profit is 3"); break;
case 4 : Alert ("profit is 4"); break;
case 5 : Alert ("profit is 5"); break;
case 6 : Alert ("profit is 6"); break;
case 7 : Alert ("profit is 7"); break;
case 8 : Alert ("profit is 8"); break;
case 9 : Alert ("profit is 9"); break;
case 10 : Alert ("profit is 10"); break;
case 11 : Alert ("profit is 11"); break;
}
................................... ................................... .




what am i doing wrong in the OrderModify()?


am i entering the ticket, openprice and stoploss wrong?


my EA only allows for a max of 1 order open at a time.


mabye someone could direct me to some literature that is very detailed about OrderModify() and OrderClose() i am prettysure i have read just about everything over at book.mql4.com and it didnt help me





 

UPDATE:


i just added the "get last error" fuction after the modify order that isnt working and i got error 4063 which means "integer parameter expected"

any ideas?
 

UPDATE #2:


and when i do this :

OrderModify(OrderTicket(),OrderOpen Price(),(OrderStopLoss()- 2),OrderTakeProfit(),Blue) ;

i get error 4051 which means "invalid function parameter value"


and when i change it to this :

OrderModify(OrderTicket(),OrderOpen Price(),(OrderStopLoss()+ 2),OrderTakeProfit(),Blue) ;

- all i did was change the subtraction sign to a addition sign-

and i get this error: 130 " invalid stops"

 

Your "2" needs to be in terms of price.

OrderModify(OrderTicket(),OrderOpen Price(),(OrderStopLoss()- 2),OrderTakeProfit(),Blue) ;

would be

OrderModify(OrderTicket(),OrderOpen Price(),(OrderStopLoss()- 2*Point),OrderTakeProfit(),Blue) ;

 

GEEZ how did i not realize that.


thanks phy.


now i have a new problem, when i am using switch i am using each case as a profit level and when my pre defined profit levels of B/e, +3, +7 etc are hit the SL moves up, my issue is, the SL is moving up with no problem, but if the prices pulls back again, and goes back to a previous profit level then the SL is lowered back down to what i wanted it at that level.


how can i prevent that?



- alex

 

By only moving the stop in the direction you want it to go.

For a long...

if Bid - NumberOfTrailingPipsDesired*Point > CurrentStopLossSetting then send an OrderModify with the new stopLoss setting at Bid - NumberOfTrailingPipsDesired*Point

 

I have a similar problem...I want to use a trailing stop in my EA and so I added this code, unfortunately it does not work, any ideas how I can fix it ? thanx (sorry if this is hijacking your thread Nikolaou, but its a similar theme to the problem im having. Hope you dont mind)


I get an error code for this code that says : " Unknown ticket 28 for ordermodification function" and " ordermodify error 4108"

please help.


//-------------------------TRAILING STOP CRITERIA-----------------------------------//
if (type==OP_BUY)
{
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
{
if(Bid-TrailingStop*Point> css-TrailingStop*Point)
{
OrderModify(ticket,price,Bid-TrailingStop*Point,0,Green);

return(0);
}
else if (type==OP_SELL)
{
OrderModify(ticket,price,Ask+TrailingStop*Point,0,Green);
return(0);
}
}
}

Reason: