Author: Copyright � 2010, karceWZROKIEM
EndOfBar

This script is designed to serve as a real-time visual countdown and monitoring tool for traders using the MetaTrader platform. Its primary purpose is to help users keep track of how much time remains before a candle (or "bar") closes across various different timeframes simultaneously.

Core Functionality

The logic operates by constantly calculating the difference between the current market time and the start of the next candle for several standard trading periods, including:

  • Short-term: 1-minute, 5-minute, and 15-minute charts.
  • Medium-term: 30-minute and 1-hour charts.
  • Long-term: 4-hour and Daily charts.

How it Works for the User

The script performs three main actions to provide this information:

1. Dynamic Countdown Display On the trading chart itself, the tool identifies your current active timeframe and displays a live countdown of the minutes and seconds remaining until that specific bar ends. This allows you to see exactly how much "room" is left in the current price action without having to manually calculate the time.

2. Proximity Alerts (Warning System) The script includes a customizable "warning" logic. For every timeframe mentioned, there is a specific threshold (set by the user) that triggers a visual notification. If the remaining time for any given period drops below these pre-defined limits, the script highlights that specific timeframe on your screen. This helps traders stay aware of upcoming major candle closes that might impact price volatility or signal a change in trend.

3. On-Screen Dashboard In addition to the visual markers on the chart, the script generates a text-based summary (comment) in a corner of your screen. This dashboard provides a comprehensive list showing:

  • The remaining time for every supported timeframe.
  • The specific warning thresholds for each period.

Summary of Benefits

Instead of requiring the trader to constantly look at the clock or guess when a new hour or day will begin, this tool centralizes that information. It acts as a "time management" assistant, ensuring you are always aware of the lifecycle of the candles you are currently analyzing, while specifically drawing your attention to those approaching their expiration point.

Price Data Components
Series array that contains open time of each bar
4 Views
0 Downloads
0 Favorites
EndOfBar
//+------------------------------------------------------------------+
//|                                                    EndingBar.mq4 |
//|                                                    karceWZROKIEM | 
//+------------------------------------------------------------------+

#property copyright "Copyright © 2010, karceWZROKIEM"
#property link      "http://kampno.pl/"

#property indicator_chart_window

extern bool  ShowComment = true;
extern int   EndingTimeM1  = 10;
extern int   EndingTimeM5  = 30;
extern int   EndingTimeM15 = 60;
extern int   EndingTimeM30 = 120;
extern int   EndingTimeH1  = 300;
extern int   EndingTimeH4  = 600;
extern int   EndingTimeD1  = 1800;
extern color ClockColor = Black;
extern color EndingColor = Red;


string comm, ending;

//+------------------------------------------------------------------+

string TimeLeft(int period)
{
	return (TimeToStr( (iTime(NULL,period,0)+period*60-TimeCurrent( )), TIME_MINUTES|TIME_SECONDS) );
}

bool isEnding(int period, int endingtime)
{
	return ( (iTime(NULL,period,0)+period*60-TimeCurrent( )) < endingtime );
}

void Clear()
{
	ObjectDelete("timeCurr");
	ObjectDelete("timeEnding");
}

void Generate(int period)
{
	ending = "";
   int indent=10, i;

   for(i=0; i<indent; i++)  ending = StringConcatenate(" ", ending);
   ObjectCreate("timeCurr", OBJ_TEXT, 0, Time[0], Close[0]);
	ObjectSetText("timeCurr", StringConcatenate(ending,TimeLeft(Period())), 8, "fixedsys", ClockColor);
	
	indent += 21;
   for(i=0; i<indent; i++)  ending = StringConcatenate(" ", ending);
   
   if(isEnding(PERIOD_M1, EndingTimeM1))   ending = StringConcatenate(ending," M1");
   else                     indent+=2;
   if(isEnding(PERIOD_M5, EndingTimeM5))   ending = StringConcatenate(ending," M5");
   else                     indent+=2;
   if(isEnding(PERIOD_M15, EndingTimeM15)) ending = StringConcatenate(ending," M15");
   else                     indent+=3;
   if(isEnding(PERIOD_M30, EndingTimeM30)) ending = StringConcatenate(ending," M30");
   else                     indent+=3;
   if(isEnding(PERIOD_H1, EndingTimeH1))   ending = StringConcatenate(ending," H1");
   else                     indent+=2;
   if(isEnding(PERIOD_H4, EndingTimeH4))   ending = StringConcatenate(ending," H4");
   else                     indent+=2;
   if(isEnding(PERIOD_D1, EndingTimeD1))   ending = StringConcatenate(ending," D1");
   else                     indent+=2;

   for(i=0; i<indent; i++)  ending = StringConcatenate(ending," ");
   
   if (indent < 41+18)
   {
      ObjectCreate("timeEnding", OBJ_TEXT, 0, Time[0], Close[0]);
	   ObjectSetText("timeEnding", ending, 8, "fixedsys", EndingColor);
   }
}

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
	return(0);
}

int deinit()
{
	ObjectDelete("time");
	Comment("");
	return(0);
}
//void deinit() 
//  {
//   Comment("");
//  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
	comm = ""; 

	//---
	//   comm =   
	//"Current TF:  " +  h + " hour(s) "+  (m-(h*60)) + " min. " + s + " sec. left to bar end;\n";
	if(ShowComment)
      Comment( StringConcatenate(
         "  D1: ", TimeLeft(PERIOD_D1), ", warn: ", EndingTimeD1, "s\n",
         "  H4: ", TimeLeft(PERIOD_H4), ", warn: ", EndingTimeH4, "s\n",
         "  H1: ", TimeLeft(PERIOD_H1), ", warn: ", EndingTimeH1, "s\n",
         "M30: ", TimeLeft(PERIOD_M30), ", warn: ", EndingTimeM30, "s\n",
         "M15: ", TimeLeft(PERIOD_M15), ", warn: ", EndingTimeM15, "s\n",
         "  M5: ", TimeLeft(PERIOD_M5), ", warn: ", EndingTimeM5, "s\n",
         "  M1: ", TimeLeft(PERIOD_M1), ", warn: ", EndingTimeM1, "s\n") 
      );

	Clear();
	Generate(Period());

	return(0);
}
//+------------------------------------------------------------------+


Comments