b-clock modified_v2
Download scriptThis script is designed as a visual time-tracking tool for the MetaTrader platform. Its primary purpose is to provide traders with a real-time countdown of how much time remains before the current candle (or "bar") on a chart closes.
How the Logic Works
The core functionality operates by comparing three different data points:
- The Current Market Time: The specific time established when the current price bar began.
- The Trading Period: The set duration of the timeframe you are viewing (for example, a 5-minute chart, a 1-hour chart, etc.).
- The Real-Time Clock: The actual passing of seconds on your computer's clock.
By calculating the difference between the start time plus the total period duration against the current actual time, the script determines exactly how many minutes and seconds are left until the next price update.
Visual Features
The script provides this information in two distinct ways to ensure it is easy for the user to read:
- On-Screen Comment: It generates a dynamic text notification in the top corner of your chart area, displaying the remaining time in a "minutes and seconds" format.
- Floating Chart Label: The script creates a specific visual text object on the chart itself. This label is programmed to follow the current price action; as new prices appear, the label moves automatically to stay positioned near the latest price point. It displays the countdown in a bold, red font to ensure it remains highly visible against various background colors.
Practical Application
For a trader, this tool removes the need to manually calculate expiration times or keep a separate clock handy. It provides an instant visual cue of how much "room" is left in the current price action, which is particularly useful for managing entries and exits close to the end of a specific timeframe.
//+------------------------------------------------------------------+
//| b-clock.mq4 |
//| Core time code by Nick Bilak |
//| http://metatrader.50webs.com/ beluck[at]gmail.com |
//| modified by adoleh2000 and dwt5 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nick Bilak"
#property link "http://metatrader.50webs.com/"
#property indicator_chart_window
//---- buffers
double s1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double i;
int m, s, k;
m = Time[0] + Period()*60 - CurTime();
i = m / 60.0;
s = m % 60;
m = (m - m % 60) / 60;
Comment(m + " minutes " + s + " seconds left to bar end");
ObjectDelete("time");
//----
if(ObjectFind("time") != 0)
{
ObjectCreate("time", OBJ_TEXT, 0, Time[2], Close[0] + 0.003);
ObjectSetText("time", "<" + m + ":" + s, 12, "Arial Black", Red);
}
else
{
ObjectMove("time", 0, Time[0], Close[0] + 0.0005);
}
return(0);
}
//+------------------------------------------------------------------+
Comments