//+------------------------------------------------------------------+ //| b-clock.mq5 | //| Core time code by Nick Bilak | //| Modified for MT5 positioning | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, Nick Bilak" #property link "http://metatrader.50webs.com/" #property version "1.20" #property indicator_chart_window //--- Input parameters input color InpColor = clrWhite; // Clock Color input int InpFontSize = 10; // Font Size input string InpFontName = "Arial"; // Font Name //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectDelete(0, "time_clock"); Comment(""); // Clear any old comments } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { if(rates_total < 1) return(0); // Set arrays to Series (index 0 is current bar) ArraySetAsSeries(time, true); ArraySetAsSeries(close, true); // Calculate time remaining [cite: 7] datetime currentBarTime = time[0]; long secondsLeft = (long)currentBarTime + PeriodSeconds() - (long)TimeCurrent(); if(secondsLeft < 0) secondsLeft = 0; int m = (int)(secondsLeft / 60); int s = (int)(secondsLeft % 60); // Format string: "m:ss" string timeText = IntegerToString(m) + ":" + (s < 10 ? "0" : "") + IntegerToString(s); // Create or Update the Text Object string objName = "time_clock"; // Position: Current Price (close[0]) // Time: We add PeriodSeconds() to move it to the right of the current candle datetime positionTime = currentBarTime + (PeriodSeconds() / 2); double positionPrice = close[0]; if(ObjectFind(0, objName) < 0) { ObjectCreate(0, objName, OBJ_TEXT, 0, positionTime, positionPrice); ObjectSetInteger(0, objName, OBJPROP_COLOR, InpColor); ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, InpFontSize); ObjectSetString(0, objName, OBJPROP_FONT, InpFontName); ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_LEFT); // Align left to stay right of candle ObjectSetInteger(0, objName, OBJPROP_BACK, false); ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false); ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true); } // Update position and text on every tick ObjectMove(0, objName, 0, positionTime, positionPrice); ObjectSetString(0, objName, OBJPROP_TEXT, " " + timeText); // Added two spaces for padding return(rates_total); }