Download MetaTrader 5
To add comments, please log in or register
Use MQL5 Cloud Network. Test robots at a super speed!
eric_mql5
106
eric_mql5 2011.11.18 07:03 

Hello Guys,

I am getting error 138 (requote) only in backtesting it looks to be fine in demo acount.

any clue?

here is my code:

#include <stdlib.mqh>
int ID = 1111;
bool ShortIsOpen;
bool LongIsOpen;
int ticket;
extern double Lots = 0.1;

int slippage = 3;
int order;
int to;

int init(){
   ShortIsOpen = false;
   LongIsOpen = false;
   order = 0;
   return(0);
  }

int deinit(){
      return(0);
  }

int start(){
      //housekeeping
      if(!LongIsOpen && !ShortIsOpen)
            ticket=-1;  
           
      //status 
      Comment(
      " ShortIsOpen=",ShortIsOpen,
      " LongIsOpen=",LongIsOpen,
      " TriggerShort()=",TriggerShort(),
      " TriggerLong()=", TriggerLong(),
      " CloseShort()=",CloseShort(),
      " CloseLong()=",CloseLong(),
      " ticket=",ticket,
      " order=",order,
      " TimeCurrent()-to=",TimeCurrent()-to,
      );
      
      //closing orders
      if(ShortIsOpen || LongIsOpen){
       if(CloseShort()){
                        OrderClose(ticket,Lots,Ask,slippage,Black);
                        ShortIsOpen=false;
                        to = 0;
                        order--;
                        ticket=-1;
                        Print("short closed");
                     }
      if(CloseLong()){
                        OrderClose(ticket,Lots,Ask,slippage,Black);
                        LongIsOpen=false;
                        to = 0;
                        order--;
                        ticket=-1;
                        Print("long closed");
                     }
       }
      // end of closing 
      
      //Open Orders
      if(!ShortIsOpen && !LongIsOpen){
      if(TriggerShort()){
                  ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,slippage,0,0,"SMA",ID,0,Red);
                  if(ticket>0){
                     ShortIsOpen=true;
                     to=TimeCurrent();
                     order++;
                     Print("short triggered");
                  }else  Print("!ShortIsOpen && TriggerShort() OrderSend failed with error #:\t",GetLastError());
                  }
     
      if(TriggerLong()){
                  ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,0,0,"SMA",ID,0,Green);
                  if(ticket>0){
                     LongIsOpen = true;
                     to = TimeCurrent();
                     order++;
                     Print("long triggered");
                  }else  Print("!LongIsOpen && TriggerLong() OrderSend failed with error #:\t",GetLastError());
               }
               }
   return(0);
   }

bool TriggerShort(){
   bool rslt = false;
   //if trigger short logic is true, rslt = true
   return (!ShortIsOpen && true);
  
}
bool TriggerLong(){
   bool rslt = false;
   // if trigger long logic is true, rslt = true
   return (!LongIsOpen && rslt);
}
bool CloseShort(){ 
   bool rslt = false;
   // if close short logic is true, rslt= true
   return (ShortIsOpen && rslt);
}


bool CloseLong(){ 
   bool rslt =false
   // if close long logic is true, rslt = true
   return (LongIsOpen && rslt);
}



Ubzen
Moderator
5394
Ubzen 2011.11.18 07:42  
Here. More then likely, you had the wrong price.
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2011.11.18 08:39  
ciremql4:

Hello Guys,

I am getting error 138 (requote) only in backtesting it looks to be fine in demo acount.

I see where your problem is . . .

Where are you getting this error ? what part of your code is generating it ? if you had checked return values from ALL order transactions you would have a good idea of what was generating this error . .

whroeder1
13641
whroeder1 2011.11.18 13:49  
Not adjusting slippage for 5 digit broker.
partha
16
partha 2015.04.05 16:39  
thanx WHRoeder! thats precise the solution!
/
To add comments, please log in or register