I challenge you to solve this SendOrder Error 130, unsolvable!

 

Lets start by showing you the code for placing the order, I've added some notes to avoid confusion:


int iSuccess;

double iStopLossShort = (dCurrentPriceBid)+(35*Point*10); // I set the current Ask and Bid price to a variable in the Start function so I work with the same value for all proceeding functions

double iTakeProfitShort = (dCurrentPriceBid)-(130*Point*10); //I am trying to run this on FXCM's MT4 who use an extra digit in the price, hence Point*10 - I am trying to set a SL of 35pips and a TP of 130pips

double iStopLossLong = (dCurrentPriceAsk)-(35*Point*10);

double iTakeProfitLong = (dCurrentPriceAsk)+(130*Point*10);

Print("Stop Loss Short = ",iStopLossShort," Take Profit = ",iTakeProfitShort); // I print them out so I can see them, they print out the values I expect

Print("Stop Loss Long = ",iStopLossLong," Take Profit = ",iTakeProfitLong);

RefreshRates(); // Refresh the rates to avoid repricing

if(sDirection == "long") iSuccess = OrderSend(Symbol(),OP_BUY,1,Ask,3,iStopLossLong,iTakeProfitLong,NULL,12345,0,Green);

else if(sDirection == "short") iSuccess = OrderSend(Symbol(),OP_SELL,1,Bid,3,iStopLossShort,iTakeProfitShort,NULL,12346,0,Red); // Place the order based on whether I am going long or short



Everytime I run this I get 'Project123 GBPUSD,M5: OrderSend failed with error #130'


I am running this on a test account on FXCM's MT4. When it runs with live prices it fails, if I then run it on the same time period on the Strategy Tester it succeeds as expected. I am trying to set a stop loss of 35 pips and a take profit of 130 pips, for instance, here are the logs of the last attempt I made for an order I tried to open with a Bid price of 1.66130:


Project123 GBPUSD,M5: Stop Loss Long = 1.6581 Take Profit = 1.6766

Project123 GBPUSD,M5: Stop Loss Short = 1.6648 Take Profit = 1.6483


The Levels look accurate to me. If I log: Print(MarketInfo(Symbol(),MODE_STOPLEVEL)); it prints out 0.


Things I have tried/Checked:


To confirm, I do have the 'Allow Live Trading' ticked on the expert properties.

The Test account has $100,000 in it, it isn't empty

I have tried passing a pip value instead of a price value for the SL/TP

I have tried setting the stop loss without multiplying the Point by 10

I have tried using live prices instead of a variable to for SL/TP (ie OrderSend(Symbol(),OP_BUY,1,Ask,3,Bid-35*Point*10,Bid+130*Point*10,NULL,12345,0,Green); -- It was changing it to a variable that got it to work on Alpari

I have tried upping the slippage value to 5, but as I refresh the rates immediately before I place an order I expect this to not be an issue.


I have put the same EA on an Alpari Test Account running in the same environment and it works fine (but the prices are different and FXCM prices are better)


The Error is #130, which I believe is for invalid Stop Loss/Take Profit but I cannot resolve this issue, Is it just that FXCM is bad for MT4 and EA's?


Help


 

if fxcm is an ecn broker, you have to open the order with no slippage, no tp and no sl

then modify the order and set sl and tp as you want it.

hope that helps ...

 
@meikel - I'll give it a try
 
meikel:

if fxcm is an ecn broker, you have to open the order with no slippage, no tp and no sl

then modify the order and set sl and tp as you want it.

hope that helps ...

Yes It solves the problem I struggled with this error a long time, Thanks for asking jameshartell :);

 
It works for me too - Thank you!!!
 
jameshartell wrote >>
It works for me too - Thank you!!!

This is the same when using Varengold

came across it abou a year ago but have only just seen this post

 
meikel:

if fxcm is an ecn broker, you have to open the order with no slippage, no tp and no sl

then modify the order and set sl and tp as you want it.

hope that helps ...

Thanks - I was struggling with my ECN broker too and now it is fixed....genius.

 
Not completely accurate about the slippage - you can put any value u want, but it will be ignored (so you don't have to specifically set it to zero).
 
So with an ECN broker we have to add slippage to the price in the OrderSend() function, before sending the order ?
 
gordon:
Not completely accurate about the slippage - you can put any value u want, but it will be ignored (so you don't have to specifically set it to zero).
Doesn't that answer your question ?
 
DayTrader:
So with an ECN broker we have to add slippage to the price in the OrderSend() function, before sending the order ?
You don't add slippage to the price, but you must pass a slippage value in the OrderSend() function
//++++ 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());
     */
Reason: