The Command Line can, for example, change a chart symbol and change a data range. But how can it be used to change a symbol’s resolution programmatically?

Adjusting the symbol’s resolution through the Command Line

Changing a data series’ resolution programmatically is done with the .csy Command Line command and its res parameter passed into the ChartCommands.CommandLine() method (MultiCharts Wiki, 2014; PowerLanguage .NET Help, n.d.).

Changing the resolution basically looks like:

ChartCommands.CommandLine(".csy res=30 minutes, dnum=2");

Here the second data series (dnum=2) has its resolution changed to 30 minutes (res=30 minutes). For more .csy parameters, see changing the symbol with the Command Line.

Table of resolutions for the MultiCharts .NET Command Line

The res parameter can set the following resolutions (MultiCharts Wiki, 2014):

Resolution type Values Example
Tick tick, ticks, t, or ts res=250 tick: builds a 250 tick chart.
Contract volume, volumes, contract, or contracts res=1000 contract: makes a volume chart of 1000 contracts per bar.
Point point, points, pt, or pts res=2 pts: constructs a 2 point chart.
Point Original point(original), orpt, or orpts res=4 orpt: assembles a 4 point (original) time frame.
Change change, changes, chg, or chgs res=10 chg: builds a 10 change chart.
Second second, seconds, sec, or secs res=30 secs: sets a data series to a 30 seconds time frame.
Minute minute, minutes, min, or mins res=15 min: constructs a 15 minute chart.
Hour hour, hours, hr, or hrs res=1 hours: creates a resolution of 1 hour.
Day day, days, d, or ds res=1 d: for a 1 day time frame.
Week week, weeks, wk, or wks res=1 wk: assembles a 1 week time frame.
Month month, months, mth, or mths res=1 mths: for a resolution of 1 month.
Quarter quarter, quarters, qrt, or qrts res=2 quarter: creates a time frame of six months.
Year year, years, yr, or yrs res=1 yrs: constructs a 1 year time frame.

Changing the resolution with the Command Line: before and after

Before discussing the programming code, let’s see what it does. Starting with a chart like the following:

Example of changing the resolution in MultiCharts .NET - before

Adding the MultiCharts .NET indicator changes both data series to:

Example of changing the resolution in MultiCharts .NET - after

Programmatically changing the resolution in MultiCharts .NET

Changing the resolution with ChartCommands.CommandLine() is done as follows:

private bool alreadyChanged = false;

protected override void CalcBar()
{
    if (Bars.LastBarOnChart && !alreadyChanged)
    {
        ChartCommands.CommandLine(".csy res=15 minutes, dnum=1");

        ChartCommands.CommandLine(".csy res=1 hour, dnum=2");

        alreadyChanged = true;
    }
}

The if statement here checks if the current bar is the last bar on the chart (in which case Bars.LastBarOnChart returns true) and if the alreadyChanged variable is false. This latter is tested with the logical not operator (!), which makes the expression true when alreadyChanged is false.

Inside the if statement the ChartCommands.CommandLine() method is called twice. It first changes the resolution of the first data series to 15 minutes, followed by adjusting the time frame of the second data series to 1 hour.

Then the alreadyChanged Boolean variable is set to true. That invalidates the if statement’s expression and ensures that the ChartCommands.CommandLine() methods are only executed once.

Summary

The .csy Command Line command can change the resolution of a data series with its res (resolution) and dnum (data series number) parameters. This command can be executed programmatically with ChartCommands.CommandLine().

Complete code of the MultiCharts .NET indicator

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

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

        private bool alreadyChanged = false;

        protected override void CalcBar()
        {
            if (Bars.LastBarOnChart && !alreadyChanged)
            {
                ChartCommands.CommandLine(".csy res=15 minutes, dnum=1");

                ChartCommands.CommandLine(".csy res=1 hour, dnum=2");

                alreadyChanged = true;
            }
        }
    }
}

References

MultiCharts Wiki (2014, August 18). MultiCharts Work Area: Understanding Command Line. Retrieved on November 18, 2014, from http://www.multicharts.com/trading-software/index.php/MultiCharts_Work_Area#Understanding_Command_Line

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