mql - Modifying order returns error 130 -
i'm trying modify order, keep error modifying order!, error#130. i'm using ecn broker, need modify order set stoploss/takeprofit. doing wrong?
int digits = marketinfo( symbol(), mode_digits ); if ( digits == 2 || digits == 3 ) pipdigits = 0.01; else if ( digits == 4 || digits == 5 ) pipdigits = 0.0001; selltakeprofit = ask + ( takeprofit * pipdigits ); sellstoploss = ask - ( stoploss * pipdigits ); ticket = ordersend( symbol(), op_sell, lotsize, ask, 100, 0, 0, 0, 0, 0, clr_none ); if ( ticket < 0 ) { print( "venda order send failed error #", getlasterror() ); print( "stop loss = ", sellstoploss ); } else { print( "order send sucesso!!" ); print( "balance = ", accountbalance() ); print( "equity = ", accountequity() ); bool res = ordermodify( ticket, 0, sellstoploss, selltakeprofit, 0 ); if ( res == false ) { print( "error modifying order!, error#", getlasterror() ); print( "sellstoploss ", sellstoploss ); print( "selltakeprofit ", selltakeprofit ); print( "stoplevel ", stoplevel ); print( "ask ", ask ); } else { print( "order modified successfully" ); } }
error #130 err_invalid_stops.
the problem that
a) stoploss level inputting close order open price. dictated by
marketinfo( symbol(), mode_stoplevel ) // returns min allowed distance [pts]
else
b) because have not normalized stoploss level normalizedouble().
see below buy order example. in example, i.e. sell order, note should opening order @ bid price, not ask have. note stoploss , takeprofit calculated relative bid price, bid displayed on charts, unfortunately have take spread loss in stride.
only other minor problem input no colour last parameter in ordermodify(). unlike in ordersend(), these not initialized default in function definition, should pass them really.
//--- minimum stop level double minstoplevel = marketinfo( symbol(), mode_stoplevel ); print( "minimum stop level=", minstoplevel, " points" ); double price = ask; //--- calculated sl , tp prices must normalized double stoploss = normalizedouble( bid - minstoplevel * point, digits ); double takeprofit = normalizedouble( bid + minstoplevel * point, digits ); //--- place market order buy 1 lot int ticket = ordersend( symbol(), op_buy, 1, price, 3, stoploss, takeprofit, "my order", 16384, 0, clrgreen );
Comments
Post a Comment