Best way to handle Requotes?

 

Hey everyone,


What is the best way to handle a requote within an EA? I set a deviation but to my understanding that only affects close orders. I need a way to have the EA retry opening an order if there is a requote.

I'm using RefreshRates() before every buy/sell order (trade.Buy/trade.Sell) but I still occasionally get requoted by as little as 1 pip and the order isn't opened.


Any direction on this would be greatly appreciated.

 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 

The best way is to use a broker which doesn't requote. That means which is using market execution.

Otherwise, with instant execution (used by dealing desk brokers), you can set a greater deviation (it affects open and close). And if you still have requote then just decide if you still want to open the trade or not.

Show your code if you need coding help.

 
tnil25: Any direction on this would be greatly appreciated.

Log it, return, wait for the next tick, retry the operation.

 
Keith Watford:
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.

Keith, this is for MQL5, not MQL4.

Alain - Heres my code for opening orders (options for risk and fixed lot) - its the same for buy/sell. I'm using the Metaquotes demo account right now and am routing my orders to MT4 for execution with Oanda. So the requote happens on the metaquotes side, Oanda wont pick it up if MT5 doesnt open the trade.

//--- Open BUY position
   if(m_need_open_buy)
     {
      if(InpRisk > 0) // Risk based order
        {
         if(!RefreshRates())
            return;
         //--- Get lot size for BUY position (CMoneyFixedRisk)
         double sl=0.0;
         double check_open_long_lot=0.0;
         //--- variant #1: StopLoss=0.0
         sl=0.0;
         check_open_long_lot=m_money.CheckOpenLong(m_symbol.Ask(),sl);
         Print("sl=0.0",
               ", CheckOpenLong: ",DoubleToString(check_open_long_lot,2),
               ", Balance: ",    DoubleToString(m_account.Balance(),2),
               ", Equity: ",     DoubleToString(m_account.Equity(),2),
               ", FreeMargin: ", DoubleToString(m_account.FreeMargin(),2));
         //--- variant #2: StopLoss!=0.0
         sl=m_symbol.Ask()-ExtStopLoss;
         check_open_long_lot=m_money.CheckOpenLong(m_symbol.Ask(),sl);
         Print("sl=",DoubleToString(sl,m_symbol.Digits()),
               ", CheckOpenLong: ",DoubleToString(check_open_long_lot,2),
               ", Balance: ",    DoubleToString(m_account.Balance(),2),
               ", Equity: ",     DoubleToString(m_account.Equity(),2),
               ", FreeMargin: ", DoubleToString(m_account.FreeMargin(),2));
         if(check_open_long_lot==0.0)
            return;

         //--- check volume before OrderSend to avoid "not enough money" error (CTrade)
         double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),check_open_long_lot,m_symbol.Ask(),ORDER_TYPE_BUY);

         if(check_volume_lot!=0.0)
            if(check_volume_lot>=check_open_long_lot)
              {
               m_trade.Buy(check_volume_lot,NULL,m_symbol.Ask(),m_symbol.Ask()-ExtStopLoss,m_symbol.Ask()+ExtStopLoss);
              }
        }
      else // Fixed lot order
        {
         if(!RefreshRates())
            return;
         //--- check volume before OrderSend to avoid "not enough money" error (CTrade)
         double free_margin_check=m_account.FreeMarginCheck(
                                     m_symbol.Name(), ORDER_TYPE_BUY, m_symbol.LotsMin(), m_symbol.Ask());

         double margin_check=m_account.MarginCheck(
                                m_symbol.Name(), ORDER_TYPE_BUY, m_symbol.LotsMin(), m_symbol.Ask());

         if(free_margin_check>margin_check)
           {
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY");
            m_trade.Buy(InpLotSize,m_symbol.Name(),m_symbol.Ask(),0,0,NULL);
           }
        }
      m_need_open_buy=false;
     }
 
William Roeder:

Log it, return, wait for the next tick, retry the operation.

This is what I was thinking, Should I grab the error code for a requote (TRADE_RETCODE_REQUOTE) and then have it loop back? Just wondering if this is the best way.

 
tnil25:

Keith, this is for MQL5, not MQL4.

Sorry, when I saw RefreshRates() which is not used in basic MQL5, I assumed that it must be MQL4.

I will move the topic again.

 
tnil25:

Keith, this is for MQL5, not MQL4.

Alain - Heres my code for opening orders (options for risk and fixed lot) - its the same for buy/sell. I'm using the Metaquotes demo account right now and am routing my orders to MT4 for execution with Oanda. So the requote happens on the metaquotes side, Oanda wont pick it up if MT5 doesnt open the trade.

Huh ? What's the point to use Metaquotes demo account ? It's useless and unreliable for production code.
 
The problem is there's currently no trusted US brokers that support MT5 and I've already done all my programming and testing on MT5. The bridge I have between MT5 and MT4 works fine and the quotes I get between the two are near identical.
 
tnil25:
The problem is there's currently no trusted US brokers that support MT5 and I've already done all my programming and testing on MT5. The bridge I have between MT5 and MT4 works fine and the quotes I get between the two are near identical.

There are trusted us brokers, search on google

 
amando:

There are trusted us brokers, search on google

I have done a lot of research, but I haven't found one that supports MT5 and are also properly regulated. The majority of brokers are overseas and don't take US clients.

Reason: