OrderSend error with Pepperstone - Works in strategy tester, not on live

 

I have a problem when programming an MT4 Expert Advisor.

The "OrderSend" function works in the strategy tester but not on the live account... Why ?

Need a magic number in the order ?

Need to add a comment ?

Need to open the order and then after set stop Loss / take profit (really not safe) ?

Slippage two low ? (3 points = 0.3 pips)

Need a RefreshRates() just before ?

And no error in the 'expert' window is displayed !

This is the line of command:

ActualTicket = OrderSend(Symbol(), OP_SELL, 0.01, Bid, 3, Bid + 100, Bid - 200);

Thanks !

 

You're question probably hasn't been answered by some of the more experienced coders because it is somewhat 'painful' to read.

But since you made an effort to show that you've considered solutions (none of which are likely to have fixed your problem), and since I remember pulling my hair out over those same questions, here are some tips:

Make sure you are using GetLastError() (https://docs.mql4.com/check/GetLastError) to help pinpoint errors as they occur. There are plenty of articles about good practice in (live) order sending.

Since you say that there are no errors being displayed in the expert window, it probably means that you are EITHER not using GetLastError() OR that the order isn't even being triggered at all (in which case the error is obviously not with the OrderSend() part).

No magic number or comments are necessary. (But they are advised / indispensable when having more than one position open at the same time. Look up trade context busy errors and using "semaphore" if this applies to you).

Read up on sending SL and TP info with the order for ECN brokers - and figure out whether that applies to you.

0.3 pips slippage probably IS too low, depending on your connection, the broker, the currency pair and the time of day.

It is always a good idea to use RefreshRates() before sending. Again, look up the good practice articles (which you probably already have, given that you know to ask about that. So read them again!).

Remember that most brokers have a minimum distance which you can set the SL and TP from the open price. Find this by using MarketInfo(Symbol(), MODE_STOPLEVEL). You might find these useful https://docs.mql4.com/constants/marketinfo.

Some broker demo accounts have a minimum lotsize. That minimum is often 0.1 - so your 0.01 lotsize is probably too low as well.

I'm surprised your line of code even complied at all without all the arguments in it. I had to try it to check, and it does. It is always a good idea to fill out all the blanks at least with placeholder / default settings - even if just to make things clearer for yourself when re-reading.

But finally, and most importantly - what the hell are you trading that you need a SL of 100.0 and a TP of 200.0 ?! Elephants? If you're trading "EURUSD" for example, then you just asked the server to place the SL at around 100 Euros. Unless you have a few million in your broker's account then that SL is a moot point because you would run out of money long before then. I'm not even sure how a TP of -200 Euros would work ... you wouldn't get that even if the Euro collapsed overnight. The SL and TP you are looking for are more likely to be Ask+0.0100 and Ask-0.0200. I write "Ask" here because unless you are being charged 0 spread, then you won't be closing at the Bid price. Look up open and closing prices for long and short positions.

 
rahan:

I have a problem when programming an MT4 Expert Advisor.

The "OrderSend" function works in the strategy tester but not on the live account... Why ?

The Strategy Tester does not simulate an ECN Broker. Are you checking your function return values and reporting any errors to the log ? What are Function return values ? How do I use them ?

There is plenty of info here: ECN

 
clerin6:

You're question probably hasn't been answered by some of the more experienced coders because it is somewhat 'painful' to read.

But since you made an effort to show that you've considered solutions (none of which are likely to have fixed your problem), and since I remember pulling my hair out over those same questions, here are some tips:

Make sure you are using GetLastError() (https://docs.mql4.com/check/GetLastError) to help pinpoint errors as they occur. There are plenty of articles about good practice in (live) order sending.

Since you say that there are no errors being displayed in the expert window, it probably means that you are EITHER not using GetLastError() OR that the order isn't even being triggered at all (in which case the error is obviously not with the OrderSend() part).

No magic number or comments are necessary. (But they are advised / indispensable when having more than one position open at the same time. Look up trade context busy errors and using "semaphore" if this applies to you).

Read up on sending SL and TP info with the order for ECN brokers - and figure out whether that applies to you.

0.3 pips slippage probably IS too low, depending on your connection, the broker, the currency pair and the time of day.

It is always a good idea to use RefreshRates() before sending. Again, look up the good practice articles (which you probably already have, given that you know to ask about that. So read them again!).

Remember that most brokers have a minimum distance which you can set the SL and TP from the open price. Find this by using MarketInfo(Symbol(), MODE_STOPLEVEL). You might find these useful https://docs.mql4.com/constants/marketinfo.

Some broker demo accounts have a minimum lotsize. That minimum is often 0.1 - so your 0.01 lotsize is probably too low as well.

I'm surprised your line of code even complied at all without all the arguments in it. I had to try it to check, and it does. It is always a good idea to fill out all the blanks at least with placeholder / default settings - even if just to make things clearer for yourself when re-reading.

But finally, and most importantly - what the hell are you trading that you need a SL of 100.0 and a TP of 200.0 ?! Elephants? If you're trading "EURUSD" for example, then you just asked the server to place the SL at around 100 Euros. Unless you have a few million in your broker's account then that SL is a moot point because you would run out of money long before then. I'm not even sure how a TP of -200 Euros would work ... you wouldn't get that even if the Euro collapsed overnight. The SL and TP you are looking for are more likely to be Ask+0.0100 and Ask-0.0200. I write "Ask" here because unless you are being charged 0 spread, then you won't be closing at the Bid price. Look up open and closing prices for long and short positions.


Hi all,

First i would like to thank you for your patience and very good informations. All are valuable.

Yes my question was a little bit unclear, poor wording. Please excuse me for that.

Excuses also for "+100" "-200": the correct values are "+100*Point" and "-200*Point". That is 10/20 pips with 5 digits broker.

1- I got no error report in MT4 during live running. But i didn't call the GetLastError function... I had continuously "invalid stops" then after doing it. Now i do a "Print" in my code and have a "Debug" parameter (true/false).

2- The problem is that Peppersone changes its account management and now it is no more possible to open an order with SL/TP at time you create the order. I confirmed it with a manual trade : you can't do it anymore manually in real-time too.

3- No magic number for me: if you do that any broker and any people who can access the trading pool can know you are using an EA. So i keep track of my orders by recoding the tickets numbers retuned by 'OrderSend'. It is reliable except if the MT4 shutdown.

So the solution is :

1- Open the order with SL/TP set o '0' - use OrderSend

2- Set the SL/TP - use OrderModify

Many thanks.

 

rahan:

This is the line of command:

ActualTicket = OrderSend(Symbol(), OP_SELL, 0.01, Bid, 3, Bid + 100, Bid - 200);

On most pairs Bid < 2.0 Even on USDJPY Bid < 100, So Bid - 200 is negative. Bad call
//++++ 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(){                                             OptInitialization();
     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());
     */
Reason: