Situation
You want to know how to retrieve symbol information from the primary data series, such as the symbol’s name, category and description.

Programming example

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

namespace PowerLanguage.Indicator
{
    [SameAsSymbol(true)]
    public class Example_SymbolInformation : IndicatorObject
    {
        public Example_SymbolInformation(object _ctx) : base(_ctx) { }
        
        protected override void StartCalc()
        {
            // Generate the symbol description string
            string symbolDescription = "";

            if (Bars.Info.Description != "")
            {
                symbolDescription = " (" + Bars.Info.Description + ")";
            }

            // Outputting symbol information
            Output.WriteLine("Symbol name: {0}{1}, Datafeed: {2}, Category: {3}, QuoteField: {4}.",
                Bars.Info.Name,
                symbolDescription,
                Bars.Info.DataFeed,
                Bars.Info.Category,
                Bars.Info.QuoteField);
        }

        protected override void CalcBar() { }
    }
}

Output of the programming example

Applied to a chart of AUD/CAD (LMAX), EUR/USD (MB Trading), ES (IQFeed) and GOOG (IQFeed), the indicator generates the following output, respectively:

Symbol name: AUD/CAD, Datafeed: LMAX, Category: Forex, QuoteField: Bid.
Symbol name: EUR/USD (Euro/US Dollar), Datafeed: MB Trading, Category: Forex, QuoteField: Bid.
Symbol name: @ES# (E-MINI S&P 500), Datafeed: IQFeed, Category: Future, QuoteField: Trade.
Symbol name: GOOG (GOOGLE INC.), Datafeed: IQFeed, Category: Stock, QuoteField: Trade.

Working with symbol information in MultiCharts .NET

Characteristics of the symbol (such as the name, description, and category of the symbol) are available in MultiCharts .NET through the Bars.Info property, which provides access to the IInstrumentSettings interface (MultiCharts, 2013).

By the way, the BarsOfData() method provides access to symbol information from non-primary data series (MultiCharts, 2013): for example, BarsOfData(2).Info.Name returns the symbol name of the second data series, while BarsOfData(3).Info.DataFeed returns the data feed of the third data series.

The Bars.Info property can be used in the StartCalc(), CalcBar(), StopCalc(), and Destroy() override methods. A range of information is available through this property, such as the symbol’s QuoteManager data, the chart resolution data, and general symbol information.

Retrieving symbol information in MultiCharts .NET

The following general symbol information is available through the Bars.Info property (MultiCharts, 2013; PowerLanguage .NET Help, n.d.):

Property Description
Bars.Info.Name Returns a string with the symbol name (for example, "EUR/USD").
Bars.Info.DataFeed Returns a string with the name of the data source (like IQFeed or LMAX).
Bars.Info.Description Returns a string with the description of the symbol (such as "S&P 500 future").
Bars.Info.Category Returns an enumerator from the ESymbolCategory enumeration, which specifies the asset class of the instrument.
Bars.Info.QuoteField Returns a RequestQuoteField enumerator that signals the used quote field on the chart (Ask, Bid, or Trade).

MultiCharts .NET programming example

To prevent the indicator from creating a sub-chart, the example begins with setting the SameAsSymbol attribute to true:

[SameAsSymbol(true)]

Generating a MultiCharts .NET symbol description string

The next part of the example is the StartCalc() override method:

protected override void StartCalc()
{
    // Generate the symbol description string
    string symbolDescription = "";

    if (Bars.Info.Description != "")
    {
        symbolDescription = " (" + Bars.Info.Description + ")";
    }

    // Outputting symbol information
    Output.WriteLine("Symbol name: {0}{1}, Datafeed: {2}, Category: {3}, QuoteField: {4}.",
        Bars.Info.Name,
        symbolDescription,
        Bars.Info.DataFeed,
        Bars.Info.Category,
        Bars.Info.QuoteField);
}

This method, called once every time the script calculation starts (MultiCharts, 2013), begins with declaring and initialising the symbolDescription string (line 16).

Then an if statement is used to verify if the symbol description (Bars.Info.Description) is not equal to (!=) an empty string (line 18). When that evaluates to true, the symbolDescription string is generated by combining (in other words, concatenating) three strings: the two parentheses together with the symbol description. This makes the output slightly nicer: no parentheses will be displayed when the symbol description is empty (see the output of the example above).

Outputting symbol information in MultiCharts .NET

The second part of the StartCalc() method outputs symbol information to the PowerLanguage .NET Editor Output Window by calling the Output.WriteLine() method:

// Outputting symbol information
Output.WriteLine("Symbol name: {0}{1}, Datafeed: {2}, Category: {3}, QuoteField: {4}.",
    Bars.Info.Name,
    symbolDescription,
    Bars.Info.DataFeed,
    Bars.Info.Category,
    Bars.Info.QuoteField);

The string argument that is generated here with string substitution parameters consists out of five values. The first two are the symbol name (Bars.Info.Name) and the symbolDescription string, followed by the name of the symbol’s data feed (Bars.Info.DataFeed). The last two are the Bars.Info.Category and Bars.Info.QuoteField enumerators, which return the asset class and quote field of the symbol, respectively.

Key points:

  • The Bars.Info property returns symbol information of the primary data series, such as the symbol name (Bars.Info.Name) and asset category (Bars.Info.Category);
  • Symbol information from additional data series can be retrieved with the BarsOfData() method (for example, BarsOfData(2).Info.Name).
References

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

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