The MultiCharts .NET Command Line can be used for changing a symbol on the chart. But how to add a new symbol to the chart programmatically?

Adding a symbol to the MultiCharts .NET price chart programmatically

The .isy Command Line command adds a symbol to the chart (MultiCharts Wiki, 2014). With the ChartCommands.CommandLine() method this command can be executed programmatically (PowerLanguage .NET Help, n.d.).

The basic usage of .isy (Insert SYmbol) looks like:

ChartCommands.CommandLine(".isy name=@ES#");

This statement adds the @ES# symbol (IQFeed’s E-mini S&P500 continuous future) to the current chart.

Parameters of the .isy (insert symbol) Command Line command

The .isy command has the following parameters (MultiCharts Wiki, 2014):

Parameter(s) Description Parameter example
name Specifies the symbol to add to the chart (case sensitive). name=@EU#: adds IQFeed’s continuous 6E (EUR/USD) future.
df Sets the symbol’s data feed. Needs to match the data feed name exactly. name=EUR/USD, df=LMAX: adds LMAX’s EUR/USD symbol to the chart instead of MB Trading’s EUR/USD symbol.
res Defines the resolution of the added symbol. See changing the chart resolution for possible values. Defaults to the last used resolution when omitted. res=30min: adds the symbol with a 30 minute time frame.
desc Specifies the description of the symbol to add. Needs to match the QuoteManager’s description exactly. desc=E-MINI NASDAQ 100: adds the NQ future (E-mini NASDAQ 100) to the chart.
from, to Sets the data range of the symbol to add. The required date format depends on your Windows settings and is either day/month/year or month/day/year (Andrew MultiCharts, 2014). Defaults to the last used data range when these parameters are missing. from=1/1/2014, to=1/1/2015: sets the data range to the full year of 2014.
bfm Defines 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) price data. With bfm missing, daily-based charts are made with daily price data. res=1day, bfm=1: creates a daily chart based on minute data.
, The comma is used to separate multiple .isy parameters. .isy name=EUR/AUD, res=60min.

Adding a symbol to the MultiCharts .NET chart programmatically

The example adds another data series to the chart as follows:

private bool alreadyAdded = false;

protected override void CalcBar()
{
    if (Bars.LastBarOnChart && !alreadyAdded)
    {
        ChartCommands.CommandLine(
            ".isy name=EUR/USD, df=LMAX, res=10min");

        alreadyAdded = true;
    }
}

We first declare and initialise a Boolean variable (alreadyAdded) to false. This variable is used later on to prevent the symbol from being added more than once.

In the CalcBar() method, an if statement verifies whether the current bar is the last on the chart (then Bars.LastBarOnChart returns true; MultiCharts, 2013) and if alreadyAdded is false. This latter is checked with the ! logical not operator.

When both expressions evaluate to true, the ChartCommands.CommandLine() method is executed. Its string argument contains the .isy command to add LMAX’s EUR/USD data series with a time frame of 10 minutes. After that, the alreadyAdded variable is set to true. That invalidates the if statement’s expression, and so the ChartCommands.CommandLine() is executed once.

Ideas for working with MultiCharts .NET’s .isy command

The .isy command has the same parameters as the command for changing the chart symbol (.csy). The following .csy programming examples can therefore also be applied to .isy:

Summary

The .isy Command Line command adds another data series to the chart, and has several parameters like name (symbol name), df (data feed), and res (resolution). .isy can be executed programmatically with ChartCommands.CommandLine(), and each time the command is executed a data series is added to the chart.

Complete code of the MultiCharts .NET indicator

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

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

        private bool alreadyAdded = false;

        protected override void CalcBar()
        {
            if (Bars.LastBarOnChart && !alreadyAdded)
            {
                ChartCommands.CommandLine(
                    ".isy name=EUR/USD, df=LMAX, res=10min");

                alreadyAdded = 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 (2013). MultiCharts .NET Programming Guide (version 1.0). Retrieved from http://www.multicharts.com/downloads/MultiCharts.NET-ProgrammingGuide-v1.0.pdf

MultiCharts Wiki (2014, August 18). MultiCharts Work Area: Understanding Command Line. Retrieved on December 10, 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