Download MetaTrader 5

Bar counter stops after first bar

To add comments, please log in or register
Deposit to your account in any convenient way. There are 4 of them here!
Akshay
48
Akshay 2016.01.06 12:14 

Hi,

I'm trying to find if there are 3 consecutive up or down bars with the below EA

the problem is that it stops counting after first bar is complete (check it on M1)

I will be glad if someone could help me here.


//--------------------------------------------------------------------

bool New_Bar=false;                             // Flag of a new bar
bool RefreshRates();
//--------------------------------------------------------------------
int start()                                     // Special funct. start()
  {
   
 int upbars,  downbars;
//--------------------------------------------------------------------
   Fun_New_Bar();                               // Function call
   if (New_Bar==false)                          // If bar is not new..
      return(0);                                   // ..return
//--------------------------------------------------------------------



//----Looping through subject and Alert

if (  New_Bar  == true)          
    
{    

  
  
  if (Close[0] > Open[0] && Close[1] > Open[1] && Close[2] > Open[2])
  upbars = 3;
  
   if (Close[0] < Open[0] && Close[1] < Open[1] && Close[2] < Open[2])
   downbars = 3;
 
  
   }
     Comment(upbars," UP Bars","\n", downbars," DOWN Bars ");
   return(0);  
}   
                                      // Exit start()
//--------------------------------------------------------------------
void Fun_New_Bar()                              // Funct. detecting ..
  {                                             // .. a new bar
   static datetime New_Time=0;                  // Time of the current bar
   New_Bar=false;                               // No new bar
   if(New_Time!=Time[0])                        // Compare time
     {
      New_Time=Time[0];                         // Now time is so
      New_Bar=true;                             // A new bar detected
     }
     
     
  }
//--------------------------------------------------------------------
Keith Watford
Moderator
9603
Keith Watford 2016.01.06 13:50  
When a new bar opens, on the first tick, Open[0]=Close[0], so your condition checks will return false unless the first tick of the bar is missed
Akshay
48
Akshay 2016.01.06 15:06  

Thanks a lot for your suggestion it worked correctly after modifying the condition

Open[0] <=Close[0] and Close[0] >= Open[0] :)

To add comments, please log in or register