Batfink Clock[1]

Download script
Author: Jerome
Batfink Clock[1]

This script is designed as a multi-timezone clock utility for the MetaTrader trading platform. Its primary purpose is to provide a real-time visual reference of various global market hours directly on your trading chart, ensuring that traders can keep track of significant sessions (like London or New York) regardless of their own local time.

Core Functionality

The script automatically calculates and displays the current time for several key geographical locations simultaneously. Instead of requiring the user to manually convert times, the tool handles the math in the background based on your specific brokerage settings.

Key Features and Logic:

  • Global Market Tracking: The clock tracks specific major financial hubs, including London, Tokyo, New York, and GMT (Greenwich Mean Time).
  • Broker Synchronization: Because different brokers may operate in different timezones, the script allows you to input your broker's specific offset. It uses this as a "base" to ensure all other converted times remain accurate relative to your live trading environment.
  • Local Time Integration: You have the option to toggle your own local timezone. If enabled, the script will display your personal local time alongside the global market clocks.
  • Daylight Savings Support: The logic includes a setting to account for Daylight Savings Time (DST) shifts, helping maintain accuracy throughout the year.
  • Customizable Display: The tool is highly customizable regarding its appearance on your screen. You can choose:
    • The corner of the chart where the clock appears (e.g., top-left, bottom-right).
    • The specific distance from the edge of the screen.
    • The colors for both the labels (titles) and the actual time digits.

How it Works for the User:

Once installed, the script creates a clean, text-based dashboard on your chart. It constantly refreshes to show the current hour and minute for each region. This allows traders to see at a glance when markets are opening or closing in different parts of the world, facilitating better timing for trade entries and exits without needing to leave the platform to check a separate clock.

Price Data Components
Series array that contains open time of each bar
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Batfink Clock[1]
//+------------------------------------------------------------------+
//|                                                        Clock.mq4 |
//|                                                           Jerome |
//|                                               whitnell@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Jerome"
#property link      "whitnell@gmail.com"

//------------------------------------------------------------------
// Instructions
//    BrokerTZ  - Timezone of your Broker (in hours from GMT)
//    LocalTz   - Your timezone in hours from GMT
//    DST       - Is it daylight savings time?
//    ShowLocal - Set to tru to show your local time zone
//    corner    - 0 = top left, 1 = top right, 2 = bottom left, 3 = bottom right
//    topOff    - pixels from top to show the clock
//    labelColor- Color of label
//    clockColor- Color of clock
//
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red


//---- input parameters
extern double       BrokerTZ=3;
extern double       LocalTz=-4;
extern bool         DST=true;
extern bool         ShowLocal=false;
extern int          corner=0;
extern int          topOff=100;
extern color        labelColor=Gray;
extern color        clockColor=White;

//---- buffers
double ExtMapBuffer1[];
int LondonTZ = 1;
int TokyoTZ = 9;
int NewYorkTZ = -4;

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int dstDelta=-1;
   if ( DST )
      dstDelta = 0;
   
   datetime brokerTime = CurTime();
   datetime GMT = brokerTime - (BrokerTZ+dstDelta)*3600;
   datetime local = GMT + (LocalTz + dstDelta) * 3600;
   datetime london = GMT + (LondonTZ + dstDelta) * 3600;
   datetime tokyo = GMT + (TokyoTZ + dstDelta) * 3600;
   datetime newyork = GMT + (NewYorkTZ + dstDelta) * 3600;
   
   //Print( brokerTime, " ", GMT, " ", local, " ", london, " ", tokyo, " ", newyork  );
   string GMTs = TimeToStr( GMT, TIME_MINUTES );
   string locals = TimeToStr( local, TIME_MINUTES  );
   string londons = TimeToStr( london, TIME_MINUTES  );
   string tokyos = TimeToStr( tokyo, TIME_MINUTES  );
   string newyorks = TimeToStr( newyork, TIME_MINUTES  );
   string brokers = TimeToStr( CurTime(), TIME_MINUTES );
   
   //string timeText = " Local: " + locals +  " GMT: " +GMTs +  " | London:" +londons + 
   //   " | New York: " +newyorks + " | Tokyo: " + tokyos ;
   
   //ObjectSetText( "times", timeText, 10, "Arial", clockColor );
   if ( ShowLocal ) {
      ObjectSetText( "locl", "Local:", 10, "Arial", labelColor );
      ObjectSetText( "loct", locals, 10, "Arial", clockColor );
   }
   ObjectSetText( "gmtl", "GMT", 10, "Arial", labelColor );
   ObjectSetText( "gmtt", GMTs, 10, "Arial", clockColor );
   ObjectSetText( "nyl", "New York:", 10, "Arial", labelColor );
   ObjectSetText( "nyt", newyorks, 10, "Arial", clockColor );
   ObjectSetText( "lonl", "London:", 10, "Arial", labelColor );
   ObjectSetText( "lont", londons, 10, "Arial", clockColor );
   ObjectSetText( "tokl", "Tokyo:", 10, "Arial", labelColor );
   ObjectSetText( "tokt", tokyos, 10, "Arial", clockColor );
   ObjectSetText( "brol", "Broker:", 10, "Arial", labelColor );
   ObjectSetText( "brot", brokers, 10, "Arial", clockColor );
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int ObjectMakeLabel( string n, int xoff, int yoff ) {
   ObjectCreate( n, OBJ_LABEL, 0, 0, 0 );
   ObjectSet( n, OBJPROP_CORNER, corner );
   ObjectSet( n, OBJPROP_XDISTANCE, xoff );
   ObjectSet( n, OBJPROP_YDISTANCE, yoff );
   ObjectSet( n, OBJPROP_BACK, true );
}

int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   
   int top=topOff;
   if ( ShowLocal ) {
      ObjectMakeLabel( "locl", 90, top );
      ObjectMakeLabel( "loct", 45, top );
   }
   ObjectMakeLabel( "gmtl", 90, top-15 );
   ObjectMakeLabel( "gmtt", 45, top-15 );
   ObjectMakeLabel( "nyl", 90, top-30 );
   ObjectMakeLabel( "nyt", 45, top-30 );
   ObjectMakeLabel( "lonl", 90, top-45 );
   ObjectMakeLabel( "lont", 45, top-45 );
   ObjectMakeLabel( "tokl", 90, top-60 );
   ObjectMakeLabel( "tokt", 45, top-60 );
   ObjectMakeLabel( "brol", 90, top-75 );
   ObjectMakeLabel( "brot", 45, top-75 );
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete( "locl" );
   ObjectDelete( "loct" );
   ObjectDelete( "nyl" );
   ObjectDelete( "nyt" );
   ObjectDelete( "gmtl" );
   ObjectDelete( "gmtt" );
   ObjectDelete( "lonl" );
   ObjectDelete( "lont" );
   ObjectDelete( "tokl" );
   ObjectDelete( "tokt" );
   ObjectDelete( "brol" );
   ObjectDelete( "brot" );
//----
   return(0);
  }

Comments