Real Market Time

by lec0456 in category Other at 22/04/2013
Description

A simple but useful indicator that places the time in London, New York, Sydney and Tokyo right on the chart.  The time will be in color if the session is active and you can select 24 or 12 hour format.  Unlike the Real Market Hours indicator, this indicator is based on your computer's local time, not the broker's server time so make sure its right.

 

Download
3435 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true , AccessRights = AccessRights.None)]
    public class MarketTimeDisplay : Indicator
    {
        
        
        [Parameter(DefaultValue = 0, MaxValue=1, MinValue=0)]
        public int paramFormat24HR { get; set; }
        
        public double TokyoOpen=9;
        public double TokyoClose=17;  //Some use a 6pm close for Tokyo.  I am using 5pm for all closings.
        public double SydneyOpen=9;
        public double SydneyClose=17; //Some use a 4pm close for Sydney
        public double LondonOpen=8;
        public double LondonClose=17;
        public double NYOpen=8;
        public double NYClose=17;
        
        public override void Calculate(int index)
        {
        TimeZoneInfo LocalTimeZone = TimeZoneInfo.Local;
                
        //Used to verify local time zone settings
        //Print("Local Time Zone Name:{0} Offset:{1} DST:{2} ",LocalTimeZone.DisplayName,LocalTimeZone.BaseUtcOffset,LocalTimeZone.SupportsDaylightSavingTime);
        
        TimeZoneInfo TokyoTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
        TimeZoneInfo NYTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
        TimeZoneInfo LondonTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
        TimeZoneInfo SydneyTimeZone = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
		
		DateTime LocalTime=DateTime.Now;
		DateTime SydneyTime=TimeZoneInfo.ConvertTime(LocalTime,LocalTimeZone,SydneyTimeZone);
        DateTime LondonTime=TimeZoneInfo.ConvertTime(LocalTime,LocalTimeZone,LondonTimeZone);
        DateTime TokyoTime=TimeZoneInfo.ConvertTime(LocalTime,LocalTimeZone,TokyoTimeZone);
        DateTime NYTime=TimeZoneInfo.ConvertTime(LocalTime,LocalTimeZone,NYTimeZone);
        
        Colors LondonColor=Colors.White;
        Colors NYColor=Colors.White;
        Colors SydneyColor=Colors.White;
        Colors TokyoColor=Colors.White;
        
        string strLondonTime;
 		string strNYTime;
 		string strSydneyTime;
 		string strTokyoTime;
        
        string strLondonLabel=string.Format("{0,-60}","London");
        string strNYLabel=string.Format("{0,-20}","NY");
        string strSydneyLabel=string.Format("{0,25}","Sydney");
        string strTokyoLabel=string.Format("{0,60}","Tokyo");
        
        if (paramFormat24HR==1){
        strLondonTime=string.Format("\n{0,-60}",LondonTime.ToString("H:mm"));
        strNYTime=string.Format("\n{0,-25}",NYTime.ToString("H:mm"));
		strSydneyTime=string.Format("\n{0,25}",SydneyTime.ToString("H:mm"));
		strTokyoTime=string.Format("\n{0,60}",TokyoTime.ToString("H:mm"));        
        }
        else{
        strLondonTime=string.Format("\n{0,-60}",LondonTime.ToString("h:mmtt"));
        strNYTime=string.Format("\n{0,-25}",NYTime.ToString("h:mmtt"));
		strSydneyTime=string.Format("\n{0,25}",SydneyTime.ToString("h:mmtt"));
		strTokyoTime=string.Format("\n{0,60}",TokyoTime.ToString("h:mmtt"));
		}
		
        if(LondonTime.Hour>=LondonOpen & LondonTime.Hour<LondonClose)LondonColor=Colors.Yellow;
        if(NYTime.Hour>=NYOpen & NYTime.Hour<NYClose)NYColor=Colors.Blue;
       	if(SydneyTime.Hour>=SydneyOpen & SydneyTime.Hour<SydneyClose)SydneyColor=Colors.Green;      
       	if(TokyoTime.Hour>=TokyoOpen & TokyoTime.Hour<TokyoClose)TokyoColor=Colors.Red;
       	
       	ChartObjects.DrawText("TimeLabel1", strLondonLabel, StaticPosition.TopCenter, LondonColor);
       	ChartObjects.DrawText("TimeLabel2", strNYLabel, StaticPosition.TopCenter, NYColor);
       	ChartObjects.DrawText("TimeLabel3", strSydneyLabel, StaticPosition.TopCenter, SydneyColor);
       	ChartObjects.DrawText("TimeLabel4", strTokyoLabel, StaticPosition.TopCenter, TokyoColor);
       	ChartObjects.DrawText("Time1", strLondonTime, StaticPosition.TopCenter, LondonColor);
       	ChartObjects.DrawText("Time2", strNYTime, StaticPosition.TopCenter, NYColor);
       	ChartObjects.DrawText("Time3", strSydneyTime, StaticPosition.TopCenter, SydneyColor);
       	ChartObjects.DrawText("Time4", strTokyoTime, StaticPosition.TopCenter, TokyoColor);
        }
    }
}
Comments

kricka - April 26, 2013 @ 08:44

Hi, thanks for the the indicator, very useful indeed! I have a minor suggestion to maybe even make it better, if you don,t mind. Can you make a count down of hours and minutes left until the different markets open? Based on the computer's local time. For example: London 4.07PM ( 3.45 ).

Tim_Mi - April 19, 2014 @ 08:33

Thank you for clocks. 

But why are they in the wrong or random order? 

Do they also work if placed from East to West? 

lorbax - September 14, 2014 @ 01:41

Hello everybody, I took the freedom to add also the Euro time (Frankfurt)

 

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class MarketClocks : Indicator
    {

        [Parameter(DefaultValue = 1, MaxValue = 1, MinValue = 0)]
        public int paramFormat24HR { get; set; }

        public double TokyoOpen = 8;
        public double TokyoClose = 17;
        //Some use a 6pm close for Tokyo.  I am using 5pm for all closings.
        public double SydneyOpen = 8;
        public double SydneyClose = 16.5;
        //Some use a 4pm close for Sydney
        public double LondonOpen = 8;
        public double LondonClose = 17;
        public double NYOpen = 8;
        public double NYClose = 17;
        public double EuOpen = 9;
        public double EuClose = 17.5;

        public override void Calculate(int index)
        {
            TimeZoneInfo LocalTimeZone = TimeZoneInfo.Local;

            //Used to verify local time zone settings
            //Print("Local Time Zone Name:{0} Offset:{1} DST:{2} ",LocalTimeZone.DisplayName,LocalTimeZone.BaseUtcOffset,LocalTimeZone.SupportsDaylightSavingTime);

            TimeZoneInfo TokyoTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
            TimeZoneInfo NYTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
            TimeZoneInfo LondonTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
            TimeZoneInfo SydneyTimeZone = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
            TimeZoneInfo EuTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");

            DateTime LocalTime = DateTime.Now;
            DateTime SydneyTime = TimeZoneInfo.ConvertTime(LocalTime, LocalTimeZone, SydneyTimeZone);
            DateTime LondonTime = TimeZoneInfo.ConvertTime(LocalTime, LocalTimeZone, LondonTimeZone);
            DateTime TokyoTime = TimeZoneInfo.ConvertTime(LocalTime, LocalTimeZone, TokyoTimeZone);
            DateTime NYTime = TimeZoneInfo.ConvertTime(LocalTime, LocalTimeZone, NYTimeZone);
            DateTime EuTime = TimeZoneInfo.ConvertTime(LocalTime, LocalTimeZone, EuTimeZone);

            Colors EuColor = Colors.DarkGray;
            Colors LondonColor = Colors.DarkGray;
            Colors NYColor = Colors.DarkGray;
            Colors SydneyColor = Colors.DarkGray;
            Colors TokyoColor = Colors.DarkGray;

            string strEuTime;
            string strLondonTime;
            string strNYTime;
            string strSydneyTime;
            string strTokyoTime;

            string strNYLabel = string.Format("{0,-85}", "NY");
            string strLondonLabel = string.Format("{0,-48}", "London");
            string strEuLabel = string.Format("{0,0}", "Euro");
            string strSydneyLabel = string.Format("{0,50}", "Sydney");
            string strTokyoLabel = string.Format("{0,89}", "Tokyo");


            strNYTime = string.Format("\n{0,-90}", NYTime.ToString("HH:mm"));
            strLondonTime = string.Format("\n{0,-48}", LondonTime.ToString("HH:mm"));
            strEuTime = string.Format("\n{0,0}", EuTime.ToString("HH:mm"));
            strSydneyTime = string.Format("\n{0,48}", SydneyTime.ToString("HH:mm"));
            strTokyoTime = string.Format("\n{0,89}", TokyoTime.ToString("HH:mm"));


            if (EuTime.Hour >= EuOpen & EuTime.Hour < EuClose)
                EuColor = Colors.Magenta;
            if (LondonTime.Hour >= LondonOpen & LondonTime.Hour < LondonClose)
                LondonColor = Colors.Blue;
            if (NYTime.Hour >= NYOpen & NYTime.Hour < NYClose)
                NYColor = Colors.Blue;
            if (SydneyTime.Hour >= SydneyOpen & SydneyTime.Hour < SydneyClose)
                SydneyColor = Colors.Red;
            if (TokyoTime.Hour >= TokyoOpen & TokyoTime.Hour < TokyoClose)
                TokyoColor = Colors.Red;

            ChartObjects.DrawText("TimeLabel1", strLondonLabel, StaticPosition.TopCenter, LondonColor);
            ChartObjects.DrawText("TimeLabel2", strNYLabel, StaticPosition.TopCenter, NYColor);
            ChartObjects.DrawText("TimeLabel3", strSydneyLabel, StaticPosition.TopCenter, SydneyColor);
            ChartObjects.DrawText("TimeLabel4", strTokyoLabel, StaticPosition.TopCenter, TokyoColor);
            ChartObjects.DrawText("TimeLabel5", strEuLabel, StaticPosition.TopCenter, EuColor);

            ChartObjects.DrawText("Time1", strLondonTime, StaticPosition.TopCenter, LondonColor);
            ChartObjects.DrawText("Time2", strNYTime, StaticPosition.TopCenter, NYColor);
            ChartObjects.DrawText("Time3", strSydneyTime, StaticPosition.TopCenter, SydneyColor);
            ChartObjects.DrawText("Time4", strTokyoTime, StaticPosition.TopCenter, TokyoColor);
            ChartObjects.DrawText("Time5", strEuTime, StaticPosition.TopCenter, EuColor);
        }
    }
}

5