Help with OrderSend( ) Function

 
New to mql4, I wrote the following code for practice, but can't figure out why I get an Error 130

I think it has to do with unNormalized numbers. I'm using IBFX broker and they use the 5th decimal on the price.


double Stoploss = 50;
double Takeprofit = 50;

int start()
{
int ticket = OrderSend(Symbol(),OP_BUY,1.0,Ask,3,Ask-Stoploss*Point,
Ask+Takeprofit*Point,"Order #1",1234,0,Red);

if(ticket == -1) Print("error-",GetLastError());

return(0);
}



I also tried setting SL and TP to 500 because of the 5th decimal but got the same error. Any suggestions? Thanks
 
JohnAdams:
New to mql4, I wrote the following code for practice, but can't figure out why I get an Error 130

I think it has to do with unNormalized numbers. I'm using IBFX broker and they use the 5th decimal on the price.


double Stoploss = 50;
double Takeprofit = 50;

int start()
{
int ticket = OrderSend(Symbol(),OP_BUY,1.0,Ask,3,Ask-Stoploss*Point,
Ask+Takeprofit*Point,"Order #1",1234,0,Red);

if(ticket == -1) Print("error-",GetLastError());

return(0);
}



I also tried setting SL and TP to 500 because of the 5th decimal but got the same error. Any suggestions? Thanks


NormalizeDouble(Value, Digits) helps for normalize the price.

MarketInfo and Stoplevel will help you to determine the min allowed distance between price and SL/TP

Some Brokers need 0 for Stoploss and 0 for Takeprofit in OrderSend. After succesfully send the order you can modify and set the SL and TP

Search for ECN Broker

 

on a 5 digits broker Points are not Pips. So Ask+50*Point might be smaller then Bid+MinimalStopDistance..

Use the MarketInfo() function to get that values, additionally you need to check with "Digits" on which broker you are working...
(This question is asked 100Times each day)

//z

 
ok, thanks to both, I'll try out these suggestions..
 

int ticket = OrderSend(Symbol(),OP_BUY,1.0,Ask,3,Ask-Stoploss*Point,
  1. For a buy you open at the ask but the stops are relative to the Bid.
  2. On a ECN broker you must open with no TP/SL and modify afterwords.
  3. For a 5 digit broker you must modify 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