Download MetaTrader 5
To add comments, please log in or register
Trade with MetaTarder 5. Download it right now!
Jusyer
41
Jusyer 2014.02.06 18:40 
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
28520
Alain Verleyen 2014.02.06 18:45  
Jusyer:

Hi.

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

Thanks.


You probably have to use RefreshRates()
Jusyer
41
Jusyer 2014.02.06 18:48  
I've used it and does not work
Alain Verleyen
Moderator
28520
Alain Verleyen 2014.02.06 19:06  
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 2014.02.06 19:44  
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
28520
Alain Verleyen 2014.02.06 20:15  
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