Formula 201 – #12 Writing Tick Precise Indicator

I am going to demonstrate the programming techniques for writing Tick Precise indicators. These techniques are equally applicable to those who like to implement TP indicators using scripts (DelphiScript or VBScript) or regular programming language through the ActiveX based IDL object model.

Utilize the Special Real-Time Bid Ask Data Functions

There are a number of real-time functions and fields that are available only when the indicator is set to update by tick. These real-time information can be collected and then analyzed easily.

For a list of these functions, check out the Help file.

Formula Topics and Tutorials>Functions in Formulas>Context Functions in Time Chart, PatternScanner, and Indicator Created with Formula

Here is an example showing how to collect the total number of trades that traded at the bid price or lower. You can enter the code below into a chart using the FML indicator.

$totalbidtrades :=
if ($prevdate <> date, 0, $totalbidtrades) +
if (c < = bidprice, 1, 0); $prevdate := date; $totalbidtrades

The technique used here is a form of recursion, that depends on the information saved in the local variable $prevdate from one tick to another. In short, we add one to the local variable $totalbidtrades whenever the update tick is at or below the bidprice. Bidprice is a real-time data function that returns the latest bid price.

(Lawrence – If you are writing an indicator with the object model, then you can use the pHeap to store intra-tick data and create exactly the same effect like the local variables in the formula. The real-time data are available as properties within the data series objects like data1, data2, etc.)

By modifying the above formula a bit, we can chart the number of trades at the bid within each bar.

$totalbidtrades :=
if ($prevdate <> date, 0, $totalbidtrades) +
if (c < = bidprice, 1, 0); $prevdate := date; mytotalbidtrades := $totalbidtrades; mytotalbidtrades - if (date <> date (1), 0, mytotalbidtrades (1));

The first 2 statements in the formula above is exactly the same as the first example. I simply copy the code and added the last 2 statements.

The last 2 statements utilize an important property of series variables – having memory effect for the final values of the previous bars. By assigning the local variable $totalbidtrades to the series variable mytotalbidtrades, we are saving the exact final values of the intra-tick information for each bar.

Here is how the formulas above will look like on a chart,

formula201 part12 chart1

Utilize the Special Tick Statistics Fields

Using the real-time data functions works well but that takes a lot of programming if you are going to do very complex analysis on tick level data.

In NeoTicker 4.1 we have introduced a set of day level tick statistics fields. These fields contain the accumulated statistics based on tick data if you are updating the indicator in real-time or conducted a tick replay in the chart.

A complete list of these tick statistics fields is available in the Help file.

Formula Topics and Tutorials>Formula in Time Chart, PatternScanner, and Indicator Created with Formula>Accessing Data Links

Using tick statistic fields, you can chart the total ticks accumulated for the day by using just the DayTotalTicks field in the FML indicator.

To chart the number of trades that traded at the bid in the day is just the DayTotalBidTrades field.

To figure out the number of trades at bid price per bar,

mytotalbidtrades := daytotalbidtrades;
mytotalbidtrades -
if (date <> date (1), 0, mytotalbidtrades (1));

We no longer need to worry about the details needed to store and manage the number of trades happened at the bid. The DayTotalBidTrades field saved our time and reduced the complexity related to implementing the concept.

Here is a chart using the Tick Statistics fields. Notice that the result is exactly the same as the one we get from using local variables to collect the data ourselves.

formula201 part12 chart2

(Lawrence – If you are writing an indicator with the object model, then remember that the tick statistics fields are available as the data series object properties.)


I have demonstrated the basic techniques in writing TP indicators. Take the time to experiment with the techniques so that you can produce the tick precise data you want proficiently.

One important thing to remember is that TP indicators require Tick Replay to produce the correct historical results. There is nothing to worry about when you just applied the TP indicators to a chart and the result is not what you expected.


No exercise for this tutorial.

Answers For Previous Exercise

There was no exercise in the previous tutorial.


Leave a Comment

Blog Developed
By ContentRobot