when high volatility time,pending order problem

 

While in normal times does not have problems in pending orders.
During the time when the high volatility and pending order is not activated (invalid sl or tp) gives warning.

my ECN broker digits 5

minimum distance : 2 pips

please help me.

<ADDED BY MODERATOR>

 Price=Bid-Avarage*Point;  
      slprice=Price;                
      if (NormalizeDouble(Price,Digits)>        // If it is less than allowed
          NormalizeDouble(Bid-Min_Dist*Point,Digits))
        {                                       // For sellstop only!
         Price=Bid-Min_Dist*Point;              // No closer
         Alert("Changed the requested price: Price = ",Price);
        }
    
      SL=Price + Dist_SL*Point;          // Requested price of SL
      if (Dist_SL<Min_Dist)                     // If it is less than allowed
        {
         SL=Price + Min_Dist*Point;             // Requested price of SL
         Alert(" Increased the distance of SL = ",Min_Dist," pt");
         }
    
      TP=Price - Dist_TP*Point;          // Requested price of TP
      if (Dist_TP<Min_Dist)                     // If it is less than allowed
        {
         TP=Price - Min_Dist*Point;             // Requested price of TP
         Alert(" Increased the distance of TP  = ",Min_Dist," pt");
        }
     
      Alert("The request was sent to the server. Waiting for reply..");
       ticket=OrderSend(Symb, OP_SELLSTOP, lot, Bid-Avarage*Point,30, SL, TP);
 
akose:
ticket=OrderSend(Symb, OP_SELLSTOP, lot, Bid-Avarage*Point,30, SL, TP);


From the small piece of code that you posted, it doesn't look like you properly formatted the OrderSend().

https://docs.mql4.com/trading/ordersend


Providing your actual codebase would have been more helpful.


- CodeMonkey

 
  1. What part of EDIT your post was unclear? Why didn't you?
  2. You are doing everything in points. Not adjusting for 4/5 digit brokers
  3. Don't use NormalizeDouble
 
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property show_confirm


extern int Avarage = 70;
extern int Dist_SL =120;                             
extern int Dist_TP =300;
extern int slippage = 30;
extern double lot = 1.00;
extern double TrailingStop = 10;
extern double StopLoss = 12; // Set it to some value above 0 to activate stop-loss

double Prots=0.35; 
double slprice, byprice,Min_Dist,SL,TP, Price;
string zaman,set1,Symb ;
int h,m,s,k,l,i,a,x,z;

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()
{     
      Symb=Symbol(); 
      Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);// Min. distance
      double Min_Lot=MarketInfo(Symb,MODE_MINLOT);// Min. volume
      double Free   =AccountFreeMargin();       // Free Margin
      double One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);//Cost per 1 lot
      double Lot=MathFloor(Free*Prots/One_Lot/Min_Lot)*Min_Lot;// Lots                                         
      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; }
 }  
 
int start()                                   
{  
      zaman = TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
      trailingstop();
   while(true)                 
   {
     //--BUYSTOP------------------BUYSTOP-------------------BUYSTOP---------------
      RefreshRates();
       Price=Ask+Avarage*Point; 
       byprice=Price;
       
        if (Price<Ask+Min_Dist*Point)
        {                                       
         Price=Ask+Min_Dist*Point;              // No closer
         Alert("Changed the requested price: Price = ",Price);
        }
   
      SL=Price - (Dist_SL*Point);          // Requested price of SL
      if (Dist_SL<Min_Dist)                     // If it is less than allowed
        {
         SL=Price - (Min_Dist*Point);             // Requested price of SL
         Alert(" Increased the distance of SL = ",Min_Dist," pt");
        }
   
      TP=Price + Dist_TP*Point;          // Requested price of TP
      if (Dist_TP<Min_Dist)                     // If it is less than allowed
        {
         TP=Price + Min_Dist*Point;             // Requested price of TP
         Alert(" Increased the distance of TP  = ",Min_Dist," pt");
         }
      RefreshRates();
      Alert("The request was sent to the server. Waiting for reply..");
      int ticket=OrderSend(Symb, OP_BUYSTOP, lot, Ask+Avarage*Point,slippage,SL,TP );
      
   if (ticket>0) {   Alert ("Placed order BuyStop",ticket);  }     
    Sleep(1500);                     
      //SELLSTO-----------------SELLSTOP-----------------------------SELLSTOP-----------------------   
      RefreshRates();    
      Price=Bid-Avarage*Point;  
      slprice=Price;                
      if (Digits>Bid-Min_Dist*Point)
        {                                       // For sellstop only!
         Price=Bid-Min_Dist*Point;              // No closer
         Alert("Changed the requested price: Price = ",Price);
        }
     
      SL=Price + Dist_SL*Point;          // Requested price of SL
      if (Dist_SL<Min_Dist)                     // If it is less than allowed
        {
         SL=Price + Min_Dist*Point;             // Requested price of SL
         Alert(" Increased the distance of SL = ",Min_Dist," pt");
         }
    
      TP=Price - Dist_TP*Point;          // Requested price of TP
      if (Dist_TP<Min_Dist)                     // If it is less than allowed
        {
         TP=Price - Min_Dist*Point;             // Requested price of TP
         Alert(" Increased the distance of TP  = ",Min_Dist," pt");
        }
    
      Alert("The request was sent to the server. Waiting for reply..");
       ticket=OrderSend(Symb, OP_SELLSTOP, lot, Bid-Avarage*Point,slippage, SL, TP);
   
       if (ticket>0)                             //  Got it)
        {
         Alert ("Placed order Sellstop",ticket);
         break;                                 // Exit cycle                                
        }
       

      int Error=GetLastError();                 // Failed :(
      switch(Error)                             //  Overcomable errors
        {
         case 129:Alert("Invalid price. Retrying..");
            RefreshRates();                     // Update data
            continue;                           // At the next iteration
         case 135:Alert("The price has changed. Retrying..");
            RefreshRates();                     // Update data
            continue;                           // At the next iteration
         case 146:Alert("Trading subsystem is busy. Retrying..");
            Sleep(500);                         //  Simple solution
            RefreshRates();                     // Update data
            continue;                           // At the next iteration
        }
      switch(Error)                             
        {
         case 2 : Alert("Common error.");
            break;                              
         case 5 : Alert("Outdated version of the client terminal.");
            break;                              
         case 64: Alert("The account is blocked.");
            break;                              
         case 133:Alert("Trading fobidden");
            break;                              
         default: Alert("Occurred error ",Error);
        }
      break;                                    
     }

 for (int i =0; i < OrdersTotal(); i++) 
 { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
       if( OP_BUY == OrderType())   deletependingorder();    if(byprice>=Ask) for(z=0; z<0; z++)   deletependingorder();}
        if( OP_SELL == OrderType())  deletependingorder();   if(slprice<=Bid) { for(x=0; x<1 ; x++)   deletependingorder();}        
    }
  }
    return; 
//-----------------------------------------------------------------------------                                    

  int deletependingorder()
 {
    int i,a;
    int total = OrdersTotal();
    string comentario,par;
  for (i=total-1; i >=0; i--)
    {
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if (OrderType()==OP_BUY || OrderType()==OP_SELL)
     {
     for (a=total-1; a >=0; a--)
       {
        OrderSelect(a,SELECT_BY_POS,MODE_TRADES);
        comentario=OrderComment();
        par=StringSubstr(comentario,0,6);
       if(OrderType()==OP_SELLSTOP)// && comentario==Symbol())
         {
         OrderDelete(OrderTicket());
         Print("Deleting SELL_STOP"," Ordertype:",OrderType());
         return(1);
         }
 if(OrderType()==OP_BUYSTOP)// && par==Symbol())
   {
   OrderDelete(OrderTicket());
   Print("Deleting BUY_STOP"," Ordertype:",OrderType());
   return(1);
    }
   }
  }
 }
}
//------------------------------------------------------------------
int trailingstop()
{
  double PointValue;
  for (int i = 0; i < OrdersTotal(); i++) 
  {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      //Calculate the point value in case there are extra digits in the quotes
      if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.00001) PointValue = 0.0001;
      else if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.001) PointValue = 0.01;
      else PointValue = MarketInfo(OrderSymbol(), MODE_POINT);
      //Normalize trailing stop value to the point value
      double TSTP = TrailingStop * PointValue;
 
      if (OrderType() == OP_BUY)
      {
         if (Bid - OrderOpenPrice() > TSTP)
         {
            if (OrderStopLoss() < Bid - TSTP)
            {
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TSTP, OrderTakeProfit(), Red))
                  Print("Error setting Buy trailing stop: ", GetLastError());
            }
         }
         else if ((OrderStopLoss() != Bid - StopLoss * PointValue) && (StopLoss != 0) && (OrderStopLoss() == 0))
            if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - StopLoss * PointValue, OrderTakeProfit(), Red))
               Print("Error setting Buy stop-loss: ", GetLastError());
      }
      else if (OrderType() == OP_SELL)
      {
         if (OrderOpenPrice() - Ask > TSTP)
         {
            if ((OrderStopLoss() > Ask + TSTP) || (OrderStopLoss() == 0))
            {
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TSTP, OrderTakeProfit(), Red))
                  Print("Error setting Sell trailing stop: ", GetLastError());
            }
         }
         else if ((OrderStopLoss() != Ask + StopLoss * PointValue) && (StopLoss != 0) && (OrderStopLoss() == 0))
            if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + StopLoss * PointValue, OrderTakeProfit(), Red))
               Print("Error setting Sell stop-loss: ", GetLastError());
      }
        }
   return(0);
}
   

 

WHRoeder

I try compile 4/5 digit pip adjust but is not happen,also that ea normaly time good working i think is not problem digit section.

and again i cant compile normalize double section.

may you help me, I realy tired.thanks you

 
akose:

WHRoeder

I try compile 4/5 digit pip adjust but is not happen,also that ea normaly time good working i think is not problem digit section.

and again i cant compile normalize double section.

may you help me, I realy tired.thanks you


"i cant compile" doesn't tell us any useful information.

We're trying to help you.

What is the specific error message you get in your editor window when you compile?

 
"Car doesn't work" says nothing. Don't have the key? Didn't turn the key? Dead battery? Flat tire? Blown engine? Don't know how the shifter works (PICNIC?) There are no mind readers here.
 
sory about that,my fault slippage value is lower.