Error 130 driving me nuts

 

This is making me crazy. I'm using Alpari's MT.


I keep getting 130 errors. Not *always* just most of the time. See how an order worked ok at 2:25 in the example below.


I had wanted to set TP and SL to 0 (ie, not set) but that didnt work. So I put an outrageously large range instead. Same results. Is there some other logic to Error 130?


Any all help appreciated.


2009.02.22 22:23:59    2009.02.23 06:20  SomeEA GBPUSD,M5: Bid= 1.4527 Spread = 0.0003 TP Price = 1.5527 SL Price = 1.3527
2009.02.22 22:23:59    2009.02.23 06:20  SomeEA GBPUSD,M5: SL=6
2009.02.22 22:23:59    2009.02.23 06:20  SomeEA GBPUSD,M5: OrderSend error 130
2009.02.22 22:23:59    2009.02.23 06:15  SomeEA GBPUSD,M5: Bid= 1.4527 Spread = 0.0003 TP Price = 1.5527 SL Price = 1.3527
2009.02.22 22:23:59    2009.02.23 06:15  SomeEA GBPUSD,M5: SL=6
2009.02.22 22:23:59    2009.02.23 06:15  SomeEA GBPUSD,M5: OrderSend error 130
2009.02.22 22:23:59    2009.02.23 06:15  SomeEA GBPUSD,M5: close #139 buy 0.10 GBPUSD at 1.4413 sl: 1.3413 tp: 1.5413 at price 1.4527
2009.02.22 22:23:59    2009.02.23 02:25  SomeEA GBPUSD,M5: Ask = 1.4413 Spread = 0.0003 TP Price = 1.5413 SL Price = 1.3413
2009.02.22 22:23:59    2009.02.23 02:25  SomeEA GBPUSD,M5: SL=6
2009.02.22 22:23:59    2009.02.23 02:25  SomeEA GBPUSD,M5: open #139 buy 0.10 GBPUSD at 1.4413 sl: 1.3413 tp: 1.5413 ok
2009.02.22 22:23:59    2009.02.23 02:20  SomeEA GBPUSD,M5: Bid= 1.4385 Spread = 0.0003 TP Price = 1.5385 SL Price = 1.3385
2009.02.22 22:23:59    2009.02.23 02:20  SomeEA GBPUSD,M5: SL=6
2009.02.22 22:23:59    2009.02.23 02:20  SomeEA GBPUSD,M5: OrderSend error 130
2009.02.22 22:23:59    2009.02.23 02:15  SomeEA GBPUSD,M5: Bid= 1.4376 Spread = 0.0003 TP Price = 1.5376 SL Price = 1.3376
2009.02.22 22:23:59    2009.02.23 02:15  SomeEA GBPUSD,M5: SL=6
2009.02.22 22:23:59    2009.02.23 02:15  SomeEA GBPUSD,M5: OrderSend error 13

 

This is the code used to place the order:


         res = OrderSend(Symbol(),OP_BUY, Lots,Ask,3,SLPrice,TPPrice,"",MAGIC,0,Blue);


and


         res = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid-SL*Point,Bid+TP*Point,"",MAGIC,0,Red);
 

/slaps forehead


ok several things were wrong. Fixed now. *sigh*


1) There are limits on the TP/SL it seems


2) This should not have been in there

Bid-SL*Point,Bid+TP*Point
 
moonstar:

/slaps forehead


ok several things were wrong. Fixed now. *sigh*


1) There are limits on the TP/SL it seems


2) This should not have been in there

Well without seeing more of the code I can only speculate, the most likely cause is you have your TP and SL set the wrong way.


SL should be above a sell order, TP should be below it.

SL should be below a buy order, TP should be above it.


Swap the plus and minus around on each, unless of course the initial values you are using are also the opposite signs.

 
Onyx:

Well without seeing more of the code I can only speculate, the most likely cause is you have your TP and SL set the wrong way.


SL should be above a sell order, TP should be below it.

SL should be below a buy order, TP should be above it.


Swap the plus and minus around on each, unless of course the initial values you are using are also the opposite signs.


Thank you Onyx! You're exactly right. That makes a lot of sense.


When I said fixed above, it only fixed it with values of 0. With the changes you suggested, it now works with TP/SL specified as well.


What I find very confusing, is why did some orders work at all when the code was so obviously broken?


 
moonstar:


Thank you Onyx! You're exactly right. That makes a lot of sense.


When I said fixed above, it only fixed it with values of 0. With the changes you suggested, it now works with TP/SL specified as well.


What I find very confusing, is why did some orders work at all when the code was so obviously broken?




This would take even greater speculation on my part, without a clearer idea of how your SL and TP points are both calculated.

Going solely by your initial two posts, your Buying Order Code seems correctly aligned and thus the buy order went through, whereas the rest of your orders in that log were sell orders and thus didn't work correctly, as they need to set be in the opposite relative direction to the buy orders SL and TP.

 

Hi,

I have a problem (OrderClose error 138), but I don't no why. Can you help me?

I'd like to put an SL into this EA...

void CheckForClose()
{
double ma;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if(Close[1]<ma) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
}
{
if(Ask<OrderOpenPrice()-StopLoss*Point) OrderClose(OrderTicket(),OrderLots(),Bid,0,Green);
break;
}
if(OrderType()==OP_SELL)
{
if(Close[1]>ma) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
}
{
if(Bid>OrderOpenPrice()+StopLoss*Point) OrderClose(OrderTicket(),OrderLots(),Ask,0,Green);
break;
}
}