Situation
You want to know what features the override methods offer when it comes to processing price data and how you might use these while programming.

Programming example

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

namespace PowerLanguage.Indicator
{
    [SameAsSymbol(true)]
    public class ExampleIndicator : IndicatorObject
    {
        public ExampleIndicator(object _ctx)
            : base(_ctx)
        {
            Output.Clear();     // Clears PowerLanguage Editor Output tab
            Output.WriteLine("Class constructor method");
        }

        protected override void Create()
        {
            Output.WriteLine("Create() method");
        }

        protected override void StartCalc()
        {
            Output.WriteLine("StartCalc() method");
        }

        protected override void CalcBar()
        {
            if (Bars.CurrentBar <= 10)
            {
                Output.WriteLine("  CalcBar() method: Bar number: {0}", Bars.CurrentBar);
            }
        }

        protected override void StopCalc()
        {
            Output.WriteLine("StopCalc() method");
        }

        protected override void Destroy()
        {
            Output.WriteLine("Destroy() method");
        }
    }
}

Programming example output

If you add the above indicator to a chart and remove it, you get the following output:

Class constructor method
Create() method
StartCalc() method
  CalcBar() method: Bar number: 1
  CalcBar() method: Bar number: 2
  CalcBar() method: Bar number: 3
  CalcBar() method: Bar number: 4
  CalcBar() method: Bar number: 5
  CalcBar() method: Bar number: 6
  CalcBar() method: Bar number: 7
  CalcBar() method: Bar number: 8
  CalcBar() method: Bar number: 9
  CalcBar() method: Bar number: 10
StopCalc() method
Destroy() method

MultiCharts .NET’s override methods for price data

Technically speaking, an override method is a method that is derived from a virtual method originating from a base class (Liberty & MacDonald, 2009). In normal English this means that you can override the default behaviour of such a method by providing a new implementation.

For processing price data, the following override methods are available in MultiCharts .NET (MultiCharts, 2013):

  • The Create() method is called once when an indicator or strategy is applied to a chart or market scanner. This method is the first method that has access to price data, and is called immediately after the constructor (lines 11-16 in the example).
  • The StartCalc() method is called once every time the calculation starts. This occurs when you add the indicator or strategy to the chart, reload price data, or reload the indicator or strategy (e.g., due to changing and saving the source file).
  • The CalcBar() method is called once on every historical bar, starting from the outmost left bar (Bar number 1) to the most recent bar on the right. We can see this in the above example and its output, with this method being called on the first 10 bars.
    After all historical data has been processed, the real-time data will be processed by CalcBar(). If the ‘Update on Every Tick’ setting or the related attribute is turned on, CalcBar() will be called on every incoming tick. Otherwise this method is only called at the close of the real-time price bar.
  • The StopCalc() method is called when the indicator or strategy is switched off or removed from the price data series.
  • The Destroy() method, while technically not active in processing price data, is the last method to be called before the indicator or strategy removal from the chart.

Note that you are not required to implement all of these methods if you do not plan on using them.

Using the MultiCharts .NET override methods

These methods can be used for the following goals:

  • Use the Create() method for instantiating (meaning, creating) objects, such as the plots of an indicator, variable data series, and orders of a strategy.
  • The StartCalc() method can be used for initializing default values, for example with functions, and for preparing data before starting calculating (for example, loading data from an external data source).
  • The CalcBar() method is used for your indicator and strategy logic, such as calculating the value of an indicator, calculating trade signals, and updating plot values.
  • Use the StopCalc() method for tying up loose ends, such as outputting data to a log file or closing file streams.
  • The Destroy() method can be used for removing toolbars and custom chart drawings, or releasing file streams.

With the MultiCharts .NET override methods you will have more control over when your code is executed, which opens up a lot of possibilities.

References

Liberty, J. & MacDonald, B. (2009). Learning C# 3.0: Master the Fundamentals of C# 3.0. Sebastopol, CA: O’Reilly Media.

MultiCharts (April 2013). MultiCharts .NET Programming Guide (version 1.0). Retrieved from http://www.multicharts.com/downloads/MultiCharts.NET-ProgrammingGuide-v1.0.pdf