Plz help me in error code 4107 with ordersend()

 

I am new to mql4 programming. i am trying to write an EA that showing error 4107 for following code...


ppbid=Bid;

ppask=Ask;

MyLot=0.01;


int ticket=OrderSend(Symbol(),OP_SELLSTOP,MyLot,ppbid-(10*Point),0,ppask+(20*Point),ppbid-(20*Point),"",16384,0,CLR_NONE);


What is my fault? I will be grateful if somebody help me. thanks.

 
Shihab:

I am new to mql4 programming. i am trying to write an EA that showing error 4107 for following code...

4107 =

https://docs.mql4.com/runtime/errors

ERR_INVALID_PRICE_PARAM (4107)

So a price is wrong within the OrderSend function. The standard fault finding method is to reduce the problem until it goes away. So, for example in this case, remove the stoploss and takeprofit values.

Typically newbies either use the wrong price (Bid/Ask) or get too close to the current price, violating the StopLevel

https://docs.mql4.com/constants/marketinfo


https://book.mql4.com/appendix/limits

 
Shihab:

I am new to mql4 programming. i am trying to write an EA that showing error 4107 for following code...

int ticket=OrderSend(Symbol(),OP_SELLSTOP,MyLot,ppbid-(10*Point),0,ppask+(20*Point),ppbid-(20*Point),"",16384,0,CLR_NONE);

  1. You can not place a pending order closer than MarketInfo(chart.symbol, MODE_STOPLEVEL)*Point from the market (IBFX was 30 points/3 pips.) You placing it 20 points below.
  2. In those pairs where TickSize is not equal to point, the open price must be normalized
    double NormalizePrice(double p, string pair=""){
        // https://www.mql5.com/en/forum/135345 zzuegg reports for non-currency DE30:
        // MarketInfo(chart.symbol,MODE_TICKSIZE) returns 0.5
        // MarketInfo(chart.symbol,MODE_DIGITS) return 1
        // Point = 0.1
        // Prices to open must be a multiple of ticksize
        if (pair == "") pair = Symbol();
        double ts = MarketInfo(pair, MODE_TICKSIZE)
        return( MathRound(p/ts) * ts );
    }
    

  3. not adjusting for 4/5 digit brokers
  4. not adjusting for ECN brokers
    //++++ 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(){                                                     OptParameters();
         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(..., 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());
         */
    

  5. And next time use this