Download MetaTrader 5

OrderModify Error#1 Bug or Not?

To add comments, please log in or register
Ubzen
5394
Ubzen  

Now why would this give OrderModify Error#1? Ea Attached.

//#################################################################
//#################################################################
double TrailingStop=20;
//#################################################################
//#################################################################
int start(){
//#################################################################
//#################################################################
double   Point_Info= MarketInfo(Symbol(),MODE_POINT);
double   Digit_Info= MarketInfo(Symbol(),MODE_DIGITS);
double   Stop_Info=  MarketInfo(Symbol(),MODE_STOPLEVEL);
int      Slippage=   MarketInfo(Symbol(),MODE_SPREAD);
//#################################################################
//#################################################################
//#---Normalize Prices:
double   Ask_Norm=NormalizeDouble(Ask,Digit_Info);
double   Bid_Norm=NormalizeDouble(Bid,Digit_Info);
//#################################################################
//#################################################################
static int Ticket;
if(OrderSelect(Ticket,SELECT_BY_TICKET)==true){
   for(int a=0;a<=Bars;a++){
      int Bar_Time=Time[a];
      if(Bar_Time<=OrderOpenTime()){int End_Bar=a;break;}
   }
}
//#################################################################
//#################################################################
double Minute1_Highest=High[iHighest(NULL,1,MODE_HIGH,End_Bar,0)];
double Highest_Norm=NormalizeDouble(Minute1_Highest,Digit_Info);
double Minute1_Lowest=High[iLowest(NULL,1,MODE_LOW,End_Bar,0)];
double Lowest_Norm=NormalizeDouble(Minute1_Lowest,Digit_Info);
double Dynamic_Stop_Buy=Highest_Norm-(TrailingStop*Point_Info);
double Dynamic_Stop_Sell=Lowest_Norm+(TrailingStop*Point_Info);
//#################################################################
//#################################################################
if(OrderType()==OP_BUY){
   if(OrderStopLoss()!=Dynamic_Stop_Buy){
      if(OrderStopLoss()==0 || Dynamic_Stop_Buy > OrderStopLoss()){
         if(Bid_Norm > Dynamic_Stop_Buy+(Stop_Info*Point_Info)){
            OrderModify(Ticket,OrderOpenPrice(),Dynamic_Stop_Buy,
            OrderTakeProfit(),0,Green);
         }
      }
   }
}
//#################################################################
//#################################################################
if(OrderType()==OP_SELL){
   if(OrderStopLoss()!=Dynamic_Stop_Sell){
      if(OrderStopLoss()==0 || Dynamic_Stop_Sell < OrderStopLoss()){
         if(Ask_Norm < Dynamic_Stop_Sell-(Stop_Info*Point_Info)){
            OrderModify(Ticket,OrderOpenPrice(),Dynamic_Stop_Sell,
            OrderTakeProfit(),0,Red);
         }
      }
   }
}
//#################################################################
//#################################################################
if(OrdersTotal()<1){
   Ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask_Norm,Slippage,0,0,
   "James_Bond",007,0,Green);
   /*Ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid_Norm,Slippage,0,0,
   "James_Bond",007,0,Red);*/
}
//#################################################################
//#################################################################
return(0);}
//#################################################################
//#################################################################
Files:
abcc.mq4 4 kb
Airat Safin
1300
Airat Safin  

https://www.mql5.com/en/forum/124153, "Error 1 and I don't know why"

Ubzen
5394
Ubzen  

I still don't get it :(

I've seen this error generated even when the new stoploss is equal to the old stoploss. With print statements.

OrderStopLoss() != Dynamic_Stop_Sell

I'd also ran into the thread where Gordon helped you fix it. But however I've never got order_modify to be error free.

 

The usual response I get for this error is because order modify is setting a value which already exist. If this is the case that does not explain why it dis-reguards the OrderStopLoss() != Dynamic_Stop_Sell and proceeds with the if statements when OrderStopLoss() is clearly (=)equal-to Dynamic_Stop_Sell.

 

Another reason could be because I'm entering the same Tp as what it already have. But I doubt that's the case as even the Documentation on order_modify uses the OrderTakeProfit() for tp.

 

If someone could please just add what missing within the above code so that it'll no longer generate error#1 within the back-tester I'll appreciate it. Because at this point I've checked everything I've heard of checking.

 

*NewStopLoss not equal to OldStopLoss.

*NewStopLoss > OldStopLoss

*NewStopLoss is Not within the StopLevel.

Kenneth Raymond Hubbard
151
Kenneth Raymond Hubbard  

Hi uzben,

Yup, you only get the error if nothing on the order is changed, so the same TP should have no effect.

I suspect your problem is that you should Normalise Dynamic_Stop_Buy(and sell).

You could try reversing the logic a bit and trouble shoot from there :-

if(OrderType()==OP_BUY){
   if(OrderStopLoss()==NormaliseDouble(Dynamic_Stop_Buy,Digit_Info))break;
   if(OrderStopLoss()==0 || Dynamic_Stop_Buy > OrderStopLoss()){
      if(Bid_Norm > Dynamic_Stop_Buy+(Stop_Info*Point_Info)){
         OrderModify(Ticket,OrderOpenPrice(),Dynamic_Stop_Buy,
         OrderTakeProfit(),0,Green);
      }
   }
}
Kenneth Raymond Hubbard
151
Kenneth Raymond Hubbard  

Actually, I am tearing my hair out with the same problem. NormaliseDouble hasn't fixed it and nor did the logic reverse.

I know the coding police will want to crucify me but I have used this simple workaround :-

if(GetLastError()==1)return(true);
The return(true) being the outcome of my OrderModify........aaarg!
Viffer
614
Viffer  

Personally, I only trail my stops on a full pip move and don't get error 1

try

if(Dynamic_Stop_Buy > OrderStopLoss()+1*Point_Info)
V
Ubzen
5394
Ubzen  

@kennyhubbard: Lol yep, if(GetLastError()==1)return(true); definitely crossed my mind. I'll go ahead and try V's method and report back on here.

 

@Viffer: if(Dynamic_Stop_Buy > OrderStopLoss()+1*Point_Info); if this is the answer, you'll save me some early gray hair. Thanks guys for your input. I can't test this right now. Will do later.

 

Edit: V's   if(Dynamic_Stop_Buy > OrderStopLoss()+1*Point_Info); totally SOLVED the problem :)

Brian Dee - Random Trader
1759
Brian Dee - Random Trader  

U

And now you have fixed it I suggest you change it!

Do you really want to stack your order channel by trailing every sub-pip..?

So if this is a sub-pip, consider moving it every 10 (i.e. 1 full pip...)

FWIW

-BB-

Ubzen
5394
Ubzen  

Oh, the piece of code is not designed for me. I programmed if for this thread. I don't know if it's sub-pip or not and wanted it to be flexible. I'm doing these script like EA to practice my bullet-proof coding (one size fits all). I'll leave that up to the user to decide.

On another note -BB- what do you think of my Pip/Point implementation Here

Viffer
614
Viffer  
ubzen:

@kennyhubbard: Lol yep, if(GetLastError()==1)return(true); definitely crossed my mind. I'll go ahead and try V's method and report back on here.

@Viffer: if(Dynamic_Stop_Buy > OrderStopLoss()+1*Point_Info); if this is the answer, you'll save me some early gray hair. Thanks guys for your input. I can't test this right now. Will do later.

Edit: V's if(Dynamic_Stop_Buy > OrderStopLoss()+1*Point_Info); totally SOLVED the problem :)

I'm glad it worked out... yeah... I am assuming Point_Info makes that 1 pip. (presumably you would have just used Point if it wasn't)

V

whroeder1
14781
whroeder1  
ubzen:

I still don't get it :(

OrderStopLoss() != Dynamic_Stop_Sell

Don't not compare doubles for equality/inequality. Suppose SL=1.2345 and DSS=1.23450000001 They're not equal but you'll get a error 1.

if ( (Dynamic_Stop_Sell - OrderStopLoss()) >= Point ) // Now ok to move SL up
See Working with Doubles in MQL4
12
To add comments, please log in or register