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)
Thanks for your reply.
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
I tried with no succuss :(
You are completly right! Thanks
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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);
}}