Is there a variable to show if the current candle is still open

 
or closed?

or is there a function that will show if the current candle on a certain time frame, if it is still open or has finished?

thanks
 
iTime();

use a global variable datetime x;
then give a x value x=iTime(symbol,period,place) inside your code. It should be the place when you want to start looking at a active bar. If x doen't equal to iTime at the moment, new bar has been created.

datetime x
 
if(x!=iTime(Symbol(), PERIOD_M30, 0) Alert("New bar!!!");
 
//...... buy moment
x=iTime(Symbol(), PERIOD_M30, 0);
This code looks at 30-minute period (it doesn't matter which timeframe your code is working!!). If you change PERIOD_M30 to 0 then it takes active timeframe, whatever it is at the moment.

hope it helps!

zolero
Reason: