I am really new to MQL4, and still trying to grasp the concept. I would want to have an event handler to detect every candle bar opening (or every previous candle bar closing). Trying to wrap that around my head but it is not working:
So I have a function to check for the tick:
bool checkingFirstTick(){
datetime currentTime = iTime(Symbol(), Period(), 0);
if(currentTime - lastCandle > 0){
lastCandle = currentTime;
return true;
}
return false;
}
where lastCandle is a global variable.
Now when I put it into the OnTick() event:
void OnTick(){
Print("Ticking");
if(checkingFirstTick()){
Print("It's an opening!");
}
}
The It's an opening! statement never get printed.
Am I doing something fundamentally wrong? Or is there any more efficient way to listen to an opening of the candle bar, no matter what is the period I set?
