Indicators can be displayed on either a data series’ price chart or in their own subchart (Henry MultiCharts, 2014a). But how can we programmatically specify where an indicator should plot?

The SameAsSymbol attribute: specifying a MultiCharts .NET indicator’s chart area

An attribute is a special tag that is added to the top of a C# class and, by doing so, stores metadata about the code (Stellman & Greene, 2010). In MultiCharts .NET these class attributes are used to change script’s settings.

One of these options is where to plot an indicator, which is set with the SameAsSymbol attribute. When this attribute is set to true, the indicator is plotted on the data series; when set to false, it’s displayed in a separate subchart (MultiCharts, 2014).

Setting the SameAsSymbol attribute in MultiCharts .NET

So in order to plot an indicator on a data series, SameAsSymbol is set as follows:

[SameAsSymbol(true)]
public class Example_SameAsSymbol : IndicatorObject
{
    // Indicator code
}

And when set to false an indicator is plotted in its own subchart:

[SameAsSymbol(false)]
public class Example_SameAsSymbol : IndicatorObject
{
    // Indicator code
}

The default behaviour of plotting in an individual subchart applies when SameAsSymbol isn’t defined in the code.

Example: plotting a MultiCharts .NET indicator on a data series

The following indicator uses SameAsSymbol to plot its line on a data series:

[SameAsSymbol(true)]
public class Example_SameAsSymbol : IndicatorObject
{
    public Example_SameAsSymbol(object _ctx) : base(_ctx) { }

    private IPlotObject closePlot;

    protected override void Create()
    {
        closePlot = AddPlot(new PlotAttributes("Close", 
            EPlotShapes.Line, Color.DarkOrange, Color.Black, 3, 
            EPlotStyle.Solid, true));
    }

    protected override void CalcBar()
    {
        closePlot.Set(Bars.Close[0]);
    }
}

We start with setting SameAsSymbol to true. Then in the indicator’s class an IPlotObject named closePlot is declared, which we’ll use to plot the closing price. This plot object is subsequently created in the Create() method.

For that the AddPlot() method is used together with a new instance of the PlotAttributes, which specifies the plot’s features in it’s overloaded constructor (see PowerLanguage .NET Help, n.d.). This sets, among other things, the plot to a line (EPlotShapes.Line) coloured in orange (Color.DarkOrange) with a width of 3.

In the CalcBar() method the plot value is set to the bar’s last price (Bars.Close[0]). When added to a chart the indicator looks like:

MultiCharts .NET SameAsSymbol - plotted on data series

Plotting a MultiCharts .NET indicator in it’s own subchart

To plot the indicator in a separate subchart, SameAsSymbol in the above example needs to be set to false. That would give the following with the other code unchanged:

MultiCharts .NET SameAsSymbol - separate subchart

By the way, should you add an indicator to a chart and change things like an attribute, the script needs to be removed and re-added in order to see the modified code (see Henry MultiCharts, 2014b).

Setting ‘Same As Symbol’ manually in the PowerLanguage .NET Editor

The option that SameAsSymbol affects can also be set manually in the PowerLanguage .NET Editor (Henry MultiCharts, 2014a). To do so, right-click somewhere in the editor’s code window and select ‘Properties’:

MultiCharts .NET SameAsSymbol - Code editor

Then in the ‘Indicator Properties’ window enable or disable ‘Same As Symbol’:

MultiCharts .NET SameAsSymbol - Indicator properties

After an indicator has been added to the chart, it’s subchart can be changed by right-clicking the indicator’s name in the Status Line and selecting ‘Format [script name]‘. Then go to the ‘Properties’ tab and select one of the ‘SubChart’ options:

MultiCharts .NET SameAsSymbol - after adding to chart

Summary

The SameAsSymbol attribute plots an indicator on a data series (when set to true) or in its own subchart (when false). This option can also be set manually in the PowerLanguage .NET Editor.


References

Henry MultiCharts (2014a, November 4). Indicator subchart – forum discussion. Retrieved on January 25, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=47514#p110178

Henry MultiCharts (2014b, December 11). MultiCharts .NET FAQ – forum discussion. Retrieved on January 25, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=45848#p111375

MultiCharts (2014). MultiCharts .NET Programming Guide (version 1.1). Retrieved from http://www.multicharts.com/downloads/MultiCharts.NET-ProgrammingGuide-v1.1.pdf

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

Stellman, A. & Greene, J. (2010). Head First C#: A Brain-Friendly Guide (2nd edition). Sebastopol, CA: O’Reilly Media.