Ordersend strange behaviour

 

Hy every clever people of this forum,

I'm new. I've a strange behaviour of the programm in my EA. I want launch an order by Ordersend function, when "isCrossed" mets the conditions (1 or 2). But when I activate my EA only first case (in this example case 2) is running. In other words if I change my EA, changing at first position "case 1", only this case is is running.

Any answar?

Thanks in advance

MauroFap

.....

int counted_bars=IndicatorCounted();
total = OrdersTotal();
if(total<3)
{
for(cnt=0;cnt<total;cnt++)
{
switch(isCrossed)
{
case 2:
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,8,
SLmin,Bid-TakeProfit*Point,
"My EA sta vendendo",12345,0,Green);
OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
{
OrderClose(OrderTicket(),OrderLots(),
Bid-TakeProfit*Point,3,Violet);
}
}
case 1:
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,8,
SLmag,Ask+TakeProfit*Point,
"My EA sta comprando",12345,0,Green);
OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
{
OrderClose(OrderTicket(),OrderLots(),
Ask+TakeProfit*Point,3,Violet);
}
}
return(0);
}
}
}
return(0);

 
maurofap wrote >>

Hy every clever people of this forum,

I'm new. I've a strange behaviour of the programm in my EA. I want launch an order by Ordersend function, when "isCrossed" mets the conditions (1 or 2). But when I activate my EA only first case (in this example case 2) is running. In other words if I change my EA, changing at first position "case 1", only this case is is running.

Any answar?

Thanks in advance

MauroFap

.....

int counted_bars=IndicatorCounted();
total = OrdersTotal();
if(total<3)
{
for(cnt=0;cnt<total;cnt++)
{
switch(isCrossed)
{
case 2:
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,8,
SLmin,Bid-TakeProfit*Point,
"My EA sta vendendo",12345,0,Green);
OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
{
OrderClose(OrderTicket(),OrderLots(),
Bid-TakeProfit*Point,3,Violet);
}
}
case 1:
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,8,
SLmag,Ask+TakeProfit*Point,
"My EA sta comprando",12345,0,Green);
OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
{
OrderClose(OrderTicket(),OrderLots(),
Ask+TakeProfit*Point,3,Violet);
}
}
return(0);
}
}
}
return(0);

I haven't used a switch in MT4 code yet, but my first guess is that you are not using break; at the end of the snippet in each case. This breaks you out of the switch. Why are you closing out the trades right after opening them? That seems really odd. Oh yeah, and you can put your code snippet in a box by clicking on the SRC button above and it will maintain the correct formatting of your code.

Reason: