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
/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.
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?
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;
}
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.