Download MetaTrader 5

Update predefined variables inside "while"

To add comments, please log in or register
Jusyer
41
Jusyer  
int start()
{
.
.
.
if ((Open[1]<Close[1]) && (hour ==TimeHour(TimeLocal()))) //Here, Open[1] and Close[1] refers to last bar closed
{
   OrderSend(Symbol(),tipoop2,Lotesvinc,tipoopprice,3,SL,TP,NULL,0,0,White);
   cnt=1;
   while (cnt==1)
   {
       if ((Open[1]>Close[1]) && (hour ==TimeHour(TimeLocal())-1)) break;    //Here, Open[1] and Close[1] refers to penultimate bar closed, no last bar closed. No update inside "while"
       if ((Open[1]<Close[1]) && (hour ==TimeHour(TimeLocal())-1))           //Here, Open[1] and Close[1] refers to penultimate bar closed, no last bar closed. No update inside "while"
       {
          OrderSend(Symbol(),tipoop2,Lotesvinc*2,tipoopprice,3,SL,TP,NULL,0,0,White);
          cnt=2;
          while (cnt==2)
          {
          .
          .
          .
       }    
   }
}
.
.

Hi.

Code repeat several times. Why predefined variables not update inside "while"?

Thanks.

Alain Verleyen
Moderator
35118
Alain Verleyen  
Jusyer:

Hi.

Code repeat several times. Why predefined variables not update inside "while"?

Thanks.


You probably have to use RefreshRates()
Jusyer
41
Jusyer  
I've used it and does not work
Alain Verleyen
Moderator
35118
Alain Verleyen  
Jusyer:
I've used it and does not work
What does that mean ? Show your code, and some logs to demonstrate your issue.
Jusyer
41
Jusyer  
if ((Open[1]>Close[1]) && (RefreshRates()) && (hour ==TimeHour(TimeLocal())-1))
By including it in the condition its value is true, but not update Open[] and Close[]
Alain Verleyen
Moderator
35118
Alain Verleyen  
Jusyer:

With the new mql4, if the condition Open[1]>Close[1] is false, the RefreshRates will never be executed. Don't include RefreshRates() in an if condition.

See this topic MetaTrader 4 Build 600 with Updated MQL4 Language and Market of Applications Released :

Shortened conditions check is now used in logical operations, unlike the old MQL4 version where all expressions have been calculated and the check has been performed afterwards. Suppose there is a check of two conditions with the use of logical AND

  if(condition1 && condition2)
    {
     // some block of operations
    }
If condition1 expression is false, calculation of condition2 expression is not performed, as false && true result is still equal to false.
To add comments, please log in or register