Countdown Timer Display free

by fzlogic in category Other at 25/01/2013
Description

Display of countdown to the next bar on the chart. W1 and M1 Timeframes are not supported.

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
// -------------------------------------------------------------------------------
//
//    Display of countdown to the next bar on the top right of the chart. 
//    Timeframes supported up to D1/
//    Format HH:mm:ss
//
//-------------------------------------------------------------------------------

using System;
using cAlgo.API;
using System.Timers;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class Timer2 : Indicator
    {
        private readonly Timer _timer = new Timer();
        private TimeSpan _timeFrame;
        private TimeSpan _nextOpenTime;
        private int _serverHourDiff;
        private DateTime _serverTime;
        private int _index;

        protected override void Initialize()
        {
            _timer.Elapsed += OnTimedEvent; //  OnTimedEvent is called at each timer tick
            _timer.Interval =  1000;        // Timer will tick every Interval (milliseconds)
            _timer.Enabled = true;          // Enable the timer
            _timer.Start();                 // Start the timer

        }


        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            
            _index = MarketSeries.Close.Count - 1;
            _timeFrame = MarketSeries.OpenTime[_index] - MarketSeries.OpenTime[_index - 1];

            if (_timeFrame <= TimeSpan.FromHours(24.0))
            {
                _nextOpenTime = MarketSeries.OpenTime[_index].TimeOfDay + _timeFrame;
                _serverHourDiff = MarketSeries.OpenTime[_index].TimeOfDay.Hours - DateTime.Now.TimeOfDay.Hours;
                _serverTime = DateTime.Now.AddHours(_serverHourDiff);

                ChartObjects.DrawText("CountDown", (_nextOpenTime - _serverTime.TimeOfDay).ToString().Substring(0, 8),
                                      StaticPosition.TopRight, Colors.White);
            }
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }
    }
}

Comments

Enivid - March 12, 2013 @ 18:33

Too bad OnTimedEvent seems to be processed only on new ticks.

Enivid - March 12, 2013 @ 18:35

No, it looks to be a problem of server time updating only on ticks.

cAlgo Fanatic - March 13, 2013 @ 16:00

cAlgo will include a build in timer in the next release.

Enivid - March 14, 2013 @ 21:04

Looks pretty obsolete now with the latest update.

cAlgo Fanatic - March 15, 2013 @ 09:32

The release will be within next week. You can see what it will look like with Spotware cAlgo.

Eduardo_Cerejo - July 03, 2015 @ 12:27

I'm getting this error when building it:

Error CS0104: 'Timer' is an ambiguous reference between 'cAlgo.API.Timer' and 'System.Timers.Timer'

Can anyone fix it?

Mario Hennenberger - July 08, 2016 @ 19:38

its obsolete as cTrader has this now build-in 

5