How to make it work on 5-digits?

 

Hello,

I found this code and it seems only working on 4-digits platform. I don't see a need to change this code but I know I missed something in the algorithm so it won't work on 5-digits platform. So, how to make this code work for 5-digits? Please help and thanks.

#define m  20050611
//----
extern int tp = 65;
extern int sh = 41;
//----
datetime lastt; 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int kol_buy()
  {
   int kol_ob = 0;
//----
   for(int i = 0; i < OrdersTotal(); i++)
     {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) 
           break;
       //----
       if(OrderType() == OP_BUY)  
           kol_ob++;
     }
   return(kol_ob);
  }    
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int kol_sell()
  {
   int kol_os = 0;
//----
   for(int i = 0; i < OrdersTotal(); i++)
     {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) 
           break;
       //----
       if(OrderType() == OP_SELL)  
           kol_os++;
     }
   return(kol_os);
  }  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int slip, i, ii, tic, total, kk, gle;
   double lotsi = 0.01;
   bool sob = false, sos = false, scb = false, scs = false;
   int kb, kb_max = 0;
   kb = kol_buy() + 1;
   double M_ob[11][8];
   ArrayResize(M_ob,kb);
   int ks = 0, ks_max = 0;
   ks = kol_sell() + 1;
   double M_os[11][8];
   ArrayResize(M_os,ks);
   ArrayInitialize(M_ob, 0.0);
   int kbi = 0;
//----
   for(i = 0; i < OrdersTotal(); i++)
     {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) 
           break;
       //----
       if(OrderSymbol() == Symbol() && OrderType() == OP_BUY)
         {
           kbi++;
           M_ob[kbi][0] = OrderTicket();
           M_ob[kbi][1] = OrderOpenPrice();
           M_ob[kbi][2] = OrderLots();
           M_ob[kbi][3] = OrderType();
           M_ob[kbi][4] = OrderMagicNumber();
           M_ob[kbi][5] = OrderStopLoss();
           M_ob[kbi][6] = OrderTakeProfit();
           M_ob[kbi][7] = OrderProfit();
         }
     } 
   M_ob[0][0] = kb; 
   double max_lot_b = 0.0;
//----
   for(i = 1; i < kb; i++)
       if(M_ob[i][2] > max_lot_b)
         {
           max_lot_b = M_ob[i][2];
           kb_max = i;
         }
   double buy_lev_min = M_ob[kb_max][1];   
   ArrayInitialize(M_os,0.0);
   int ksi = 0;
//----
   for(i = 0; i < OrdersTotal(); i++)
     {
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) 
           break;
       //----
       if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
         {
           ksi++;
           M_os[ksi][0] = OrderTicket();
           M_os[ksi][1] = OrderOpenPrice();
           M_os[ksi][2] = OrderLots();
           M_os[ksi][3] = OrderType();
           M_os[ksi][4] = OrderMagicNumber();
           M_os[ksi][5] = OrderStopLoss();
           M_os[ksi][6] = OrderTakeProfit();
           M_os[ksi][7] = OrderProfit();
         }
     } 
   M_os[0][0] = ks; 
   double max_lot_s = 0.0;
//----
   for(i = 1;i < ks; i++)
       if(M_os[i][2] > max_lot_s)
         {
           max_lot_s = M_os[i][2];
           ks_max = i;
         }
   double sell_lev_max = M_os[ks_max][1];    
//----
   if(Bars < 100 || IsTradeAllowed() == false) 
       return(0); 
   sob = (kol_buy() < 1 || buy_lev_min - sh*Point > Ask) && 
          AccountFreeMargin() > AccountBalance()*0.5;
   sos = (kol_sell() < 1 || sell_lev_max + sh*Point < Bid) &&
          AccountFreeMargin() > AccountBalance()*0.5;
//----
   if(M_ob[kb_max][2] > 0.0)
       scb = M_ob[kb_max][7] / (M_ob[kb_max][2]*10) > tp;
//----
   if(M_os[ks_max][2] > 0.0)
       scs = M_os[ks_max][7] / (M_os[ks_max][2]*10) > tp;
   kk = 0;
   ii = 0;
//----
   if(scb)
     {
       while(kol_buy() > 0 && kk < 3)
         {
           for(i = 1; i <= kb; i++)
             {
               ii = M_ob[i][0];
               //----
               if(!OrderClose(ii,M_ob[i][2],Bid,slip,White)) 
                 {
                   gle = GetLastError();
                   kk++;
                   Print("Îøèáêà ¹", gle, " ïðè close buy ", kk);
                   Sleep(6000);
                   RefreshRates();  
                 }
             }
           kk++;
         }
     }
   kk = 0;  
   ii = 0; 
//----
   if(scs)
     {
       while(kol_sell() > 0 && kk < 3)
         {
           for(i = 1; i <= ks; i++)
             {
               ii = M_os[i][0];
               //----
               if(!OrderClose(ii,M_os[i][2], Ask, slip, White))
                 {
                   gle = GetLastError();
                   kk++;
                   Print("Îøèáêà ¹", gle, " ïðè close sell ", kk);
                   Sleep(6000);
                   RefreshRates();  
                 }
             }
           kk++;
         }
     }
   kk = 0; 
   tic = -1;  
//----
   if(sob) 
     {
       if(max_lot_b == 0.0)
           lotsi = 0.01;
       else 
           lotsi = 2.0*max_lot_b;
       //----
       while(tic == -1 && kk < 3)
         {
           tic = OrderSend(Symbol(), OP_BUY, lotsi, Ask, slip, 0, Ask + (tp + 25)*Point, 
                           " ", m, 0, Yellow);
           Print("tic_buy=", tic);
           //----
           if(tic==-1)
             {
               gle = GetLastError();
               kk++;               
               Print("Îøèáêà ¹", gle, " ïðè buy ", kk);
               Sleep(6000);
               RefreshRates();   
             }
         }   
       lastt = CurTime();
       return;
     }
   tic = -1;
   kk = 0;  
//----
   if(sos) 
     {
       if(max_lot_s == 0.0)
           lotsi = 0.01;
       else 
           lotsi = 2.0*max_lot_s;
       //----
       while(tic == -1 && kk < 3)
         {
           tic = OrderSend(Symbol(), OP_SELL, lotsi, Bid, slip, 0, Bid - (tp + 25)*Point, 
                           " ", m, 0, Red);
           Print("tic_sell=", tic);
           //----
           if(tic == -1)
             {
               gle = GetLastError();
               kk++;               
               Print("Îøèáêà ¹", gle, " ïðè sell ", kk);
               Sleep(6000);
               RefreshRates();   
             }
          }
       lastt = CurTime();
       return;
     }        
  }
//+------------------------------------------------------------------+   
 

Hi, was discussed many times here in forum.

You will find lot of articels if you use the search function ... https://www.mql5.com/en/search?keyword=5+digits

only one thing: tp = 65; for a 5 digit (or 3 digit) will be 6.5 points

Same with slippage, Stoploss .. all you calculate with points

 
EADeveloper:

Hi, was discussed many times here in forum.

You will find lot of articels if you use the search function ... https://www.mql5.com/en/search?keyword=5+digits

only one thing: tp = 65; for a 5 digit (or 3 digit) will be 6.5 points

Same with slippage, Stoploss .. all you calculate with points


thanks.. those are useful articles yet still can't solve my code's problem there. I've tried to use several ideas but still the code can't work on 5-digits. So, instead of giving me the link, can you please give me a direct idea to the code above?
 
  1.    for(i = 0; i < OrdersTotal(); i++)
         {
           if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) 
               break;
           //----
           if(OrderSymbol() == Symbol() && OrderType() == OP_BUY)
    This makes the EA incompatible with any other including itself. Always filter by magic number
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol() ){              // and my pair.
    

  2. EA's must adjust TP, SL, AND slippage for 5 digit brokers. On ECN brokers you must open and THEN set stops
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    

  3. sob = (kol_buy() < 1 || buy_lev_min - sh*Point > Ask) && 
    
    Another 5
  4. You MUST count down when closing
    for(i = 1; i <= kb; i++)
                 {
                   ii = M_ob[i][0];
                   //----
                   if(!OrderClose(ii,M_ob[i][2],Bid,slip,White)) 
 

WHRoeder, I've tried your advise but still not working. I've change:

//----
   if(Bars < 100 || IsTradeAllowed() == false) 
       return(0); 
   sob = (kol_buy() < 1 || buy_lev_min - sh*pips2dbl > Ask) && 
          AccountFreeMargin() > AccountBalance()*0.5;
   sos = (kol_sell() < 1 || sell_lev_max + sh*pips2dbl < Bid) &&
          AccountFreeMargin() > AccountBalance()*0.5;
//----

then I've change:

//----
               if(!OrderClose(ii,M_ob[i][2],Bid,slip*pips2points,White))

//----
               if(!OrderClose(ii,M_os[i][2], Ask, slip*pips2points, White))

and in ordersend() part, I've also change:

tic = OrderSend(Symbol(), OP_BUY, lotsi, Ask, slip*pips2points, 0, Ask + (tp + 25)*pips2dbl, 
                           " ", m, 0, Yellow);

tic = OrderSend(Symbol(), OP_SELL, lotsi, Bid, slip*pips2points, 0, Bid - (tp + 25)*pips2dbl, 
                           " ", m, 0, Red);

I've tried your suggest number 2 and 3 but EA still 'silent' although the smiley icon is on. Please help.

 
 tic = OrderSend(Symbol(), OP_BUY, lotsi, Ask, slip, 0, Ask + (tp + 25)*Point, 
                           " ", m, 0, Yellow);
           Print("tic_buy=", tic);
           //----
           if(tic==-1)
             {
               gle = GetLastError();
If the orderSend fails it's supposed to print the last error, but the Print() clears it. move the gle to just below the orderSend or comment out the print. Same with the sell code. Look in the journal tab to see what errors you're getting.
Reason: