Solution for "How to Make EA Auto Fits 4, 5, 6 and Any Digits Form Platforms, Unit in Pips." - page 2

 
TomSG:
How can i change the attached EA so it works with my 3 digit broker on USDJPY? Currently it is set up for 5 digits
  1.     for(int i=0; i<OrdersTotal(); i++)
          {
          OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
          if (OrderType()==OP_SELL && OrderSymbol()==Symbol())
    
             {
                OrderClose(OrderTicket(),OrderLots(),Ask,3,Yellow);
    You MUST count down when closing/deleting or in the presence of multiple order on other charts. Count Down ALWAYS.
    Always test return codes, if the order select fails so does your code.
    What is the meaning of 3. On a 4 digit broker it's 3 pips (3 points,) on a 5 digit broker it's 0.3 pips (3 points)
        for(iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        ){
            if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3*pips2dbl,Yellow))
               Alert("OrderClose failed: ", GetLastError());

  2.    if(OrdersTotal()<1)
          {
    
    This makes the EA incompatable with every other including manual trading.
    int count=0;
        for(iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        ){ count++; }
    if(count<1)
          {
    

  3.    if ( MyStopLoss >0) StopLoss = Ask - MyStopLoss * Point; 
    :
       if((Ask - Signalbuyvalue) < -Delay*Point) Buyvalue=2;
    :
       if ( MyStopLoss >0) StopLoss = Ask - MyStopLoss * pips2dbl;
    :
       if((Ask - Signalbuyvalue) < -Delay*pips2dbl) Buyvalue=2;
    :
    
    //++++ 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(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                    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(...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket()...)
           Alert("OrderModify failed: ", GetLastError());
         */
    ETC
Reason: