Countdown to Zero

Countdown time chart

(These two indicator are now part of the standard installation).

The above is countdown time chart example.

We have developed two indicators call Countdown Tick and Countdown Time, they are included as part of NeoTicker distribution. In this article we will explain the thought process and incremental steps that have taken during development.

Countdown tick works only on constant tick bar data series (e.g. 30 ticks, 10 ticks and etc.), it return number of ticks remaining until creation of a new bar. If apply this indicator on any other data series time frame beside tick only current time is shown.

Countdown time works only on intraday time based data series (i.e. seconds, minutes and hours), it show the time remaining until creation of a new bar. When apply on another type of data series time frame only the current time is shown.

Initially we plan to create one countdown indicator for both tick and time, it will decide on its own where tick countdown or time countdown is need for the base data series. That plan was scrapped after the first prototype, because we discover that tick do not arrive every second for all symbols, so when doing time countdown, time display sometime stand still, this make split countdown into two indicators a must. The two indicators are: 1, tick countdown is an update by tick indicator. 2, time countdown is a timer indicator with update speed default at 1 second.

Tick countdown were developed first due to simplicity of code involve. The heart of the indicator is one line of code:

data1.timeframeperiod – data1.tick[0]

This line return number of ticks remaining until next bar.

After verifying tick count down calculation is correct, options to set color and font size was added.

During real-time test of tick countdown indicator, we’ve discovered CPU was always at 100% when running it. After doing research on the internet, we found out font assignment in scripting language is extremely resource demanding. Since font and color of drawing object attribute assignment will not change during real-time calculation for this indicator, they were moved into the initialization encapsulation. This move limits font and color assignment to once per complete recalculation. After these changes, CPU usage when running tick countdown in real-time went down significantly.

After running tick countdown real-time for a day, we are happy with the result and move on to develop time countdown.

This screenshot is countdown tick in action.

Countdown tick chart

Time countdown calculation is more complex, it will need to determine which time frame it is working on, whether it is a second, minute or hourly data series. Then different calculation and display method is needed for different time frame.

Time to end of bar is calculated by subtracting the current time from bar datetime:

data1.datetime [0]-ntlib.now

Time ramaining until next bar is created is the result of above calculation, the calculation reulst is in internal window time format. To convert result into conventional time format, fraction portion of the resulting time is multiplied by value of second in a day (86400) to yield value in second until next bar. If base data series time frame is second, this result of calculation is displayed.

When base time frame is minute, fraction portion of time difference is multiplied by minute in a day (1440) to get minute value of time until new bar. Display time is separated into minute and second, leading zero is added when second is less than 10 to make the display look more conventional.

Hourly based data series calculation and display is done in similar fashion as minute data series.

During real-time test of time countdown, negative times were encountered. This is because ntlib.now will always advance according to timer where as data1.datetime [0] only advance when new bar is created. So when no new ticks arrive after the current time passes the end of hour, minute or second bar, a negative time is return as a result. So detection of negative time difference is added, when negative delta time occur, all second, minute and hour are set to zero.

After time countdown is verify in real-time, setting for fonts and colors are added.

This complete the discussion on the two countdown indicators development.

Both indicators along with source code in Delphi script are part of NeoTicker installation.

Discuss this article.

3 Comments on “Countdown to Zero”

  1. Ted A Says:

    When I look in the script manager,I see “countdown_tick” , not countdown_time .
    I have version 4.01 . Did I miss something ?

  2. Kenneth Says:

    Countdown time did not make it in time for 4.01 distribution, please use the above installer to install the indicator into NeoTicker.

  3. BKuerbs Says:

    I would like to display a similar information for Constant Volume Bar charts (Superposition Charts) – the volume required to fill this bar. I could plot the actual volume below the chart, but that is consuming too much space.

    I tried to find where you store the info about the volume used to construct the bars, but did not succeed. TimeFramePeriod and TimeFrameType are set to “T1”, so do you have any hints?

    Many Thanks

    Bernd Kuerbs

Leave a Comment

Blog Developed
By ContentRobot