b-clock_spread

Download script
Author: Copyright � 2005, Nick Bilak
b-clock_spread

This tool serves as a real-time visual countdown and market data tracker designed to help traders monitor the remaining duration of the current price bar on their charts. By providing immediate feedback on time progression, it allows users to better understand the rhythm of market movements.

How the Logic Works

The script operates by constantly calculating the difference between the current moment in time and the exact point when the next candle (bar) is scheduled to open. It breaks down this remaining duration into hours, minutes, and seconds based on the specific timeframe you are currently viewing.

Key functionalities include:

  • Dynamic Time Calculation: The tool automatically detects your current chart settings (such as a 1-minute, 15-minute, or 4-hour chart) and calculates how much time is left in that specific interval.
  • Context-Aware Display: To keep the interface clean, the display adapts to your timeframe. On shorter periods (under 60 seconds), it simplifies the display to show minutes and seconds. For longer periods, it expands to show hours, minutes, and seconds.
  • Visual Positioning: Rather than appearing as a static list in a menu, the information is rendered directly on the chart. It is programmed to sit at a specific distance from the current candle's price, ensuring that the countdown remains visible without obstructing the actual price action.
  • Spread Monitoring: With an optional setting enabled, the tool also captures and displays the "spread"—the difference between the buying and selling prices—providing a quick snapshot of current market liquidity alongside the time countdown.
  • Automatic Updating: The script is designed to refresh its calculations instantly. As every second passes, the countdown updates in real-time, providing a live "clock" for the active trading candle.

In summary, this script acts as a specialized dashboard element that transforms raw time data into an easy-to-read visual aid, helping traders stay synchronized with the market's pace.

Price Data Components
Series array that contains open time of each bar
10 Views
0 Downloads
0 Favorites
b-clock_spread
//+------------------------------------------------------------------+
//|                                                      b-clock.mq4 |
//|                                     Core time code by Nick Bilak |
//|        http://metatrader.50webs.com/         beluck[at]gmail.com |
//|            custom font size color and spread modified by tembox  | 
//+------------------------------------------------------------------+

#property copyright "Copyright © 2005, Nick Bilak"
#property link      "http://metatrader.50webs.com/"

#property indicator_chart_window

extern string FontName   = "Trebuchet MS";
extern int    FontSize   = 12;
extern color  FontColor  = Aqua;
extern bool   ShowSpread = True;
extern int    Distance   = 10;


//---- buffers
double s1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    return(0);   
  }
  
int deinit()
  {
    ObjectDelete("time");   
    return(0);   
  }
  
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
	 double i;
    int m, s, k, h;
    string ss;

   m = Time[0]+Period()*60-CurTime();
   i = m /60.0;
   s = m % 60;
   m = (m - m % 60) / 60;
   h = i / 60;
   k = m -(h*60);
    
   // Comment( h + " hours " + k + " minutes " + s + " seconds left to bar end");
    ObjectDelete("time");   
//----
    if(ObjectFind("time") != 0)
      { 
        if (Period()<=60) { ss = "< " + DoubleToStr(k,0) + ":" + DoubleToStr(s,0); }
        else { ss = "< " + DoubleToStr(h,0) + ":"+ DoubleToStr(k,0) + ":" + DoubleToStr(s,0); }
        
        if (ShowSpread) 
            { ss = ss +" ("+(Ask-Bid)/Point+")"; }
        
        ObjectCreate("time", OBJ_TEXT, 0, Time[0]+(Distance* PeriodSeconds(PERIOD_CURRENT)), (High[0]+Close[0])/2 ); 
        ObjectSetText("time", ss, FontSize, FontName, FontColor);
      }
    else
      {
        ObjectMove("time", 0, Time[0]+(Distance* PeriodSeconds(PERIOD_CURRENT)), (High[0]+Close[0])/2);
      }
    return(0);
  }
//+------------------------------------------------------------------+


Comments