err_requote problem - any help will do

 

Hi everyone,

I get error 138 will examine my code,

trying to place an order execute my code on the strategy tester with data about the last 2 days,

I wrote to log the parameters and that what I get :

OrderSend Function failed with error # 138
Error Description : requote

OrderSend Function parameters are
Bid Price : 130.47900000
Ask Price : 130.52000000
Point Is : 0.00100000
StopLoss Is : 1500
TakeProfit Is : 1500
dSellStopLoss Is : 131.97900000
dSellTakeProfit Is : 128.97900000

I was reading about this error in the documentation and on the forum but didn't find solution to this problem,

the code that create this look like that :

if(OpenPositionOK("BUY"))
{
double dBuyStopLoss = Ask - (StopLoss * Point);
double dBuyTakeProfit = Ask + (TakeProfit * Point);

ticket = OrderSend ( Symbol(), OP_BUY, Lots, PRICE_CLOSE, Slippage, dBuyStopLoss, dBuyTakeProfit, NULL, 0, 0, Green ) ;

if(ticket<0)
{ ........ }

iTradeSignal = iBuy ;
}
else if(OpenPositionOK("SELL"))
{
double dSellStopLoss = Bid + (StopLoss * Point);
double dSellTakeProfit = Bid - (TakeProfit * Point);

ticket = OrderSend ( Symbol(), OP_SELL, Lots, PRICE_CLOSE, Slippage, dSellStopLoss, dSellTakeProfit, NULL, 0, 0, Blue ) ;

if(ticket<0)
{ ........ }

Any help will be very appreciate,

me.

 

ERR_REQUOTE 138 The requested price has become out of date or bid and ask prices have been mixed up. The data can be refreshed without any delay using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

errors list

 
qjol:

ERR_REQUOTE 138 The requested price has become out of date or bid and ask prices have been mixed up. The data can be refreshed without any delay using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

errors list

Hi, Thank you for replaying, I read the error description and used the refreshrates function, still i get the same error, any other suggestions?

Thanks,

Meir.

 

change to

ticket = OrderSend ( Symbol(), OP_BUY, Lots,Ask , Slippage, dBuyStopLoss, dBuyTakeProfit, NULL, 0, 0, Green ) ;
ticket = OrderSend ( Symbol(), OP_SELL, Lots, Bid, Slippage, dSellStopLoss, dSellTakeProfit, NULL, 0, 0, Blue ) ;

PRICE_CLOSE is wrong

edit: I do not see where you define Slippage

& one more thing maybe u should send the order without SL & TP & use OrderModify() after OrderSend()

 

Thank you very much for your help, I've changed the priceclose to ask & bid and it worked.

I do not understand why do you think i should use ordermodify() instead of SL&TP? whats the logic after that?

thats my first code in MQL.

Thanks you again,

Meir.

 

There are many brokers that you can not send the SL TP with OrderSend()

 

O.K great thank you for the info, will you please help and show me how it should be written [ ticket = OrderSend ( Symbol(), OP_SELL, Lots, Bid, Slippage, dSellStopLoss, dSellTakeProfit, NULL, 0, 0, Blue ) ; ]
with the ordermodify(), I mean how do I open the order ?

 
meirgazit:

O.K great thank you for the info, will you please help and show me how it should be written [ ticket = OrderSend ( Symbol(), OP_SELL, Lots, Bid, Slippage, dSellStopLoss, dSellTakeProfit, NULL, 0, 0, Blue ) ; ]
with the ordermodify(), I mean how do I open the order ?


Try something like this:
ticket = OrderSend ( Symbol(), OP_BUY, Lots,Ask , Slippage, dBuyStopLoss, dBuyTakeProfit, NULL, 0, 0, Green ) ;
err = GetLastError();
if(err==ERR_INVALID_STOPS)
   {
   Print("This broker appears to use a bridge, retrying order send request");
   RefreshRates();
   ticket = OrderSend ( Symbol(), OP_BUY, Lots,Ask , Slippage, 0, 0, NULL, 0, 0, Green ) ;
   if(ticket!=-1)
      {
      OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
      OrderModify(ticket, OrderOpenPrice(), dBuyStopLoss, dBuyTakeProfit, 0);
      }
   }
You'll need to insert the usual bevy of error traps and checks of course.
 

Thank you Phillip for your answare, will you take a look at the code I write and see if you can see something wrong with it?


//+------------------------------------------------------------------+
//|                                                        4x4.mq4   |
//|                                                       Meir Gazit |
//+------------------------------------------------------------------+
#property copyright "Meir Gazit"

#include  <stdlib.mqh>
// global
int ticket=0;        
//-------------------------
extern int TakeProfit = 15000 ; 
extern int StopLoss = 15000 ;   
extern int Slippage = 2 ;       
extern int Lots = 1;            
extern double dSpred = 0.01 ;   

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
StopLoss = AccountPercentStopPips(Symbol(), 0.05, 2);
Print("StopLoss : " + StopLoss);   
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   StartTrade();
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| custom functions                                                 |
//+------------------------------------------------------------------+


bool StartTrade()
{ 
   Print("StartTrade") ;
   if(ticket!=0) IfExitCoditionTrueStopTrade(); 
   else
   { 
      if(bFeasibility(OP_BUY))  { OrderPosition(OP_BUY); }
      if(bFeasibility(OP_SELL)) { OrderPosition(OP_SELL); }       
   }
   return(0);   
} 

void OrderPosition(int op)
{
   double   price;
   
   if(op==OP_BUY) price=Bid; else price=Ask;
   
   while(true)
   {
      ticket  = OrderSend ( Symbol() , op , Lots , price , Slippage , 0 , 0 , NULL , 0 , 0 , Blue  ) ;          
      OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+(StopLoss*Point),OrderOpenPrice()-(TakeProfit*Point),0,CLR_NONE);
      RefreshRatesOROrderPrint(); break;
   }
}
void RefreshRatesOROrderPrint()
{
   int iErrNumber=GetLastError(); 
   if(ticket<=0)
   {
      iErrNumber=GetLastError(); if(iErrNumber==134) return;
      Sleep(10000); RefreshRates();
   }
   else{ PlaySound("alert2.wav"); OrderSelect(ticket,SELECT_BY_TICKET); OrderPrint(); }
}

bool bFeasibility(int cmd)
{
   double ma_open   = iMA ( Symbol()  , Period() , 4  , 0 , MODE_EMA , MODE_OPEN  , 0  ) ;
   double ma_close  = iMA ( Symbol()  , Period() , 4  , 0 , MODE_EMA , MODE_CLOSE , 0  ) ;
   double ma_10     = iMA ( Symbol()  , Period() , 10 , 0 , MODE_EMA , MODE_OPEN  , 0  ) ;
   
   if(cmd == OP_BUY)
   {
      if  (( ma_open < ma_close ) && ( ma_open > ma_10 ) && ( ma_close > ma_10 )  && ( bIsSpredOK(ma_open, ma_close) )) return ( true );  else return ( false ) ; 
   }
   else  if(cmd == OP_SELL)
   { 
      if (( ma_open > ma_close ) && ( ma_open < ma_10 ) && ( ma_close < ma_10 )  && ( bIsSpredOK(ma_open, ma_close) )) return ( true );  else  return ( false ) ; 
   }
} 

bool bIsSpredOK(double maOpen, double maClose)
{
   double iTheSpred = MathAbs(maOpen-maClose);
   if(iTheSpred>=dSpred) { return(true);} else{return(false);}
}  

void IfExitCoditionTrueStopTrade()
{
   if(!bFeasibility(OrderType())) { OrderCloseManager(); }
}  

void OrderCloseManager()
{
   string   strErrorMessage;
   int      iTotalTrades = OrdersTotal();
   
   if(iTotalTrades==0) return;
   
   for(int pos=0;pos<iTotalTrades;pos++)
   {
      if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
      if(OrderSymbol() == Symbol()) OrderCloseExecutiv();
   }
}

void OrderCloseExecutiv()
{
   int      iErrorNumber,cmd;
   bool     bOrderCloseStatus;
   string   strErrorMessage;
   double   price;
   
   if(cmd==OP_BUY) price=Bid; else price=Ask;
   bOrderCloseStatus = OrderClose( OrderTicket(), OrderLots(), price, Slippage, Red );
   if( bOrderCloseStatus == false )
   {
     iErrorNumber = GetLastError();
     strErrorMessage = ErrorDescription(iErrorNumber); Print( "OrderClose Function Failed: ", strErrorMessage );
     return;
   } 
}

double AccountPercentStopPips(string symbol, double percent, double lots)
{
    double balance   = AccountBalance();
    double tickvalue = MarketInfo(symbol, MODE_TICKVALUE);
    double lotsize   = MarketInfo(symbol, MODE_LOTSIZE);
    double spread    = MarketInfo(symbol, MODE_SPREAD);

    double stopLossPips = percent * balance / (lots * lotsize * tickvalue) - spread;

    return (stopLossPips);
}

it do not genrte error but allso it do not create any orders, so I dont know if its working,

if you run t on the 12/10/2010 around 15:00 it should generate an order,

Thank you, any help will do.


meir.

 

use some Print() or Alert() to find out your problem

Reason: