BarTimer_v1

Download script
Author: Copyright � 2008, Art Royal s.r.o.
BarTimer_v1

This tool is designed to provide traders with a real-time visual countdown and progress tracker directly on their trading charts. It serves as an on-screen timer that monitors the current "bar" (the individual time candle) and shows exactly how much time has elapsed and how much remains before the next candle opens.

How it Works

Visual Feedback The script places a text label on your chart screen. You can customize where this text appears, as well as its size, color, and font style to ensure it fits perfectly with your trading layout.

Real-Time Calculation The tool continuously calculates the difference between the current time and the opening time of the current candle. It then compares this duration against the total length of the period you are currently viewing (e.g., a 1-minute, 15-minute, or 1-hour chart).

Progress Tracking The logic provides two specific types of information:

  • The Countdown: It visualizes the remaining time and the time passed using a progress-style format.
  • Percentage Completion: In addition to the time, it calculates the exact percentage of the current candle's duration that has already passed (e.g., "50%").

Automatic Updates The script runs automatically in the background. Every time the market price updates, the tool recalculates these values instantly, ensuring that the progress bar and countdown remain accurate without you needing to manually refresh the chart. When you remove the tool from your chart, it is designed to automatically clean up and remove its visual elements.

5 Views
0 Downloads
0 Favorites
BarTimer_v1
//+------------------------------------------------------------------+
//|                                                     BarTimer.mq4 |
//|                               Copyright © 2008, Art Royal s.r.o. |
//|                                           Author: Vasyl Gumenyak |  
//|                                           http://www.jiport.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Art Royal s.r.o."
#property link      "http://www.jiport.com/"

#property indicator_chart_window
#property indicator_buffers 0

extern string FontName="Arial";
extern int FontSize=14;
extern color FontColor=White;
extern int Corner=0;// values [0-3]
extern int XDistance=250;
extern int YDistance=0;

int lenbase;
string s_base=":...:...:...:...:";

int init()
  {
   lenbase=StringLen(s_base);
   return(0);
  }

int deinit()
  {
   if (ObjectFind("BarTimer") != -1) ObjectDelete("BarTimer");
   return(0);
  }

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

int start()
  {
   int i=0,sec=0;
   double pc=0.0;
   string time="",s_end="",s_beg="";
   if (ObjectFind("BarTimer") == -1) {
     ObjectCreate("BarTimer" , OBJ_LABEL,0,0,0);
     ObjectSet("BarTimer", OBJPROP_XDISTANCE, XDistance);
     ObjectSet("BarTimer", OBJPROP_YDISTANCE, YDistance);
     ObjectSet("BarTimer", OBJPROP_CORNER, Corner);
   }
   sec=TimeCurrent()-Time[0];
   i=(lenbase-1)*sec/(Period()*60);
   pc=100.0*sec/(Period()*60);
   if(i>lenbase-1) i=lenbase-1;
   if(i>0) s_beg=StringSubstr(s_base,0,i);
   if(i<lenbase-1) s_end=StringSubstr(s_base,i+1,lenbase-i-1);
   time=StringConcatenate(s_beg,"|",s_end,"  ",DoubleToStr(pc,0),"%");
   ObjectSetText("BarTimer", time, FontSize, FontName, FontColor);

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

Comments