a_candle
Download scriptThis tool is designed as a visual dashboard for MetaTrader users who need to keep a close eye on live market dynamics. Its primary purpose is to provide a real-time countdown timer that displays exactly how much time remains before the current price candle closes.
How it Works
The script continuously monitors the relationship between your current chart timeframe and the actual passage of time. It performs the following logic in the background:
- Timeframe Detection: The tool automatically identifies which timeframe you are currently viewing (such as minutes, hours, or days).
- Dynamic Calculation: It calculates the difference between the exact moment the current candle opened and the current server time. By subtracting this duration from the total length of your chosen timeframe, it determines the remaining seconds until the next candle appears.
- Real-Time Formatting: The script converts these raw numbers into a human-readable clock format (Hours:Minutes:Seconds). It includes internal logic to ensure that single digits are correctly displayed with leading zeros (e.g., showing "05" instead of just "5") for a clean, consistent look.
Visual Display
Instead of cluttering your workspace with complex data, the tool creates a simple, high-visibility text label on your chart.
- Customizable Positioning: You can choose which corner of the screen the timer appears in.
- Readable Styling: It uses a clear font size and bright yellow coloring to ensure you can see the remaining time at a glance, even during fast-moving market conditions.
By providing this "live countdown," the tool helps traders better understand the rhythm of the market, allowing for more precise entries and exits based on candle expirations.
//+------------------------------------------------------------------+
//| CandleTime.mq4 |
//| Copyright © 2010, Elmare |
//| http://elmare.webnode.ru |
//+------------------------------------------------------------------+
#property copyright "Elmare © 2010"
#property link "http://elmare.webnode.ru/"
#property indicator_chart_window
//int per;
int tmp;
int sec;
int min;
int hor;
int barTime;
int curTime;
string cTime;
string sHor;
string sMin;
string sSec;
int per;
string sper;
extern int obCorner=3; // 0 - left up 3 - bottom right
extern int fsize=10; // font size
int init()
{
per=Period();
if (per<60){sper="M"+per;}
else if(per>=60&&per<60*24) {sper="H"+per/60+" ";}
else {sper="D"+per/(60*24);}
ObjectCreate("TimeLable12",OBJ_LABEL,0,0,0);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("TimeLable12");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
// int counted_bars=IndicatorCounted();
per=Period();
barTime=Time[0];
curTime=TimeCurrent();
tmp=curTime-barTime; //ñåêóíäû ñ ìîìåíòà îòêðûòèÿ ñâå÷è
tmp=per*60-tmp; //ñåêóíäû äî îêîí÷àíèÿ ñâå÷è
// {
min=tmp/60;
hor=min/60;
min=min-hor*60;
sec=tmp-min*60-hor*60*60;
// }
if (min<10){sMin="0"+min;}
else {sMin=""+min;}
if (sec==60) {sec=59;}
if (sec<10){sSec="0"+sec;}
else {sSec=""+sec;}
if(hor>0)
{
if (hor<10){sHor="0"+hor;}
else {sHor=""+hor;}
}
if (hor==0) {
cTime=sMin+":"+sSec;
}
else {cTime=sHor+":"+sMin+":"+sSec;}
//----
ObjectSet("TimeLable12",OBJPROP_CORNER,obCorner);
ObjectSetText("TimeLable12",cTime,fsize,"Microsoft Sans Serif",Yellow);
ObjectSet("TimeLable12",OBJPROP_XDISTANCE,5);
ObjectSet("TimeLable12",OBJPROP_YDISTANCE,3);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments