New Bar detection help.

 
i wanted to create an EA that only trade when new early of the current candle bar. i have already code it to detect new bar been form. but.... when i test it on 5 minutes chart. seems that sometimes it can alert new bar been form, and sometimes it cannot. i cannot figure it out.... blur.... can someone help me? thanks.


My code :


//+------------------------------------------------------------------+
//| my_bar_change.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
bool b_Check_New_Bar=false;

b_Check_New_Bar = Function_New_Bar(); // Function call
if (b_Check_New_Bar==false){
Alert("Waiting for new bar");
}else{
Alert("New bar just Exist.");
}
//----
return(0);
}
//+------------------------------------------------------------------+

bool Function_New_Bar(){
if(Volume[0]>1) return(false);
static datetime f_New_Time = 0;
bool f_New_Bar = false;
if (f_New_Time!= Time[0])
{
f_New_Time = Time[0];
f_New_Bar = true;
Alert(Time[0]);
}
return(f_New_Bar);
}


 
if(Volume[0]>1) return(false);
Remove the above line. Volume[] is unreliable.
 
kennyhubbard:
Remove the above line. Volume[] is unreliable.

still cannot, in early stage it suppose to have "Waiting for new bar". but, it alert when EA attach "New bar just Exist" when EA bee attach. pls help. yaiks..
 

We did this already in your other thread. Read the rest of the post and my point that Volume[] is unreliable along with code to solve it...

https://www.mql5.com/en/forum/128117

V

Reason: