Situation
You to know how to access resolution information (such as time frame, resolution type) of the current symbol in MultiCharts .NET.

Programming example

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
    [SameAsSymbol(true)]
    public class Example_ResolutionInfo : IndicatorObject
    {
        public Example_ResolutionInfo(object _ctx) : base(_ctx) { }

        private bool printOnce;

        protected override void StartCalc()
        {
            printOnce = false;
            Output.Clear();
        }

        protected override void CalcBar()
        {
            if (!printOnce)
            {
                Output.WriteLine("Current symbol resolution information:");

                if (Bars.Info.Resolution.ChartType == ChartType.Regular)
                {
                    Output.WriteLine("Data series = {0} chart type.",
                        Bars.Info.Resolution.ChartType);
                }

                Output.WriteLine("Time frame: {0} minutes.",
                    Bars.Info.Resolution.Duration().ToString("%m"));

                Output.WriteLine("Is day? {0}\r\nIs tick? {1}\r\nIs time-based? {2}",
                    Bars.Info.Resolution.IsDayOrHigher(),
                    Bars.Info.Resolution.IsOneTick(),
                    Bars.Info.Resolution.IsTimeBased());

                Output.WriteLine("Size: {0}, Type: {1}",
                    Bars.Info.Resolution.Size,
                    Bars.Info.Resolution.Type);

                printOnce = true;
            }
        }
    }
}

Output of the programming example

Applied to a chart like the following:

Example - accessing resolution information in MultiCharts .NET

The indicator generates the following output:

Current symbol resolution information:
Data series = Regular chart type.
Time frame: 15 minutes.
Is day? False
Is tick? False
Is time-based? True
Size: 15, Type: Minute

Price bars of the data series in MultiCharts .NET

Regardless of the MultiCharts .NET environment (such as a price chart, real-time market scanner, or portfolio), price data of a data series are represented with price bars (MultiCharts, 2013). These bars graphically represent an instrument’s price movement over a defined interval (MultiCharts Wiki, 2013).

The construction of price bars depends on the data series resolution settings. There are two main resolution types: time interval (based on seconds, minutes, hours, days, weeks, months, years) and count interval, which are based on tick, volume, change or range (MultiCharts Wiki, 2013).

How price bars are formed affects the values returned by the Bars property and BarsOfData() method, but also has less notable influences on, for example, volume data in MultiCharts .NET.

Access MultiCharts .NET resolution information programmatically

There are various ways in which resolution information of the primary data series can be used in a MultiCharts .NET script (e.g., PowerLanguage .NET Help, n.d.):

Bars.Info.Resolution property or method Description How to use
Attributes Property that returns a Dictionary with resolution attributes for non-regular chart types. Will be discussed in a separate article; when available, that link will be included here.
ChartType Property that returns an enumerator from the ChartType enumeration that specifies the resolution chart type. Returned values are: Regular, PointAndFigure, Kagi, Renko, LineBreak, HeikinAshi, FootPrint, CumulativeDelta. Bars.Info.Resolution.ChartType: returns the Regular enumerator when the primary data series is a time-based chart.
Duration() Extension method that returns the TimeSpan of the data series. Bars.Info.Resolution.Duration(): returns a TimeSpan structure that holds the time period of the resolution of the primary data series.
IsDayOrHigher() Extension method that returns a Boolean variable to indicate whether the resolution is day or higher (week, month, quarter, year). Bars.Info.Resolution.IsDayOrHigher(): returns true if the primary data series is day or higher; returns false otherwise.
IsOneTick() Extension method that returns true if the resolution is 1 tick; otherwise, it returns false. Bars.Info.Resolution.IsOneTick(): returns true if the resolution of the primary data series is 1 tick.
IsTimeBased() Extension method that returns true when the resolution is time-based (e.g., minute, second, hour) and false for non-time-based resolutions. Bars.Info.Resolution.IsTimeBased(): returns true if the resolution of the primary data series is time-based.
Size Property that returns the time frame size, which is the value specified in the ‘Resolution’ field of the ‘Settings’ tab from the ‘Format Instrument’ window. Bars.Info.Resolution.Size: returns 15 when the current chart is a 15 minute chart.
Type Returns an enumerator from the EResolution enumeration that specifies the type of resolution. Can return Tick, Minute, Hour, Day, Week, Month, Year, Volume, Second, Quarter, Points, Change, or OrigPoints. Bars.Info.Resolution.Type: returns the Minute enumerator when the chart is a minute chart.

Substitute the Bars property for the BarsOfData() method to access resolution information from additional data series. For example, BarsOfData(2).Info.Resolution.ChartType returns the chart type of the second data series.

MultiCharts .NET programming example

The example starts with the SameAsSymbol attribute:

[SameAsSymbol(true)]

By setting this attribute to true, the indicator does not create its own sub-chart.

Variable declaration and Output Window clearing

Then a Boolean variable is declared followed by its initialisation in the StartCalc() override method:

private bool printOnce;

protected override void StartCalc()
{
    printOnce = false;
    Output.Clear();
}

Setting this variable in the StartCalc() method, which is executed at the start of every calculation cycle (MultiCharts, 2013), ensures that the output is only printed once every calculation. To prevent cluttering the PowerLanguage .NET Editor Output Window, the Output.Clear() method is also called here.

Outputting resolution information in MultiCharts .NET

Next we arrive at the CalcBar() method:

protected override void CalcBar()
{
    if (!printOnce)
    {
        Output.WriteLine("Current symbol resolution information:");

        if (Bars.Info.Resolution.ChartType == ChartType.Regular)
        {
            Output.WriteLine("Data series = {0} chart type.",
                Bars.Info.Resolution.ChartType);
        }

        Output.WriteLine("Time frame: {0} minutes.",
            Bars.Info.Resolution.Duration().ToString("%m"));

        Output.WriteLine("Is day? {0}\r\nIs tick? {1}\r\nIs time-based? {2}",
            Bars.Info.Resolution.IsDayOrHigher(),
            Bars.Info.Resolution.IsOneTick(),
            Bars.Info.Resolution.IsTimeBased());

        Output.WriteLine("Size: {0}, Type: {1}",
            Bars.Info.Resolution.Size,
            Bars.Info.Resolution.Type);

        printOnce = true;
    }
}

The if statement (line 23) verifies whether the printOnce variable is false with the logical not operator (!). When that is the case, the output begins with a general statement printed to the output window (line 25).

Outputting the resolution type of the data series

In the body of the if statement is the following embedded if statement:

if (Bars.Info.Resolution.ChartType == ChartType.Regular)
{
    Output.WriteLine("Data series = {0} chart type.",
        Bars.Info.Resolution.ChartType);
}

The conditional expression in this if statement evaluates whether the chart type of the primary data series (Bars.Info.Resolution.ChartType) is a regular chart (ChartType.Regular). Since the example is applied to a minute chart, the chart type is printed with the Output.WriteLine() method.

Outputting the resolution TimeSpan duration

Next is the following segment:

Output.WriteLine("Time frame: {0} minutes.",
    Bars.Info.Resolution.Duration().ToString("%m"));

Here the Duration() method is called to get the resolution length in TimeSpan format. With the ToString() method and %m custom format specifier, the TimeSpan value is formatted as the number of minutes.

Data series resolution characteristics: day, tick, and time

Then three extension methods are called:

Output.WriteLine("Is day? {0}\r\nIs tick? {1}\r\nIs time-based? {2}",
    Bars.Info.Resolution.IsDayOrHigher(),
    Bars.Info.Resolution.IsOneTick(),
    Bars.Info.Resolution.IsTimeBased());

Here a string is formatted with string substitution parameters and the \r\n escape character (which inserts an Enter). The three values in the string are the IsDayOrHigher() method, which returns true with a daily or higher time frame. Second is the IsOneTick() method that returns true if the time frame is one tick. Third, the IsTimeBased() method, which returns true for time frames based on time.

Outputting the MultiCharts .NET resolution size and type

The last part outputs the resolution size (Bars.Info.Resolution.Size) and type (Bars.Info.Resolution.Type):

Output.WriteLine("Size: {0}, Type: {1}",
    Bars.Info.Resolution.Size,
    Bars.Info.Resolution.Type);

printOnce = true;

Both of these properties output the same information as can be found in the ‘Settings’ tab of the ‘Format Instrument’ window. In the case of the chart displayed above, they return ‘15’ and ‘Minute’, respectively.

The printOnce variable is set to true here (line 45). Doing so prevents the output from being outputted more than once.

Key points:

  • Bars.Info.Resolution provides access to various properties and methods that return information about the time frame of the current symbol;
  • The Attributes property returns information about a non-regular resolution, while the Size property returns the resolution size;
  • The Duration() method returns a TimeSpan with the resolution duration;
  • The IsDayOrHigher(), IsOneTick(), and IsTimeBased() extension methods return information about the time frame with true/false values;
  • The ChartType and Type enumeration provide information about the resolution chart type and resolution type, respectively.
References

MultiCharts (2013). MultiCharts .NET Programming Guide (version 1.0). Retrieved from http://www.multicharts.com/downloads/MultiCharts.NET-ProgrammingGuide-v1.0.pdf

MultiCharts Wiki (2013, September 16). Chart Resolution. Retrieved on August 9, 2014, from http://www.multicharts.com/trading-software/index.php/Chart_Resolution

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