Situation
You want to know how to use volume data from the primary data series in MultiCharts .NET.

Programming example

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

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

        protected override void CalcBar()
        {
            if (Bars.LastBarOnChart && (Bars.Status == EBarState.Close))
            {
                Output.WriteLine("{0} - Symbol: {1}, data source: {2}",
                    Bars.TimeValue.ToString("d-M-yyyy HH:mm:ss"),
                    Bars.Info.Name,
                    Bars.Info.DataFeed);

                Output.WriteLine("UpTicks: {0}, DownTicks: {1}. Ticks: {2}.",
                    Bars.UpTicks[0],
                    Bars.DownTicks[0],
                    Bars.Ticks[0]);

                Output.WriteLine("Volume: {0}, TrueVolume(): {1}",
                    Bars.Volume[0],
                    Bars.TrueVolume()[0]);
            }
        }
    }
}

Output of the programming example

When applied to a minute-based chart of LMAX’s EUR/GBP symbol, the indicator generates the following output to the Output Window:

20-5-2014 16:40:00 - Symbol: EUR/GBP, data source: LMAX
UpTicks: 27065, DownTicks: 50028. Ticks: 77093.
Volume: 27065, TrueVolume(): 77093
20-5-2014 16:45:00 - Symbol: EUR/GBP, data source: LMAX
UpTicks: 16190, DownTicks: 35334. Ticks: 51524.
Volume: 16190, TrueVolume(): 51524
20-5-2014 16:50:00 - Symbol: EUR/GBP, data source: LMAX
UpTicks: 15170, DownTicks: 19189. Ticks: 34359.
Volume: 15170, TrueVolume(): 34359

Volume data from the primary data series

Price and volume data are represented by price bars in any MultiCharts .NET chart, real-time market scanner, or backtest portfolio. Accessing volume data for the current bar can be done with the Bars property, which returns a reference to the IInstrument interface (MultiCharts, 2013). This works similar as retrieving price data from the primary data series.

To retrieve volume data for the current bar, the Bars property can be used in the StartCalc(), CalcBar(), or StopCalc() override methods (see MultiCharts, 2013). Referencing historical price bars with the Bars property can only be done in the CalcBar() method.

Working with volume data in MultiCharts .NET

The value that is returned by volume-related statements (such as Bars.UpTicks[0]) is dependent on the ‘Build Volume On’ instrument setting. This option, which can be found in the ‘Settings’ tab of the ‘Format Instrument’ screen, has the following impact (MultiCharts, 2013; MultiCharts Support, personal communication, August 4, 2014; MultiCharts Wiki, February 2012a, February 2012b, August 2012; PowerLanguage .NET Help, n.d.):

Bars member Description - With ‘Build Volume On’ set to ‘Trade Volume’ Description - With ‘Build Volume On’ set to ‘Tick Count’
Bars.DownTicks[0] or Bars.DownTicksValue Returns the down tick volume for the current bar. Returns the number of down ticks for the current bar.
Bars.UpTicks[0] or Bars.UpTicksValue Returns the up tick volume for the current bar. Returns the number of up ticks for the current bar.
Bars.Ticks[0] or Bars.TickValue Returns the volume of the current bar: the sum of up, down, and unchanged volume. Returns the total number of ticks (up, down, and unchanged) for the current bar.
Bars.OpenInt[0] or Bars.OpenIntValue For time-based charts with a resolution of 1 day or higher:
Returns the open interest for the current bar.

For other charts:
Returns the down tick volume for the current bar.
For time-based charts with a resolution of 1 day or higher:
Returns the open interest for the current bar.

For other charts:
Returns the number of down ticks for the current bar.
Bars.Volume[0] or Bars.VolumeValue For time-based charts with a resolution of 1 day or higher:
Returns the total volume for the current bar.

For other charts:
Returns the up tick volume for the current bar.
For time-based charts with a resolution of 1 day or higher:
Returns the total number of ticks for the current bar.

For other charts:
Returns the number of up ticks for the current bar.
Bars.TrueVolume()[0] or Bars.TrueVolume().Value Returns the total volume for the current bar. Returns the total number of ticks for the current bar.

Depending on the resolution of the chart, Bars.Volume[0] does not return the total volume for the current bar. To retrieve the total volume for the current bar, use Bars.Ticks[0] or Bars.TrueVolume()[0] (with ‘Build Volume On’ set to ‘Trade Volume’).

Programming example: attribute setting

The example begins with setting the SameAsSymbol attribute to true:

[SameAsSymbol(true)]

By setting this attribute to true, the indicator is plotted on the price chart of the primary data series instead of on a separate sub-chart.

Outputting data from the last bar on close

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

protected override void CalcBar()
{
    if (Bars.LastBarOnChart && (Bars.Status == EBarState.Close))
    {
        Output.WriteLine("{0} - Symbol: {1}, data source: {2}",
            Bars.TimeValue.ToString("d-M-yyyy HH:mm:ss"),
            Bars.Info.Name,
            Bars.Info.DataFeed);

        Output.WriteLine("UpTicks: {0}, DownTicks: {1}. Ticks: {2}.",
            Bars.UpTicks[0],
            Bars.DownTicks[0],
            Bars.Ticks[0]);

        Output.WriteLine("Volume: {0}, TrueVolume(): {1}",
            Bars.Volume[0],
            Bars.TrueVolume()[0]);
    }
}

The if statement in line 15 evaluates two conditions: first, if the current bar is the last bar on the chart (in which case the Bars.LastBarOnChart property returns true). Second, if the current price update is the closing tick of the bar. In that situation, the Bars.Status property equals the EBarState.Close enumerator.

When both of these expressions are true, the Output.WriteLine() method is called three times to output information to the Output Window.

Outputting symbol and data feed information

First, some general information is outputted:

Output.WriteLine("{0} - Symbol: {1}, data source: {2}",
    Bars.TimeValue.ToString("d-M-yyyy HH:mm:ss"),
    Bars.Info.Name,
    Bars.Info.DataFeed);

Three things are printed here with the help of string substitution parameters: the time of the current bar (Bars.TimeValue) is formatted to a string with the ToString() method, followed by the symbol name (Bars.Info.Name) and the data feed name (Bars.Info.DataFeed).

Outputting tick volume data for the current bar

The second statement outputs tick volumes:

Output.WriteLine("UpTicks: {0}, DownTicks: {1}. Ticks: {2}.",
    Bars.UpTicks[0],
    Bars.DownTicks[0],
    Bars.Ticks[0]);

Three values of the current bar are passed into the string here: the up ticks (Bars.UpTicks[0]) and down ticks (Bars.DownTicks[0]), followed by the total number of ticks (Bars.Ticks[0]).

Outputting volume data

The third segment outputs volume information:

Output.WriteLine("Volume: {0}, TrueVolume(): {1}",
    Bars.Volume[0],
    Bars.TrueVolume()[0]);

The first string substitution parameter (with Bars.Volume[0]) returns, when adding the indicator to a minute chart, the up ticks. The actual, total volume of the bar can be retrieved with the Bars.TrueVolume() method. Because this method returns a series variable (see PowerLanguage .NET Help, n.d.), we need to use a zero index (i.e., [0]) to return the value for the current bar.

Key points:

  • Bars.UpTicks[0] and Bars.DownTicks[0] return either the up and down tick volume or the number of up and down ticks, depending on the ‘Build Volume On’ instrument setting;
  • Volume data for the current bar can also be retrieved with any “Bars.*Value” property (e.g., Bars.VolumeValue or Bars.DownTicksValue);
  • Bars.VolumeValue and the equivalent Bars.Volume[0] do not return the total volume for the current bar — use Bars.Ticks[0] or Bars.TrueVolume()[0] (with ‘Build Volume On’ set to ‘Trade Volume’) to get the total volume of the bar.
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 (February 2012a). Ticks. Retrieved on May 17, 2014, from http://www.multicharts.com/trading-software/index.php/Ticks

MultiCharts Wiki (February 2012b). Volume. Retrieved on May 20, 2014, from http://www.multicharts.com/trading-software/index.php/Volume

MultiCharts Wiki (August 2012). OpenInt. Retrieved on May 20, 2014, from http://www.multicharts.com/trading-software/index.php/OpenInt

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