Market Hours free

by Jiri in category Other at 19/03/2016
Description

DonateDescription:

  • Current open markets, updated in real time.
  • Time bar progresses from left to right.
  • Hours are optimized to local time.

 

Updates:

  • 19/03/2016 - Released.
  • 26/03/2016 - Updated strings.
  • 30/03/2016 - Fixed offset issue.
  • 01/04/2016 - Fixed opening times.

 

Screenshot:

 

Make a Donation

  • If you like my work and effort then please consider to make a kind donation thru PayPal or any Credit Card at the top right corner.
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.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MarketHours : Indicator
    {
        private string[] hours = new string[24];
        private TimeSpan offset = DateTime.Now.Subtract(DateTime.UtcNow);
        private int sync = -1;
        private Colors color;

        protected override void Initialize()
        {
            SetHours();
            Timer.Start(TimeSpan.FromMilliseconds(1));
        }

        protected override void OnTimer()
        {
            DateTime utc = DateTime.UtcNow;
            int vLine = 240 - (utc.AddHours(3).Hour * 10 + utc.Minute / 6);

            for (int i = 0; i <= 4; i++)
            {
                int shift = 0;
                for (int h = 1; h <= 24; h++)
                {
                    if (i == 0)
                    {
                        color = Colors.DimGray;

                        if (shift + 10 >= vLine && vLine > shift)
                            color = Colors.LimeGreen;
                    }
                    else
                    {
                        color = Colors.Gainsboro;

                        if (i == 1)
                            if (240 > shift && shift >= 150)
                                if (240 >= vLine && vLine > 150)
                                    color = Colors.Orange;
                                else
                                    color = Colors.BurlyWood;

                        if (i == 2)
                            if (220 > shift && shift >= 130)
                                if (220 >= vLine && vLine > 130)
                                    color = Colors.YellowGreen;
                                else
                                    color = Colors.LightGreen;

                        if (i == 3)
                            if (140 > shift && shift >= 50)
                                if (140 >= vLine && vLine > 50)
                                    color = Colors.DodgerBlue;
                                else
                                    color = Colors.LightBlue;

                        if (i == 4)
                            if (90 > shift && shift >= 0)
                                if (90 >= vLine && vLine > 0)
                                    color = Colors.DeepPink;
                                else
                                    color = Colors.LightPink;
                    }
                    ChartObjects.DrawText("background" + h + i, y(i) + (char)9609 + x(shift + 5), StaticPosition.TopRight, color);

                    int hour = (21 - h + offset.Hours);
                    hour = hour >= 24 ? hour - 24 : hour < 0 ? hour + 24 : hour;

                    color = Colors.White;
                    ChartObjects.DrawText("hour" + h, hours[hour] + x(shift + 6), StaticPosition.TopRight, color);

                    shift += 10;
                }
            }

            string sydney = "" + (char)42801 + (char)655 + (char)7429 + (char)628 + (char)7431 + (char)655;
            string tokyo = "" + (char)7451 + (char)7439 + (char)7435 + (char)655 + (char)7439;
            string london = "" + (char)671 + (char)7439 + (char)628 + (char)7429 + (char)7439 + (char)628;
            string newyork = "" + (char)628 + (char)7431 + (char)7457 + " " + (char)655 + (char)7439 + (char)640 + (char)7435;

            ChartObjects.DrawText("Sydney", y(1) + sydney + x(182), StaticPosition.TopRight, color);
            ChartObjects.DrawText("Tokyo", y(2) + tokyo + x(165), StaticPosition.TopRight, color);
            ChartObjects.DrawText("London", y(3) + london + x(80), StaticPosition.TopRight, color);
            ChartObjects.DrawText("New York", y(4) + newyork + x(26), StaticPosition.TopRight, color);

            color = Colors.LimeGreen;
            for (int i = 1; i <= 4; i++)
            {
                ChartObjects.DrawText("vLine" + i, y(i) + (char)9474 + x(vLine), StaticPosition.TopRight, color);
            }

            if (sync < 1)
            {
                Timer.Stop();
                TimeSpan interval;

                if (sync < 0)
                {
                    var nextUpdate = new DateTime(utc.Year, utc.Month, utc.Day, utc.Hour, (utc.Minute / 6 + 1) * 6, 2);
                    var difference = nextUpdate.Subtract(utc);

                    interval = difference;
                    Timer.Start(interval);
                    sync = 0;
                }
                else
                {
                    interval = TimeSpan.FromMinutes(6);
                    Timer.Start(interval);
                    sync = 1;
                }
            }
        }

        public override void Calculate(int index)
        {
            // Do nothing.
        }

        private string x(int count)
        {
            return new string((char)8202, count);
        }

        private string y(int count)
        {
            return new string('\v', count);
        }

        private void SetHours()
        {
            for (int i = 0; i <= 23; i++)
            {
                if (i <= 9)
                {
                    hours[i] = "" + (char)(8320 + i) + x(2);
                }
                else if (i <= 19)
                {
                    hours[i] = "" + (char)8321 + (char)(8310 + i);
                }
                else
                {
                    hours[i] = "" + (char)8322 + (char)(8300 + i);
                }
            }
        }
    }
}
Comments