Download MetaTrader 5

why does not while break work?

To add comments, please log in or register
Download MQL5 library codes via MetaTrader. It is convenient!
pascalboy
238
pascalboy 2013.12.02 17:30 
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 XAL=MarketInfo(Symbol(),MODE_ASK);
double XSAT=MarketInfo(Symbol(),MODE_BID);


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


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

int Emiral=OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+50*Point,3,Ask-500*Point,Ask+1000*Point,0);

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 ?

Ex Ovo Omnia
3156
Ex Ovo Omnia 2013.12.02 17:58  

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

while(OrdersTotal()>=2)break;
Keith Watford
Moderator
9650
Keith Watford 2013.12.02 18:21  
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

whroeder1
14532
whroeder1 2013.12.02 21:14  
  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
pascalboy
238
pascalboy 2013.12.03 15:48  
while(OrdersTotal()>=2)break;

how can i do it?

put these things into loop i mean .

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.12.03 17:20  
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.

To add comments, please log in or register