136: error "off quotes" and NormalizeDouble

 
I've been running into a 136 error frequently when my EA has been trying to place an order. What's this really all about? And apparently NormalizeDouble is an important part of the EA placing orders. I searched through my code and I'm not using NormalizeDouble. Could this be part of the problem?
 
MisterDog:
I've been running into a 136 error frequently when my EA has been trying to place an order. What's this really all about? And apparently NormalizeDouble is an important part of the EA placing orders. I searched through my code and I'm not using NormalizeDouble. Could this be part of the problem?
No. Do what the documentation tells you to do . . . . wait 5 seconds, do a RefreshRates() and then try again . . . if after 5 secs the trading opportunity has passed then abandon and wait for the next trade. Perhaps your Broker is a bit rubbish ?
 

It is NEVER necessary to use NormalizeDouble. EVER. It is a kludge. Don't use it. Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum and Can price != price ? - MQL4 forum

Are you adjusting for 4/5 digit brokers (SLIPPAGE) are you using the correct price to open.

 

Okay I won't use NormalizedDouble. I am using FXCM on EURUSD and GPBAUD which are both five digits. But I don't believe I'm doing anything in the code to be sure I'm always delivering exactly 5 digits to the broker. Slippage is set to three pips.

Here's the code that I inherited from a programmer sometime ago -- before I started learning to program on my own. I think I'll go back and add a Print statement to be sure how many digits I'm sending to the broker for each trade.

int EnterOrder(string BuyorSell)
{
   if (BuyorSell=="Buy")
   {
      if (TakeProfit!=0) 
         TP = Ask + TakeProfit*Point*10; 
         else TP=0;
      if (StopLoss!=0)   
         SL = Ask - StopLoss*Point*10; 
         else SL=0;
      OpenOrder ("Buy");
   }
   if (BuyorSell=="Sell")
   {  
      if (TakeProfit!=0) 
         TP = Bid - TakeProfit*Point*10; 
         else TP=0;
      if (StopLoss!=0)   
         SL = Bid + StopLoss*Point*10; 
         else SL=0;
      OpenOrder ("Sell");
   }
   return(0);
}
//------------------------
int OpenOrder(string OpOrd)
{
   double Risk = RiskPercent * 0.001;
   double DesiredRisk = Risk * AccountEquity();
   double RiskOfOneLot = StopLoss * MarketInfo(Symbol(), MODE_TICKVALUE);
   double Lot = DesiredRisk / RiskOfOneLot;

   int error,err;
   while (true)
   {  
      error=true;
      if (OpOrd=="Buy" ) 
         error=OrderSend(Symbol(),OP_BUY,Lot,Ask,Slippage,SL,TP,"",Magic,3,Green);
      if (OpOrd=="Sell") 
         error=OrderSend(Symbol(),OP_SELL,Lot,Bid,Slippage,SL,TP,"",Magic,3,Red);
      if (error==-1)
      {  
         ShowERROR();
         err++;
         Sleep(2000);
         RefreshRates();
      }
      if (error || err >10) return;
   }
   return (0);
}                  
//--------------
void ShowERROR()
{
   int err=GetLastError();
   switch ( err )
   {                  
      case 1:   return;
      default:  Alert("Error  " ,err," ",Symbol());return;
   }
}// End Place an Order
 
MisterDog:

I think I'll go back and add a Print statement to be sure how many digits I'm sending to the broker for each trade.

Make sure you use DoubleToStr or you will only get 4 digits . . .
 
WHRoeder: Are you adjusting for 4/5 digit brokers (SLIPPAGE) are you using the correct price to open.
MisterDog:
         TP = Ask + TakeProfit*Point*10; 
    error=OrderSend(Symbol(),OP_SELL,Lot,Bid,Slippage,SL,TP,"",Magic,3,Red);

But I don't believe I'm doing anything in the code to be sure I'm always delivering exactly 5 digits to the broker. Slippage is set to three pips.

I think I'll go back and add a Print statement to be sure how many digits I'm sending to the broker for each trade.

  1. You don't send ANY digits to the broker, you send prices, a double, infinite digits.
  2. "Slippage is set to three pips" Don't bother to show ALL the code with the declarations. If Slippage is set to 3 pips then you must have (extern) int Slippage=30; (5 digit broker, otherwise it is not.)
  3. Point*10 means you've adjusted for a 5 digit broker (other than slippage) but your EA will fail on a 4 digit. Adjust for 4/5 digit brokers. Also you WILL have to adjust for ECN brokers when you start getting error 130.
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){                                             OptInitialization();
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(..., 0,0,...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
           Alert("OrderModify failed: ", GetLastError());
         */
    

 

Ok, this could be a problem...

extern int StopLoss = 15;
extern int TakeProfit = 5;
extern int Slippage = 3; //Oops! Not adjusted for a 5 digit broker.

In this case my slippage would end up 0.3 which is way too small. This actually worked in a very quiet markets but failed as things picked up.

Thanks for the help!


Reason: