The MultiCharts .NET Command Line can be used for a range of things, such as adding data series or indicators to the chart. But how can it be used to add trading strategies?

Using the Command Line to add trading signals to the chart

Adding a trading strategy to the chart is done with the Command Line’s .isig command (MultiCharts Wiki, 2014). Like the other Command Line commands, .isig can be executed programmatically with the ChartCommands.CommandLine() method (PowerLanguage .NET Help, n.d.).

.isig (Insert SIGnal) basically operates like this:

ChartCommands.CommandLine(".isig name1=MACD_LE");

This statement adds the MACD_LE trading strategy to the chart with this signal’s default inputs.

Parameters for adding trading strategies programmatically in MultiCharts .NET

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

Parameter Description Parameter example
nameN Specifies the trading strategy to add to the chart. nameN can go up to 99 (name1, name2, name3, etc) and needs to match a strategy’s name exactly (naming errors can be prevented by verifying if a script exists). name1=RSI_LE, name2=RSI_SE for adding these two strategies to the chart.
, Separates multiple name_N_ parameters used in a .isig command. name1=EMA_LE, name2=EMA_SE.

When .isig is used without parameters, it brings up the ‘Insert Study’ window for manually adding the signal. Indicators can also use .isig by calling the ChartCommands.CommandLine() method.

As the table shows, there are no parameters for setting a strategy’s inputs or properties. And trading strategies cannot be removed programmatically.

Tip: Like the .iind command for adding indicators, .isig adds trading strategies each time it’s executed by ChartCommands.CommandLine(). To prevent the same strategy from being added multiple times, execute this method conditionally (such as in an if statement).

Using the Command Line to add a strategy: before and after

Before discussing the programming code, here’s what it does when starting with an chart like this:

Adding a MultiCharts .NET trading strategy - before

And then adding the example strategy, which leads to:

Adding a MultiCharts .NET trading strategy - after

Adding a MultiCharts .NET trading strategy with the Command Line

Those two trading strategies were added programmatically with:

private bool strategyAlreadyAdded = false;

protected override void StartCalc()
{
    if (strategyAlreadyAdded == false)
    {
        ChartCommands.CommandLine(".isig name1=Channel_Breakout_LE, " +
            "name2=Channel_Breakout_SE");

        strategyAlreadyAdded = true;
    }
}

Here we first declare and initialise a Boolean variable to false. This strategyAlreadyAdded variable is used later to prevent ChartCommands.CommandLine() from executing repeatedly.

In the StartCalc() method, executed once at the beginning of every calculation cycle (MultiCharts, 2013), the if statement’s expression evaluates whether strategyAlreadyAdded equals false. When that is the case, the code inside the if statement is executed.

That code calls the ChartCommands.CommandLine() method with a string argument that contains the .isig command and two name_N_ parameters for adding the Channel_Breakout_LE and Channel_Breakout_SE trading strategies to the chart. After that strategyAlreadyAdded is set to true. Since that invalidates the if statement’s expression, this code is only executed once. Without this check, the strategies would have been added numerous times.

Other uses of the Command Line and trading strategies are enabling or disabling trading strategies and bringing up the Strategy Performance Report programmatically.

Summary

Trading strategies can be added to the chart with the .isig Command Line command, which can be executed programmatically with the ChartCommands.CommandLine() method. Each time .isig is executed, the signal(s) specified by its nameN parameters are added to the price chart.

Complete code of the MultiCharts .NET trading strategy

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

namespace PowerLanguage.Strategy
{
    public class Example_AddStrategyProgrammatically : SignalObject
    {
        public Example_AddStrategyProgrammatically(object _ctx) : base(_ctx) { }

        private bool strategyAlreadyAdded = false;

        protected override void StartCalc()
        {
            if (strategyAlreadyAdded == false)
            {
                ChartCommands.CommandLine(".isig name1=Channel_Breakout_LE, " +
                    "name2=Channel_Breakout_SE");

                strategyAlreadyAdded = true;
            }
        }

        protected override void CalcBar() { }
    }
}

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