OrderModify error 1

rghanmi
128

Hi all, 

hope you are ok.

i need your help to help me fix the OrderModify error 1 when using trailing stop.

i tried to compare new SL and old one with no succuss , your help will be so much appreciated. thanks

here is my code :

 double tStopLoss = NormalizeDouble(OrderStopLoss(), Digits);     

if(OrderType()==OP_BUY){

if(Ask> NormalizeDouble(OrderOpenPrice()+TrailingStart* myPoint,Digits) && tStopLoss < NormalizeDouble(Bid-(TrailingStop+TrailingStep)*myPoint,Digits)){

tStopLoss = NormalizeDouble(Bid-TrailingStop*myPoint,Digits);

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

}}


double sl = NormalizeDouble(OrderStopLoss(), Digits);

if (OrderType()==OP_SELL) {

if (Bid < NormalizeDouble(OrderOpenPrice()-TrailingStart*myPoint,Digits)&& (sl >(NormalizeDouble(Ask+(TrailingStop+TrailingStep)*myPoint,Digits)))|| (OrderStopLoss()==0)){

sl = NormalizeDouble(Ask+TrailingStop*myPoint,Digits);

OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Red);

}}

Mladen Rakic
257828
rg1983:

Hi all, 

hope you are ok.

i need your help to help me fix the OrderModify error 1 when using trailing stop.

i tried to compare new SL and old one with no succuss , your help will be so much appreciated. thanks

here is my code :

 double tStopLoss = NormalizeDouble(OrderStopLoss(), Digits);     

if(OrderType()==OP_BUY){

if(Ask> NormalizeDouble(OrderOpenPrice()+TrailingStart* myPoint,Digits) && tStopLoss < NormalizeDouble(Bid-(TrailingStop+TrailingStep)*myPoint,Digits)){

tStopLoss = NormalizeDouble(Bid-TrailingStop*myPoint,Digits);

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

}}


double sl = NormalizeDouble(OrderStopLoss(), Digits);

if (OrderType()==OP_SELL) {

if (Bid < NormalizeDouble(OrderOpenPrice()-TrailingStart*myPoint,Digits)&& (sl >(NormalizeDouble(Ask+(TrailingStop+TrailingStep)*myPoint,Digits)))|| (OrderStopLoss()==0)){

sl = NormalizeDouble(Ask+TrailingStop*myPoint,Digits);

OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Red);

}}

Order modify error means that the parameters you tried to apply did not make any change to the actual order

Simply check if the stop loss and/or take profit price will be changed or not at all compared to the existing stop loss and/or take profit of the selected order before trying to change the order (otherwise you shall get "error" 1 when those are exactly the same as they are already)

rghanmi
128
rghanmi  
Thanks for your reply.
In my case i modify only stop loss
I tried to compare new SL and old SL but error 1 appears again.
Any help to fix that working properly tick by tick thanks

Mladen Rakic
257828
rg1983:
Thanks for your reply.
In my case i modify only stop loss
I tried to compare new SL and old SL but error 1 appears again.
Any help to fix that working properly tick by tick thanks

You have to compare the values first and only then try to do the order modify

Like this (for example)

if (NormalizeDouble(Bid-TrailingStop*myPoint,_Digits)!=NormalizeDouble(OrderStopLoss(),_Digits) ... do the order modify
rghanmi
128
rghanmi  
I tried with no succuss :(
rghanmi
128
rghanmi  
You are completly right! Thanks
All is resolved. I have added the condition before all my orders modify in my code.thanks Mladen.
I have another issue. How can i fix the code so trailing stop will work tick by tick.
Because actually some profits become loss.
I use Void Ontick() function
Thanks
Mladen Rakic
257828
rg1983:
I tried with no succuss :(
I don't know the rest of your code, but if you use the solution posted here for the problem you have with order modification, you will not have "order modify error 1" any more
Mladen Rakic
257828
rg1983:
You are completly right! Thanks
All is resolved. I have added the condition before all my orders modify in my code.thanks Mladen.
I have another issue. How can i fix the code so trailing stop will work tick by tick.
Because actually some profits become loss.
I use Void Ontick() function. 
Thanks
If the EA is running normally, then the code for trailing stop is executed on each tick too (that is if you allow it from your code to do so)