When we edit MultiCharts .NET scripts, but also when creating indicators, coding functions, and programming trading strategies, we’ll often use the code completion window in the PowerLanguage .NET Editor. What is this feature and how does it work?

The PowerLanguage .NET Editor and intelligent code completion

The PowerLanguage .NET Editor is our primary tool for creating and editing MultiCharts .NET indicators, trading strategies, and functions (MultiCharts, 2014). And while we can also edit scripts in other programs (such as Visual Studio), importing, exporting, and removing scripts, as well as adding DLL references, is only possible in the PowerLanguage .NET Editor.

Because of that we’ll spend a lot of time programming in this code editor. Luckily, the PowerLanguage .NET Editor makes coding much more efficient with something called ‘intelligent code completion’. This feature looks as follows:

Example of the IntelliSense feature

This context-aware completion feature, popularised as IntelliSense (“intelligent sense”) by Visual Studio, displays prompts and descriptions of accessible items (Stephens, 2014; Wikipedia, 2015). By doing so it prevents typing errors and reduces the amount we need to type (Liberty & MacDonald, 2009). Let’s look at its features in depth.

Opening the IntelliSense feature in the PowerLanguage .NET Editor

The code completion window in the PowerLanguage .NET Editor opens automatically when we pause during typing or when we type a dot (.). We can force the IntelliSense window to open at the location of the text cursor with the Ctrl + Space keyboard shortcut. The IntelliSense’s list contains all methods, properties, and fields that belong to whatever we’ve already typed (Sharp, 2013).

For instance, typing Bars. opens the IntelliSense window with the following list of items:

IntelliSense opening after typing a dot

We insert an item by double-clicking on it or press Tab or Enter to insert the highlighted item. By the way, if there’s only one way to complete what has already been typed, then the code completion window won’t open but instead will complete the code for us. That means that the IntelliSense feature only displays when there are still multiple options remaining.

Context-awareness of the PowerLanguage .NET Editor IntelliSense

The IntelliSense drop-down list contains all code elements that are available and valid in the current context (Liberty & MacDonald, 2009; Sharp, 2013). For instance, in the top of a trading strategy’s class file the Bars property, which provides access to data from the first data series (MultiCharts, 2014), isn’t available:

Context awareness of the IntelliSense feature

But in CalcBar(), a method that’s executed at least once every bar (MultiCharts, 2014), we can access Bars as well as methods that weren’t available in the top of the class file:

Context awareness of the IntelliSense feature

This context-awareness feature makes it much easier to see which code is allowed in the current context, which helps to reduce programming errors.

Icons used in the code completion window

As the images above show, each IntelliSense item is preceded by an icon. These icons, which are called babel icons (Microsoft Developer Network, n.d.), are similar to those used in Visual Studio. While we can easily do without knowing their meaning, recognising them can help if you’re searching for a specific code element.

The icons in the PowerLanguage .NET Editor’s code completion window and their meaning are:

Icon Description Example
Class XAverage, List<>, Bollinger_Bands_LE.
Constant Any constant variable you’ve added to your script.
Delegate LoadDataCallback, ITC_CommandChanged_OnChangeEventHandler.
Enumeration EPlotShapes, EBarState, EOrderAction.
Enumeration item EPlotShapes.Histogram, EBarState.Close, EOrderAction.Buy.
Event Any event you’ve added to the script.
Extension method Bars.High.Highest(), Bars.Low.Lowest(), Bars.CurrentBarAbsolute().
Field (private) Any variable you’ve declared in the current class and that’s marked private.
Field (public) Any public declared variable in the class.
Field (protected) Any protected declared variable in the class.
Field (internal) Any internal declared variable in the class.
Interface IPlotObject, IOrderPriced, IOrderMarket.
Keyword where, for, break, bool, double.
Local variable Any variable you’ve declared in a method.
Method Equals(), ReferenceEquals().
Method (internal) Any custom method that you’ve added to a script and that’s declared internal.
Method (private) Any private method that you’ve added to a script.
Method (protected) CalcBar(), StartCalc(), OnMouseEvent().
Namespace PowerLanguage.Function, System, System.Collections.Generic.
Property Bars.Close, Account, AvgBarsEvenTrade.
Structure ChartPoint, Decimal, PlotAttributes.

IntelliSense help descriptions in the PowerLanguage .NET Editor

Besides icons, the code completion window also shows a brief explanation of the selected item. For instance, here we can see that the highlighted item (AvgEntryPrice) is a read-only property that returns a double value with the average entry price:

Code explanation in the IntelliSense feature

These descriptions are also visible when we hover with the mouse over a code element, which brings up a tooltip window with the element in question:

Code explanation when hovering with the mouse

Another helpful feature of the code completion window is the information about overloaded methods. An overloaded method is a method that has the same name as another method, but whose parameters differ in type or number (Sempf, Sphar, & Davis, 2010; Sharp, 2013).

For example, here the code completion window shows us that the Send() method (which generates trading orders; PowerLanguage .NET Help, n.d.), has 4 versions: the one that’s currently displayed plus 3 others:

Overloaded methods highlighted in IntelliSense

When we insert the highlighted Send() with Enter, Tab, or by typing, the IntelliSense selects the first overloaded method (see arrow) and describes this method version together with a required int value:

Overloaded methods explained in IntelliSense

We select another overloaded method in the IntelliSense window with the arrow up and down keys, which also causes the description to change with it. The second overloaded Send() method, for example, requires a string and an int:

Overloaded methods explained in IntelliSense

While the third version of Send() only needs a string:

Overloaded methods explained in IntelliSense

And the fourth and final overloaded Send() method doesn’t have a parameter at all:

Overloaded methods explained in IntelliSense

For more on working with the PowerLanguage .NET Editor, see editing scripts and compiling MultiCharts .NET scripts. The tutorials about creating an indicator, coding a function, and programming a trading strategy contain more examples and information about the PowerLanguage .NET Editor.

Summary

The code completion window in the PowerLanguage .NET Editor, a feature that’s also known as IntelliSense, opens when we type something or press Ctrl + Space. It contains all the code elements that are available in the current context, which speeds up programming and reduces mistakes. The window also contains help information about the highlighted code element.


References

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

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

Microsoft Developer Network (n.d.). Babel Icons. Retrieved on August 25, 2015, from https://msdn.microsoft.com/en-us/library/bb166402%28v=VS.90%29.aspx

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

Sempf, B., Sphar, C., & Davis, S.R. (2010). C# 2010 All-In-One for Dummies. Hoboken, NJ: John Wiley & Sons.

Sharp, J. (2013). Microsoft Visual C# 2013 Step by Step. Microsoft Press.

Stephens, R. (2014). C# 5.0 Programmer Reference. Indianapolis, IN: John Wiley & Sons.

Wikipedia (2015, August 16). Intelligent code completion. Retrieved on August 26, 2015, from https://en.wikipedia.org/wiki/Intelligent_code_completion