A MultiCharts .NET indicator can be calculated on every tick, or the same ticks can be skipped to make the script run more efficient. How can we set that option programmatically?

The SkipIdenticalTicks attribute: bypassing ticks with the same price

A C# attribute adds metadata to code elements like classes (Dorman, 2010) and by doing so influence the way these operate (e.g., see Stephens, 2014). With class attributes in MultiCharts .NET certain indicator or trading strategy options can be set programmatically.

One of these attributes is SkipIdenticalTicks (see PowerLanguage .NET Help, n.d.). With this attribute MultiCharts .NET skips real-time calculations that have the same price as the previous tick, which reduces CPU usage (MultiCharts Wiki, 2015). This applies only to intra-bar ticks – opening and closing ticks are always processed, even when they’re identical (MultiCharts Support, personal communication, January 27, 2015).

Tip: SkipIdenticalTicks is helpful for indicators based on price data because these only need to be calculated when the price changes. But this setting can give inaccurate results due to missed ticks when the indicator uses volume or tick count data (MultiCharts Wiki, 2015).

Setting the SkipIdenticalTicks attribute in MultiCharts .NET

To have the indicator process all intra-bar ticks, set SkipIdenticalTicks to false:

[SkipIdenticalTicks(false)]
public class Example_SkipIdenticalTicks : IndicatorObject
{
    // Indicator code
}

And to skip the same real-time prices, set it to true:

[SkipIdenticalTicks(true)]
public class Example_SkipIdenticalTicks : IndicatorObject
{
    // Indicator code
}

When the SkipIdenticalTicks attribute isn’t specified, identical ticks are skipped by default (see MultiCharts Wiki, 2015).

Example: processing tick count data in MultiCharts .NET

In the following example we explore the effect that SkipIdenticalTicks can have:

[SkipIdenticalTicks(true), SameAsSymbol(true)]
public class Example_SkipIdenticalTicks : IndicatorObject
{
    public Example_SkipIdenticalTicks(object _ctx) : base(_ctx) { }

    double prevPrice;
    int identicalTicks = 0, tickCount = 0;

    protected override void CalcBar()
    {
        if (Environment.IsRealTimeCalc)
        {
            tickCount++;

            if (Bars.Close[0] == prevPrice &&
                Bars.Status == EBarState.Inside)
                identicalTicks++;

            if (Bars.Status == EBarState.Close)
            {
                Output.WriteLine("Bar #{0} - {1} - " + 
                    "Ticks: {2}, of which identical: {3}",
                    Bars.CurrentBar,
                    Bars.Time[0].ToShortTimeString(),
                    tickCount,
                    identicalTicks);
            }

            prevPrice = Bars.Close[0];
        }
    }
}

Besides setting SkipIdenticalTicks to true, SameAsSymbol is also enabled so that the indicator is displayed on a data series and not a individual subchart.

Then three variables are declared: prevPrice (which will hold the price from the previous script calculation), identicalTicks (for counting the number of identical ticks), and tickCount (for counting the number of ticks per bar).

Counting the number of (identical) ticks in MultiCharts .NET

The CalcBar() method contains an if statement that checks whether the Environment.IsRealTimeCalc property returns true, which it does when the script is calculated on real-time data (PowerLanguage .NET Help, n.d.). This way the if statement’s code is only executed on the kind of data where identical ticks can be skipped.

That code begins with adding one to tickCount with the ++ postfix increment operator. A nested if statement then evaluates whether the bar’s current price (Bars.Close[0]) equals the price from the previous script calculation (prevPrice) and if the current price is an intra-bar tick (EBarState.Inside). When both conditions evaluate to true, the ++ operator increments identicalTicks with one.

The next if statement uses Bars.Status to see if the price currently processed by the script is the bar’s closing tick (EBarState.Close). When it is, Output.WriteLine() prints data to the PowerLanguage .NET Editor that contains the bar number (Bars.CurrentBar), the bar’s time (Bars.Time[0]), and the tickCount and identicalTicks variables.

The last statement updates prevPrice with the current price processed by the script (Bars.Close[0]). That way this variable holds the value of the previous tick during the next script calculation.

Output of ‘Skip Identical Ticks’ enabled versus disabled

When the example indicator has SkipIdenticalTicks set to true, it generates the following output when applied to a LMAX’s EUR/USD chart:

//> Bar #92 - 14:25 - Ticks: 481, of which identical: 0
//> Bar #93 - 14:35 - Ticks: 1457, of which identical: 0
//> Bar #94 - 14:45 - Ticks: 2331, of which identical: 0
//> Bar #95 - 14:55 - Ticks: 555, of which identical: 0
//> Bar #96 - 15:05 - Ticks: 1644, of which identical: 0
//> Bar #97 - 15:15 - Ticks: 2436, of which identical: 0

And with the attribute is set to false, the output for the same symbol is as follows:

//> Bar #98 - 15:25 - Ticks: 1195, of which identical: 417
//> Bar #99 - 15:35 - Ticks: 2916, of which identical: 1006
//> Bar #100 - 15:45 - Ticks: 4565, of which identical: 1578
//> Bar #101 - 15:55 - Ticks: 7304, of which identical: 2073
//> Bar #102 - 16:05 - Ticks: 9342, of which identical: 2670

As this output shows a considerable amount of identical ticks were processed when the attribute was disabled.

Tip: When you add an indicator to the chart and change certain code components (like an attribute), the script needs to be removed and re-added to the chart in order to see the modified code (see Henry MultiCharts, 2014).

Setting ‘Skip Identical Ticks’ manually in the PowerLanguage .NET Editor

The ‘Skip Identical Ticks’ option can also be set manually in the PowerLanguage .NET Editor. To do so, right-click somewhere in the editor’s code window and select ‘Properties’:

MultiCharts .NET SkipIdenticalTicks - code editor

Then in the ‘Indicator Properties’ window enable or disable ‘Skip Identical Ticks’:

MultiCharts .NET SkipIdenticalTicks - enable manually

By the way, we also use this window to manually set the ‘Same As Symbol’ and ‘Update on every tick’ options.

Specifying ‘Skip Identical Ticks’ manually in MultiCharts .NET

Once an indicator is added to a chart or Scanner/Watchlist, the ‘Skip Identical Ticks’ option can still be changed manually. This way it can be set for specific instances of the indicator.

To do that, right-click on the indicator’s name in the chart’s Status Line and select ‘Format [script name]‘. Or, when using the Scanner/Watchlist, right-click in the indicator’s column and select ‘Format Study’.

Then go to the ‘Properties’ tab to enable or disable the ‘Skip identical ticks’ option:

MultiCharts .NET SkipIdenticalTicks - set manually for indicator

Other indicator attributes include those that enable mouse click processing (MouseEvents) and prevent intra-bar drawings from being deleted (RecoverDrawings).

Summary

With SkipIdenticalTicks set to true, intra-bar ticks with the same price as the previous aren’t processed by the indicator. While this reduces CPU usage, it isn’t suited for indicators that use volume or tick count.


References

Dorman, S. (2010). Sams Teach Yourself Visual C# 2010 in 24 Hours. Indianapolis, IN (USA): Sams/Pearson Education.

Henry MultiCharts (2014, December 11). MultiCharts .NET FAQ – forum discussion. Retrieved on January 25, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=45848#p111375

MultiCharts Wiki (2015, January 29). Skip Identical Ticks. Retrieved on January 30, 2015, from http://www.multicharts.com/trading-software/index.php/Skip_Identical_Ticks

PowerLanguage .NET Help (n.d.). Retrieved on November 18, 2014, from http://www.multicharts.com/downloads/PowerLanguage.NET.chm

Stephens, R. (2014). C# 5.0 Programmer Reference. Indianapolis, IN: John Wiley & Sons.