OrderSend error 130 - but SL and TP seem to be set correct

 

Hi,

I googled and searched this forum, but was not able to solve my problem. I know, that error 130 occours if stop losses or take profits are set false. But I am pretty sure, that that's not my problem ;). Maybe someone had the same problem...

I have a demo account at TradingPoint. They state, that stop losses and take profits and orders can be set at ask +/- the spread. But when backtesting my EA, sometimes the error 130 occours.

Here the relevant code:

            dTP = NormalizeDouble(dHigh + 80 * Point + MarketInfo(Symbol(), MODE_SPREAD) * Point, MarketInfo(Symbol(), MODE_DIGITS));
            dSL = NormalizeDouble(dMaxLow - 20 * Point, MarketInfo(Symbol(), MODE_DIGITS));
            dBuyStop = NormalizeDouble(dHigh + 20 * Point + MarketInfo(Symbol(), MODE_SPREAD) * Point, MarketInfo(Symbol(),MODE_DIGITS));
            
            if( dBuyStop < Ask + MarketInfo( Symbol(), MODE_SPREAD ) * Point ) {
               dBuyStop = Ask + MarketInfo( Symbol(), MODE_SPREAD ) * Point;
               
               if( dTP < Ask + MarketInfo( Symbol(), MODE_SPREAD ) * Point )
                  dTP = NormalizeDouble(Ask + 2 * MarketInfo( Symbol(), MODE_SPREAD ) * Point, MarketInfo(Symbol(),MODE_DIGITS));
            }
                        
            if( dTP < Ask + MarketInfo( Symbol(), MODE_SPREAD ) * Point )
               dTP = NormalizeDouble(Ask + MarketInfo( Symbol(), MODE_SPREAD ) * Point, MarketInfo(Symbol(),MODE_DIGITS));
               
            if( dSL > Ask - MarketInfo( Symbol(), MODE_SPREAD ) * Point )
               dSL = NormalizeDouble(Ask - MarketInfo( Symbol(), MODE_SPREAD ) * Point, MarketInfo(Symbol(),MODE_DIGITS));
               

            
            iTicket = OrderSend(Symbol(),OP_BUYSTOP ,0.1 , dBuyStop, 3 , dSL, dTP );
            Print("Ask: ", Ask, " BuyStop: ", dBuyStop, " SL: ", dSL, " TP: ", dTP );

dHigh, is the High from the previous bar and dLow is the Low from the previous bar

If I run the EA, some orders are processed and others generate this error. I'm messing around with this since 3 days. If someone could help, i would relly appreciate it!

Here is the output i get:

2012.03.05 11:19:35     2012.02.23 14:20  Test EURUSD,M5: ticket number: -1
2012.03.05 11:19:35     2012.02.23 14:20  Test EURUSD,M5: Ask: 1.3296 BuyStop: 1.33 SL: 1.3283 TP: 1.3306
2012.03.05 11:19:35     2012.02.23 14:20  Test EURUSD,M5: OrderSend error 130

Thanks for your help,

Regards, maecky

 

Ok,

can I already modify the order, after it is placed, or only, if the order got filled?

Does this matter with backtesting? Because some of my orders worked and some not?

Thanks for your help!

 
maecky:

Ok,

can I already modify the order, after it is placed, or only, if the order got filled?

Does this matter with backtesting? Because some of my orders worked and some not?

Thanks for your help!

The Strategy Tester does not simulate an ECN Broker so you can set TP & SL with the OrderSend. On Demo and Live things are different with an ECN Broker . . . you should make sure the OrderSend worked before you attempt to Modify the Order.
 

Ok, I understand, but than we are back to my initial question ;)

Why do I get the error 130 - with most of the test data it does work, but a few orders deliver this error :(

 
maecky:

Ok, I understand, but than we are back to my initial question ;)

Why do I get the error 130 - with most of the test data it does work, but a few orders deliver this error :(

Ah, I should have read your post rather than just following on from deVries I suspect your issue is most likely due to your SL being too close . . you can send SL and TP with a Pending order with an ECN Broker, just not with a Market Order.

There is good info here: Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial there was also a good thread that I contributed to a little, it might be worth a read, it's not specifically about Pending orders but is a good discussion about Stop and Freeze levels: https://www.mql5.com/en/forum/135633

 
RaptorUK:

Ah, I should have read your post rather than just following on from deVries I suspect your issue is most likely due to your SL being too close . . you can send SL and TP with a Pending order with an ECN Broker, just not with a Market Order.

There is good info here: Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial there was also a good thread that I contributed to a little, it might be worth a read, it's not specifically about Pending orders but is a good discussion about Stop and Freeze levels: https://www.mql5.com/en/forum/135633


Thanks for correcting buystop I was wrong deleted the post
 
EAs must adjust TP, SL AND slippage for 4/5 digit brokers. On ECN brokers 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(){                                                 OptParameters();
     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());
     */
Drop the normalizeDouble, it is NEVER necessary.
Reason: