Error 130: Invalid stop. With no reason?

 

Hi all,

I'm trying to Send some market order on a demo account through the OrderSend function, setting TP and SL. This is my code:

RefreshRates();
TP=Ask+120*Point;
SL=Ask-120*Point;
Print("Sending BUY. Point: " + Point + " EntryPrice: " + Ask + " TP: " + TP + " SL: " + SL);


int Tck=OrderSend(Symb, OP_BUY, Lts, Ask, 2, TP, SL, "OpenLong", 0, DarkGreen); //Opening Buy

if (Tck > 0) return; // Order succeded. Can exit Start 'cose no more orders need to be opened at the same time.
if (Fun_Error(GetLastError())==1) continue; // Processing errors
return;

This is the output:

2012.04.10 10:32:00 SP_Trader1 EURUSD,H1: Sending BUY. Point: 0.00001000 EntryPrice: 1.30923000 TP: 1.31043000 SL: 1.30803000
2012.04.10 10:32:00 SP_Trader1 EURUSD,H1: Error occurred: 130

If I try to make the same order manually in the Trade window, it works perfectly.

Any idea?


Thank you very much in advance

Regards

Stefano

 

Is your Broker an ECN Broker ?

ECN

 
spronti 2012.04.10 10:38

Hi all,

I'm trying to Send some market order on a demo account through the OrderSend function, setting TP and SL.

RaptorUK 2012.04.10 10:56

Is your Broker an ECN Broker ?

ECN

Market order is ECN.

Send it with TP = 0 and SL = 0

 

  1. TP=Ask+120*Point;
    SL=Ask-120*Point;
    EA's must adjust for 4 vs 5 digit brokers. 120*point is 120 pips on a 4 but 12.0 on a 5. Adjust TP, SL, AND slippage. On ECN you must open first and THEN set stops
    //++++ 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 forum.mql4.com/43064#515262
                    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());
         */
    
 
WHRoeder:

  1. EA's must adjust for 4 vs 5 digit brokers. 120*point is 120 pips on a 4 but 12.0 on a 5. Adjust TP, SL, AND slippage. On ECN you must open first and THEN set stops


Thanks all,

I'm not sure I've fully understood, I will take my time to study the ECN and digits topic.

By the way for now I've tried the following to be on the safe side (speaking of digits):

RefreshRates();
TP=Ask+120*Point;
SL=Ask-120*Point;
TP = MathFloor(TP*100)/100;
SL = MathFloor(SL*100)/100;
Print("SP_Trader1. Sending BUY. Point: " + Point + " EntryPrice: " + Ask + " TP: " + TP + " SL: " + SL);
int Tck=OrderSend(Symb,OP_BUY,Lts,Ask,2,TP,SL,"OpenLong",0,DarkGreen);//Opening Buy

2012.04.10 15:48:18 SP_Trader1 EURUSD,M1: SP_Trader1. Sending BUY. Point: 0.00001000 EntryPrice: 1.30957000 TP: 1.31000000 SL: 1.30000000

As you can see from the output, the EntryPrice is set to Ask[] and the TP is seto to 1.31 and SL to 1.30 which should bypassa any digit problem, doesn't it?

Nevertheless, the error is still 130. Am I midunderstanding what you mean by digits, and 1.31 is not good enough?

My provider is AAAF, but I'm running with a demo account not with the live account.

Thanks

Stefano

 
spronti:


Nevertheless, the error is still 130. Am I midunderstanding what you mean by digits, and 1.31 is not good enough?

My provider is AAAF, but I'm running with a demo account not with the live account.

Thanks

Stefano

From what I can see your Broker is an ECN Broker so you cannot set TP & SL when you do an OrderSend()

What is meant by Digits is that your Broker is a 5 digit broker, so they quote GBPUSD, EURUSD, etc to a precision of 5 digits . . . in this case 12 pips is 120 points . . . but on a 4 Digit Broker (they all were 4 Digit brokers at one time) . . 12 pips is 12 points . . . . if you code the way you have your code will not work as you intended on a 4 digit broker . . .

 
RefreshRates(); 
//TP=Ask+120*Point;
//SL=Ask-120*Point;
Print("Sending BUY. Point: " + Point + " EntryPrice: " + Ask + " TP: " + TP + " SL: " + SL);
int Tck  =  OrderSend(Symb, OP_BUY, Lts, Ask, 2, 0, 0, "OpenLong", 0, DarkGreen); //<<== put zero on SL and TP
if (Tck > 0) 
    {
    OrderSelect (tck, SELECT_BY_TICKET, MODE_TRADES);
    OrderModify (Tck,OrderOpenPrice(), OrderOpenPrice() - 120*Point, OrderOpenPrice() + 120*Point, 0, Blue); <<== put SL and TP
    return; // Order succeded. Can exit Start 'cose no more orders need to be opened at the same time.
    }
if (Fun_Error(GetLastError())==1) continue; // Processing errors 
return;
 
. . . in addition to this you might want to check the return value from the OrderModify, if it fails you will have an open order with no SL or TP set . . . and that is really not a good idea unless you are managing it in some other way.
 
onewithzachy:

And also correction for how to do Slippage ..... MagicNumber adjusting for 5 digit brokers and it is compleet
 
RaptorUK:
. . . in addition to this you might want to check the return value from the OrderModify, if it fails you will have an open order with no SL or TP set . . . and that is really not a good idea unless you are managing it in some other way.

Good one RaptorUK. Corrected. BTW, what is AAAF ???

RefreshRates(); 
//TP=Ask+120*Point;
//SL=Ask-120*Point;
Print("Sending BUY. Point: " + Point + " EntryPrice: " + Ask + " TP: " + TP + " SL: " + SL);
int Tck  =OrderSend(Symb, OP_BUY, Lts, Ask, 2, 0, 0, "OpenLong", 0, DarkGreen); //<<== put zero on SL and TP
if (Tck > 0) 
    {
    OrderSelect (tck, SELECT_BY_TICKET, MODE_TRADES);
    bool Modif = OrderModify (Tck,OrderOpenPrice(), OrderOpenPrice() - 120*Point, OrderOpenPrice() + 120*Point, 0, Blue);
    if (Modif == false)
       {
       Print  ("OMG, OMG, I have open orders with no TP and SL");
       }
       else
       {
       return; // Order succeded. Can exit Start 'cose no more orders need to be opened at the same time.
       }
    }
if (Fun_Error(GetLastError())==1) continue; // Processing errors 
return;
 
onewithzachy:

Good one RaptorUK. Corrected. BTW, what is AAAF ???

AAAFx . . . a Broker
Reason: