Only check price (or do certain actions) after each candle close

 

Hi,

Probably newbie question (that's what i am),

I would like to do certain actions (like check price, change variables) based on Candle close actions rather than on each tick.

Could somebody provide me with sample code or another post for me to learn. Found some topics but i'm confused 

It would help me a lot.

thanks,

 
giobenoni:

Hi,

Probably newbie question (that's what i am),

I would like to do certain actions (like check price, change variables) based on Candle close actions rather than on each tick.

Could somebody provide me with sample code or another post for me to learn. Found some topics but i'm confused 

It would help me a lot.

thanks,

Hello you can read all the information about handling new bar at the following link

https://www.mql5.com/en/articles/159

or you can simply use this code:

datetime NewCandleTime=TimeCurrent();
bool IsNewCandle(){
   if(NewCandleTime==iTime(Symbol(),0,0)) return false;
   else{
      NewCandleTime=iTime(Symbol(),0,0);
      return true;
   }
}
 
void OnTick(){
 
   if(IsNewCandle()){
   
   }
 
}
The "New Bar" Event Handler
The "New Bar" Event Handler
  • www.mql5.com
Authors of indicators and experts have always been interested in writing the compact code in terms of execution time. You can approach to this problem from different angles. From this broad topic in this article we will cover the problem, that is seemingly already have been solved: check for a new bar. This is quite a popular way to limit the...
 
thank you Nikolay