Category Other  Published on 03/09/2015

Broker and Time Zones Clock

Description

This is not my whole work, I just made a mod from the source of "Real Market Time" by  lec0456

In this file I added some custom parameters as menu options:

 Broker's name, Broker UTC/GMT Time Zone, Swap Hour, Format 24hr or AM/PM, Label Color, Open and Close hour colors.

*Swap hour based on Broker server.

 

Now you can choose custom colors and write the label of your broker.

The Market Hours used are New York, London, Broker, Sydney and Tokyo 

If you prefer, you can also write another Time Zone instead of Broker's name and choose one of this UTC/GMT:

North America

     Pacific(-8), Central (-6) and East (-4)

Europe

    GMT (0), West (1) and East (2)

Asia

    Tokyo (9), East Australia (10) and New Zeland (12)

 

The indicator use your Local Time to show you the Market Hours.

If you want to include another time zone in the code there are some comment sections to make it easier.

 


/*This is a mod made by badtzo
Original source taken from "Real Market Time" by  lec0456

In this file I added some custom parameters as menu options for Broker's name,
Broker UTC/GMT Time Zone,Format 24hr or AM/PM, Label Color, Open and Close colors.

If you want to add another custom Time Zone or change color order, please look
below for the comment sections.
*/

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


namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class BrokerandTimeZonesClock : Indicator
    {
        [Parameter("Time 24hr?", DefaultValue = true)]
        public bool Format24HR { get; set; }
        [Parameter("Label Color", DefaultValue = "White")]
        public string LabelColor { get; set; }
        [Parameter("Closed Color", DefaultValue = "Gray")]
        public string ClosedColor { get; set; }
        [Parameter("Open Color", DefaultValue = "White")]
        public string OpenColor { get; set; }
        [Parameter("Broker's Name", DefaultValue = "Broker")]
        public string BrokerName { get; set; }
        [Parameter("Broker UTC/GMT", DefaultValue = "2")]
        public int BrokerUTC { get; set; }
        [Parameter("Swap Hour? 24hr", DefaultValue = "0")]
        public int BrokerSwap { get; set; }

        //Hours in 24hr and decimal format
        //Add here or modify custom Market hours. 
        //Broker hours are defined on Indicator's Menu. 
        public double TokyoOpen = 8;
        public double TokyoClose = 18;
        public double SydneyOpen = 7;
        public double SydneyClose = 16;
        public double LondonOpen = 8;
        public double LondonClose = 17;
        public double NYOpen = 8;
        public double NYClose = 17;
        public double BrokerOpen = 0.05;
        public double BrokerClose = 23.95;




        public override void Calculate(int index)
        {

            if (BrokerSwap >= 24 || BrokerSwap <= 0)
            {
                BrokerSwap = 0;
                BrokerClose = 23.95;
            }
            else
                BrokerClose = BrokerSwap - 0.05;

            BrokerOpen = BrokerSwap + 0.05;

            TimeZoneInfo LocalTimeZone = TimeZoneInfo.Local;

            //Add here custom time zones
            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 BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");

            //Add here custom UTC/GMT time zones number of hours
            switch (BrokerUTC)
            {
                case -8:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
                    break;
                case -6:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
                    break;
                case -4:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
                    break;
                case 0:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
                    break;
                case 1:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
                    break;
                case 2:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("E. Europe Standard Time");
                    break;
                case 9:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
                    break;
                case 10:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
                    break;
                case 12:
                    BrokerTimeZone = TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time");
                    break;
            }

            //Convert Time Zones to local 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 BrokerTime = TimeZoneInfo.ConvertTime(LocalTime, LocalTimeZone, BrokerTimeZone);

            //Label vars
            string strBrokerTime;
            string strLondonTime;
            string strNYTime;
            string strSydneyTime;
            string strTokyoTime;

            //Label positions
            string strNYLabel = string.Format("{0,-90}", "New York");
            string strLondonLabel = string.Format("{0,-44}", "London");
            string strBrokerLabel = string.Format("{0,14}", BrokerName);
            string strTokyoLabel = string.Format("{0,57}", "Tokyo");
            string strSydneyLabel = string.Format("{0,103}", "Sydney");


            //Time positions
            if (Format24HR == true)
            {
                strNYTime = string.Format("\n{0,-86}", NYTime.ToString("H:mm"));
                strLondonTime = string.Format("\n{0,-44}", LondonTime.ToString("H:mm"));
                strBrokerTime = string.Format("\n{0,12}", BrokerTime.ToString("H:mm"));
                strTokyoTime = string.Format("\n{0,57}", TokyoTime.ToString("H:mm"));
                strSydneyTime = string.Format("\n{0,102}", SydneyTime.ToString("H:mm"));
            }
            else
            {
                strNYTime = string.Format("\n{0,-89}", NYTime.ToString("h:mmtt"));
                strLondonTime = string.Format("\n{0,-44}", LondonTime.ToString("h:mmtt"));
                strBrokerTime = string.Format("\n{0,19}", BrokerTime.ToString("h:mmtt"));
                strTokyoTime = string.Format("\n{0,64}", TokyoTime.ToString("h:mmtt"));
                strSydneyTime = string.Format("\n{0,108}", SydneyTime.ToString("h:mmtt"));
            }



            //Color Vars
            Colors labelColor = (Colors)Enum.Parse(typeof(Colors), LabelColor, true);
            Colors openColor = (Colors)Enum.Parse(typeof(Colors), OpenColor, true);
            Colors closedColor = (Colors)Enum.Parse(typeof(Colors), ClosedColor, true);
            Colors BrokerColor = labelColor;
            Colors LondonColor = labelColor;
            Colors NYColor = labelColor;
            Colors SydneyColor = labelColor;
            Colors TokyoColor = labelColor;


            //Is Open or Close? and colors
            //If you added another Time zone, you shoul include it here

            if (BrokerTime.DayOfWeek == DayOfWeek.Saturday || BrokerTime.DayOfWeek == DayOfWeek.Sunday || BrokerTime.DayOfWeek == DayOfWeek.Friday && BrokerTime.Hour >= BrokerClose)
                BrokerColor = closedColor;
            else
                BrokerColor = openColor;
            if (NYTime.DayOfWeek == DayOfWeek.Saturday || NYTime.DayOfWeek == DayOfWeek.Sunday || NYTime.Hour < NYOpen || NYTime.Hour >= NYClose)
                NYColor = closedColor;
            else
                NYColor = openColor;

            if (LondonTime.DayOfWeek == DayOfWeek.Saturday || LondonTime.DayOfWeek == DayOfWeek.Sunday || LondonTime.Hour < LondonOpen || LondonTime.Hour >= LondonClose)
                LondonColor = closedColor;
            else
                LondonColor = openColor;
            if (SydneyTime.DayOfWeek == DayOfWeek.Saturday || SydneyTime.DayOfWeek == DayOfWeek.Sunday || SydneyTime.Hour < SydneyOpen || SydneyTime.Hour >= SydneyClose)
                SydneyColor = closedColor;
            else
                SydneyColor = openColor;
            if (TokyoTime.DayOfWeek == DayOfWeek.Saturday || TokyoTime.DayOfWeek == DayOfWeek.Sunday || TokyoTime.Hour < TokyoOpen || TokyoTime.Hour >= TokyoClose)
                TokyoColor = closedColor;
            else
                TokyoColor = openColor;

            //Labels position and color
            ChartObjects.DrawText("TimeLabel1", strLondonLabel, StaticPosition.TopCenter, labelColor);
            ChartObjects.DrawText("TimeLabel2", strNYLabel, StaticPosition.TopCenter, labelColor);
            ChartObjects.DrawText("TimeLabel3", strSydneyLabel, StaticPosition.TopCenter, labelColor);
            ChartObjects.DrawText("TimeLabel4", strTokyoLabel, StaticPosition.TopCenter, labelColor);
            ChartObjects.DrawText("TimeLabel5", strBrokerLabel, StaticPosition.TopCenter, labelColor);

            // Market Hours positions and colors
            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", strBrokerTime, StaticPosition.TopCenter, BrokerColor);
        }

    }
}


BA
badtzo

Joined on 02.09.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Broker and Time Zones Clock.algo
  • Rating: 5
  • Installs: 5194
Comments
Log in to add a comment.
No comments found.