Error #130 - Invalid stops

 

Hello,

Can anybody help me with this error?

I am sending an Order using this command: Ticket = OrderSend(Symbol(), OP_BUY, 1, Ask, 3, 30, 30, "Buy_Order", 0, 0, Green);

I want to buy 1 lot and set StopLoss and TakeProfit to 30 pips and I am receiving the error #130 - Invalid stops.

I have AlpariUK demo Account and I am trying it on EURUSD pair with the following MarketInfo:

MODE_POINT -> 0.0001
MODE_DIGITS -> 4
MODE_SPREAD -> 2
MODE_STOPLEVEL -> 2
MODE_LOTSIZE -> 100000
MODE_TICKVALUE -> 10
MODE_TICKSIZE -> 0.0001
MODE_MINLOT -> 0.01
MODE_LOTSTEP -> 0.01
MODE_MAXLOT -> 99999

Thanks for any help

Draho

 

Stoploss and TakeProfit need to be a price, not an integer of pips

int OrderSend(string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

 
phy:

Stoploss and TakeProfit need to be a price, not an integer of pips

int OrderSend(string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)


I have the same problem with stop in my EA, the Variables are that:

extern double StopLoss       = 30.0;
extern double TakeProfit     = 50.0;

and then so:

if(signal==2)  
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,StopLoss,TakeProfit,"Sell",MAGICMA,0,Red);
      if (res>0) 
        {
          Print("Order #",res," opend by Sell Signal");
        } 
      else 
        {
        err=GetLastError();
        Print("Error(",err,") opening Sell position: ",ErrorDescription(err));
        } 
      return;
     }
if(signal==1)  
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,StopLoss,TakeProfit,"Buy",MAGICMA,0,Blue);
      if (res>0) 
        {
          Print("Order #",res," opend by normale Buy Signal");
        } 
      else 
        {
        err=GetLastError();
        Print("Error(",err,") opening Buy position: ",ErrorDescription(err));
        }
      return;
     }
But I get always error 130 for Stoplos, even if I set a Stoplos from zero 0 than it work, but where is the error, I use double values or not :-) ?
 

You have to convert your stoploss to a price.

res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+(StopLoss*Point),Bid-(TakeProfit*Point),"Sell",MAGICMA,0,Red);

 
phy:

You have to convert your stoploss to a price.

res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+(StopLoss*Point),Bid-(TakeProfit*Point), "Sell",MAGICMA,0,Red);


Yes that´s right so it work, thank you.

 
phy:

You have to convert your stoploss to a price.

res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+(StopLoss*Point),Bid-(TakeProfit*Point),"Sell",MAGICMA,0,Red);

Hi phy...


I'm getting the same error with the following code snippets. I just can't see why my code is behaving in this way, but maybe you or some other switched on person might be able to spot what I've missed...


Here's the offending snippet of code.


double dStopLoss, dTakeProfit, dLots;

// Removed - logic for calculating values for dStopLoss, dTakeProfit and dLots

Print("About to BUY: Ask="+Ask+" (Bid="+Bid+"), StopLoss="+dStopLoss+", TakeProfit="+dTakeProfit+", Lots="+dLots);
iTicket = OrderSend(Symbol(), OP_BUY, dLots, Ask, 2, dStopLoss, dTakeProfit, "Mikes Winner", Magic, 0, Green);
if (iTicket<=0) {
   Print("Failed to execute order. Error is "+ GetLastError());
}

and here is the trace output showing the inputs to the error and the error code itself. Any ideas what I've got wrong here?

About to BUY: Ask=1.50295000 (Bid=1.50280000), StopLoss=1.47195000, TakeProfit=1.50495000, Lots=7.70000000
Failed to execute order. Error is 130
 
mjbrady wrote >>

Hi phy...

I'm getting the same error with the following code snippets. I just can't see why my code is behaving in this way, but maybe you or some other switched on person might be able to spot what I've missed...

Here's the offending snippet of code.

and here is the trace output showing the inputs to the error and the error code itself. Any ideas what I've got wrong here?

Look for NormalizeDouble() in the Documentation!

 
EADeveloper:

Look for NormalizeDouble() in the Documentation!

That seems unlikely to be the answer. It's not as though the prices are being specified to 6 or 7 decimal places (and my personal experience is that this doesn't matter anyway - the broker rounds the prices as necessary).


It's worth bearing in mind that there's a new-ish reason for error #130, which (I think) has come into existence since the original posts on this thread in 2008. If your broker uses something like the Boston Technologies Bridge, then the s/l and t/p have to be placed separately from a market order, and (I think) you get error #130 if you try to do the s/l and t/p as part of the market order.


In other words, try placing just the buy order by itself first, and then do an OrderModify() to put in the s/l and t/p.

 
jjc:

That seems unlikely to be the answer. It's not as though the prices are being specified to 6 or 7 decimal places (and my personal experience is that this doesn't matter anyway - the broker rounds the prices as necessary).


It's worth bearing in mind that there's a new-ish reason for error #130, which (I think) has come into existence since the original posts on this thread in 2008. If your broker uses something like the Boston Technologies Bridge, then the s/l and t/p have to be placed separately from a market order, and (I think) you get error #130 if you try to do the s/l and t/p as part of the market order.


In other words, try placing just the buy order by itself first, and then do an OrderModify() to put in the s/l and t/p.

 

Still error#130

// Regular variables
extern double LotSize = 0.1;
extern double LotIncrement = 0.1;

extern double TakeProfitPip = 10;

extern double StopLossPip = 21;

================

if (Lots == 0)
{
// if (Multiplier)
if (Multiplier == 1)
Lots = NormalizeDouble(LotSize, 2);
else
Lots = NormalizeDouble(LotSize, 2);
}
double xTp = 0;
if(TakeProfitPip!=0) xTp = Ask+(TakeProfitPip*Point);
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage,Bid+(StopLossPip*Point),Ask+(TakeProfitPip*Point), TradeComment, Reference, Green);

Error = GetLastError();
if (Error != 0)
Write("Error opening BUY order: " + ErrorDescription(Error) + " (C" + Error + ") Ask:" + Ask + " Slippage:" + Slippage);
else
{
TickPrice = Close[0];
TradeAllowed = false;
}
}

}

===================

if (Lots == 0)
{
// if (Multiplier)
if (Multiplier == 1)
Lots = NormalizeDouble(LotSize, 2);
else
Lots = NormalizeDouble(LotSize, 2);
}

double xTp = 0;
if(TakeProfitPip!=0) xTp = Bid-(TakeProfitPip*Point);

OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, Bid+(StopLossPip*Point),Bid-(TakeProfitPip*Point), TradeComment, Reference, Red);
//res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+(StopLoss*Point),Bid-(TakeProfit*Point), "Sell",MAGICMA,0,Red);

Error = GetLastError();
if (Error != 0)
Write("Error opening SELL order: " + ErrorDescription(Error) + " (D" + Error + ") Bid:" + Bid + " Slippage:" + Slippage);
else
{
TickPrice = Close[0];
TradeAllowed = false;
}
}
}

 

I believe I can confirm that for eg. Alpari Micro Account (it has to be a "live" account), you have to do OrderSend with zero SL and TP and then straightaway afterwards, modify the order with the required SL and TP to get it to work. I do an OrderSelect straight after so that I can use OrderOpenPrice() as the open price in the OrderModify parameter list.

That's what I changed in my code and it seems to work now.

I think I had the same problem with Axis trader so maybe I'll try it on there again some time.

The only other thing I did was make sure that when I sent the OrderSend, there was a magic number not zero on it.

Good luck to all.

Reason: