The MultiCharts .NET Command Line can be used to control the chart window with various commands. But how can we change a chart symbol through the code?

Changing the symbol with the MultiCharts .NET Command Line

The .csy Command Line command changes the chart’s symbol (MultiCharts Wiki, 2014), and is executed programmatically with the ChartCommands.CommandLine() method (PowerLanguage .NET Help, n.d.). It’s basic usage looks like:

ChartCommands.CommandLine(".csy name=GBP/USD");

This statement changes the primary data series to the GBP/USD symbol.

The .csy (Change SYmbol) command has the following parameters (MultiCharts Wiki, 2014):

Parameter(s) Description Example
name Sets the symbol to change to (case sensitive). name=EUR/USD creates an EUR/USD chart, while name=@EU# switches the symbol to IQFeed’s continuous 6E future.
df Specifies the symbol’s data feed. Needs to match exactly. name=EUR/USD, df=MB Trading specifies that the EUR/USD symbol from MB Trading should be plotted. Note that df=MB trading (wrong capitalisation) and df=MB Trading (two spaces) don’t work.
desc Specifies the description of the symbol to load (case sensitive). desc=EURO STOXX 50: changes the chart to the EuroStoxx 50 future.
res Sets the resolution of the symbol. See changing the chart resolution with the Command Line for an overview of possible values. When this parameter is missing, the resolution of the existing data series on the chart is used. res=15min: plots the symbol as a 15 minute chart.
from, to Set the data range. The required date format depends on your Windows settings and is either DD/MM/YYYY or MM/DD/YYYY (Andrew MultiCharts, 2014). When these parameters aren’t set, the data range of the existing data series on the chart is used. For more, see changing the data range programmatically. from=1/5/2012, to=9/10/2014: plot the symbol from May 1, 2012, to October 9, 2014, when one’s operating system is set to Western European settings.
dnum Specifies the data number. When omitted, defaults to the selected data series; with no data series selected it applies to the first data series. dnum=2: makes the .csy command apply to the second data series.
bfm Specifies whether a daily-based chart (day, week, month, quarter, or year time frame) needs to be based on minute (bfm=1) or daily (bfm=0) data. When bfm is missing, daily-based charts are made with daily data. res=1day, bfm=1: creates a daily chart constructed from minute data.
mute Prevents the ‘Format Instrument’ window from displaying when there is an error in the .csy command (by default, this window is shown). name=ER/DSU, mute: switches to the non-existing ER/DSU symbol, but won’t show the ‘Format Instrument’ window with this faulty request.
, Multiple .csy parameters are separated with comma’s. .csy name=EUR/USD, res=15min.

Changing the symbol in MultiCharts .NET with the Command Line

Changing the chart symbol programmatically can be done as follows:

private bool alreadyChanged = false;

protected override void CalcBar()
{
    if (!alreadyChanged && Bars.LastBarOnChart)
    {
        ChartCommands.CommandLine(".csy name=EUR/GBP, df=LMAX, res=30min");

        alreadyChanged = true;
    }
}

Two expressions are evaluated in the if statement here. The first uses the logical not operator (!) to check whether it’s true that the alreadyChanged variable is false. The second expression evaluates if the current bar is the last bar on the chart, in which case the Bars.LastBarOnChart property returns true.

When both expressions are true, the ChartCommands.CommandLine() method is called. Its argument consists out of the .csy command with parameters to change the symbol of the first data series to a 30 minute LMAX EUR/GBP chart.

Then the alreadyChanged variable is set to true, which makes the if statement’s expression false. That way, the .csy command is only executed once. When such a check isn’t added, the chart would change continuously to the EUR/GBP symbol.

Other things we can do with .csy is changing the data range, the chart’s resolution, and the start or end date of the data range.

Summary

Programmatically changing the chart’s symbol is done with the .csy command passed to the ChartCommands.CommandLine() method. This command has several parameters, including name (symbol), df (data feed), and res (resolution).

Complete MultiCharts .NET programming example

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

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

        private bool alreadyChanged = false;

        protected override void CalcBar()
        {
            if (!alreadyChanged && Bars.LastBarOnChart)
            {
                ChartCommands.CommandLine(".csy name=EUR/GBP, df=LMAX, res=30min");

                alreadyChanged = true;
            }
        }
    }
}

References

Andrew MultiCharts (2014, October 6). Command line to change start date – forum discussion. Retrieved on November 21, 2014, from http://www.multicharts.com/discussion/viewtopic.php?f=1&t=47294#p108924

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