problems with break; and continue; code and error enclosed

 

Hello,

I am currently writing an EA (have a small amount of programming experience in other languages but nothing worth mentioning) that has a section for opening orders.

In the open buy orders section, the code works perfectly with no erros.

In the open sell section, the code was copied, pasted and then edited for an open sell trade but I have two errors involving the continue and break operators even though they are the same as the ones in the buy section that have no error

Could somebody have a look and see if theyu can spot what I'm doing wrong? The code is below and the error messages further below that.

Thanks in advance

while(true) //orders closing loop

{

if(total == 0 && opn_b == true) //no new orders, criteria to open buy true

{

RefreshRates();

SL = Bid - stoploss*Point; //calcualating stoploss

Alert("Attempted to open buy. Waiting for response...");

ticket = OrderSend(symb, OP_BUY, lts, Ask, 2, SL, NULL); //open buy position

if(ticket < 0)

{

Alert("Opened order Buy ",ticket,"."); //succes

return;

}

if(fun_error(GetLastError()) == 1) //processing error

continue;

return; //exit start

}

if(total == 0 && opn_s == true) //no new orders, criteria to open sell orders

{

RefreshRates();

SL = Ask + stoploss*Point; //calculating stoploss

Alert("Attempt to open Sell. Waiting for response...");

ticket = OrderSend(symb, OP_SELL, lts, Bid, 2, SL, NULL); //attempt to open order

if(ticket > 0) //success

{

Alert("Opened order Sell ",ticket,"");

return;

}

if(fun_error(GetLastError()) == 1) //processing error

continue;                                                                       //***ERROR***

return;

}

break;                                                          //****ERROR******

}

The errors are as follows:

'break' - 'break' or 'continue' used within some cycle only C:\LAPTOP FILES\business\mt4\experts\120 12 ma 5 opening orders.mq4 (75, 10)

'continue' - 'break' or 'continue' used within some cycle only C:\LAPTOP FILES\business\mt4\experts\120 12 ma 5 opening orders.mq4 (72, 16)

 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. There is nothing wrong with your posted coded. Comment out the while loop through the closing brace and find the real error.
 
Thanks, I'm not sure what you mean though. Do you mean take the code out of the while loop and try and spot the issue or something else?
 
fibios1:

Hello,

I am currently writing an EA (have a small amount of programming experience in other languages but nothing worth mentioning) that has a section for opening orders.

In the open buy orders section, the code works perfectly with no erros.

In the open sell section, the code was copied, pasted and then edited for an open sell trade but I have two errors involving the continue and break operators even though they are the same as the ones in the buy section that have no error

Could somebody have a look and see if theyu can spot what I'm doing wrong? The code is below and the error messages further below that.

Thanks in advance

The errors are as follows:

'break' - 'break' or 'continue' used within some cycle only C:\LAPTOP FILES\business\mt4\experts\120 12 ma 5 opening orders.mq4 (75, 10)

'continue' - 'break' or 'continue' used within some cycle only C:\LAPTOP FILES\business\mt4\experts\120 12 ma 5 opening orders.mq4 (72, 16)


It is not clear whether you are asking advice on the compiling or the execution of the code.

I don't think that it answers your question, but I think that you intend to test that ticket >0

ticket = OrderSend(symb, OP_BUY, lts, Ask, 2, SL, NULL); //open buy position

if(ticket < 0)   //This would mean that the order failed
Reason: