# why does not while break work?

238

```int start()
{

//PIYASADA EMIR YOK ISE İKİ ADET EMİR AÇ
//MEVCUT BIDIN
//20 PIPS ASAGISINDA SATIM EMRİ AÇ
//20 PIPS YUKARISINDA ALIM EMRI AÇ
//1000 PIPS TP
//500 PIPS STOPLOSS
RefreshRates();

double XSAT=MarketInfo(Symbol(),MODE_BID);

double AL=NormalizeDouble(XAL,5);
double SAT=NormalizeDouble(XSAT,5);

while(OrdersTotal()>=2)break;
{
{

if(OrderSelect(OrderTicket(),SELECT_BY_TICKET)==true)
{
int X=OrderTicket();
Print(X);
int A=OrderDelete(X);
}
int Emirsat=OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-50*Point,3,Bid+500*Point,Bid-1000*Point,0);

if(OrderSelect(OrderTicket(),SELECT_BY_TICKET)==true)
{
int Y=OrderTicket();
Print(Y);
int B=OrderDelete(Y);
}
}

if (OrdersTotal()>=2)
{
Print(X,Y);

}

return;

}}```

the program gives error 148 because of too many orders.

i am triying to limit the orders by the number of 2.

but it continiously opens orders.

how can i resolve it ?

3422

There are no orders in your loop. The orders are located after the loop.

`while(OrdersTotal()>=2)break;`
Moderator
8293

`while(OrdersTotal()>=2)break;`

I'm confused by this.

Isn't it the case that if orders total is smaller than 2, the break will be ignored, but as the only action in the loop is the break, what difference does it make.

Unless i am missing something, this does nothing?

`if(OrderSelect(OrderTicket(),SELECT_BY_TICKET)==true)`

Where is the OrderSelect that gets OrderTicket ?

As far as I can see, your order sends are not subject to any conditions, so will open new orders every tick

17111

1. If ordersTotal is less thean two the while loop terminates and it does what is below. If OrdersTotal is two or greater it executes the statement that follows. That statement is the break, so the loop exits and then it does what is below. That while loop does NOTHING.
2. The braces below are NOT part of the while loop.
3. You can NOT use OrderTicket until you do a successful OrderSelect.
4. What are Function return values ? How do I use them ? - MQL4 forum
238

`while(OrdersTotal()>=2)break;`

how can i do it?

put these things into loop i mean .

Moderator
18058

pascalboy:

how can i do it?

put these things into loop i mean .

Why don't you simply do this . . .

```if(OrdersTotal() < 2)
(```

. . . or if you really need a loop

```while(OrdersTotal() < 2)
(```

. . . you may find that the number of orders is not updated quickly enough, you may need to add a short Sleep() at the end of the loop.