Need Help to adopt the code to client with 5digits after point

 

Hello I need a helpt to adopt this code (see below) to a micro account, that means 1 Lot = 10 Dollars and with 5 digits after point, The EA starts the initial trade with 0.01 Lot.

The Point is that after the firts trade, it doesnt want to open the second one, if the first one is in MINUS. The failure masage is "invalide lots amount for OderSend function"

Can anybody help me?

Files:
 
  1.            lotsi = MathCeil(AccountBalance()*risk / 10000) / 10; 
    Must use lotstep
        double  lotStep         = MarketInfo(Symbol(), MODE_LOTSTEP);   //IBFX= 0.01
        lotsi=MathCeil(lotsi/lotStep)*lotStep;
    

  2.    for(cnt = 0; cnt < OrdersTotal(); cnt++)   
         {
           OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
              //----
           if(OrderSymbol() == Symbol())
                   OpenOrders++;
         }       
    
    Always count down when modifying/deleting/closing in the presence of multiple orders (multiple charts.) Always test return codes.
        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.
            OpenOrders++;
        }

  3.    if(Symbol() == "EURUSD") 
           PipValue = EURUSDPipValue; 
    
    Don't hard code values.
    double  PointValuePerLot() { // Value in account currency of a Point of Symbol.
        /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147)
         * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip.
         * IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
         * IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
         *                                  $1.00/point or $10.00/pip.
         *
         * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the
         * same value as MODE_POINT (or Point for the current symbol), however, an
         * example of where to use MODE_TICKSIZE would be as part of a ratio with
         * MODE_TICKVALUE when performing money management calculations which need
         * to take account of the pair and the account currency. The reason I use
         * this ratio is that although TV and TS may constantly be returned as
         * something like 7.00 and 0.00001 respectively, I've seen this
         * (intermittently) change to 14.00 and 0.00002 respectively (just example
         * tick values to illustrate). */
        return(  MarketInfo(Symbol(), MODE_TICKVALUE)
               / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.
    }
    

  4. if(mode == OP_BUY) 
        OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Blue); 
            //----
    if(mode == OP_SELL) 
        OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Red); 
    
    The calls are the same so you don't need the if's. EAs must adjust to 5 digit brokers (TP, SL, AND slippage)
    //++++ These are adjusted for 5 digit brokers.
    double  pips2points,    // slippage  3 pips    3=points    30=points
            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
    

  5.    if(OpenOrders >= MaxTrades) 
              ContinueOpening = False;
       else 
              ContinueOpening = True;
    
    Simplify code where possible
    bool ContinueOpening = OpenOrders < MaxTrades;
    

  6. if(OrderClosePrice() < OrderOpenPrice()) 
        Profit = Profit - (OrderOpenPrice() - OrderClosePrice())*OrderLots() / Point; 
                               //----
    if(OrderClosePrice() > OrderOpenPrice()) 
        Profit = Profit + (OrderClosePrice() - OrderOpenPrice())*OrderLots() / Point; 
    
    Simplify
    Profit+=OrderProfit();

  7.       mylotsi = NormalizeDouble(mylotsi*1.5, 1); 
      else 
          mylotsi = NormalizeDouble(mylotsi*2, 1); 
    
    These assume lot step = 0.1; fail for 0.2
        double  lotStep         = MarketInfo(Symbol(), MODE_LOTSTEP);   //IBFX= 0.01
        mylotsi=MathCeil(mylotsi/lotStep)*lotStep;
    

  8.            if(mylotsi > 100) 
                   mylotsi = 100; 
    
    Don't hard code values.
    double  maxLot          = MarketInfo(Symbol(), MODE_MAXLOT );   //IBFX=50.00
    if (mylotsi > maxLot) mylotsi = maxLot;

  9.            OrderSend(Symbol(), OP_BUY, mylotsi, BuyPrice, slippage, sl, tp, NULL, 0, 0, 
                         Blue);                 
    
    Five digit adjustments already mentioned. On ECN brokers you must open the order and THEN set the tp/sl
 

I hope the member fully appreciates the effort involved & the quality of WHRoeders reply...

-BB-

 

Thank You very much, will try it!!!

 
WHRoeder:
  1. Must use lotstep
  2. Always count down when modifying/deleting/closing in the presence of multiple orders (multiple charts.) Always test return codes.
  3. Don't hard code values.
  4. The calls are the same so you don't need the if's. EAs must adjust to 5 digit brokers (TP, SL, AND slippage)
  5. Simplify code where possible
  6. Simplify
  7. These assume lot step = 0.1; fail for 0.2
  8. Don't hard code values.
  9. Five digit adjustments already mentioned. On ECN brokers you must open the order and THEN set the tp/sl

So I've made changes and I've tried to comply the code, but there are 8 warnings and 8 failure. I've tried to make correction by myself, but I've got more failure and warnings then before. I've atached the new version of the code with the chages you adviced, can u correct one more time, please?!!!

 
BarrowBoy:

I hope the member fully appreciates the effort involved & the quality of WHRoeders reply...

-BB-

Seriously! That was at least an hour of work. Way to support the community, WHRoeder.

   else 
       // then is mini
       if(mm != 0) 
           double  lotStep         = MarketInfo(Symbol(), MODE_LOTSTEP);   //IBFX= 0.01
            lotsi=MathCeil(lotsi/lotStep)*lotStep; 
                     else 
                         lotsi = Lots; 

Is it me or are we missing curly braces in this bit of code? Try this:

   else 
       // then is mini
       if(mm != 0) 
       {
          double  lotStep         = MarketInfo(Symbol(), MODE_LOTSTEP);   //IBFX= 0.01
          lotsi=MathCeil(lotsi/lotStep)*lotStep; 
       }
       else 
          lotsi = Lots; 
 

MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.


What's the difference for example on eurusd?

 
forexCoder:

MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.


What's the difference for example on eurusd?

Read the last sentence in the comment just above the statement.
Reason: