After we edit a script or create a new trading strategy, function, or indicator, the code needs to be compiled before we can use the updated script in the PowerLanguage .NET Editor. What is this ‘compiling’?

The PowerLanguage .NET Editor and compiling scripts

The PowerLanguage .NET Editor is our primary tool for creating and editing MultiCharts .NET indicators, trading strategies, and functions (MultiCharts, 2014). Things that we can do with this program include exporting, importing, removing, and editing scripts. But before we can add a modified script to the chart, it needs to be saved and compiled first.

Compiling is the process of turning code that we can read into code that the computer can read, which transforms the source code into an actual program (Liberty & MacDonald, 2009; Sempf, Sphar, & Davis, 2010). This is also called compilation (Albahari & Albahari, 2012). We can compile MultiCharts .NET scripts either manually or automatically.

How to see if a MultiCharts .NET script is compiled or not?

When a MultiCharts .NET script is not compiled, its icon in the ‘Studies’ window in the PowerLanguage .NET Editor is red ( ) while compiled scripts are listed with a green icon ( ). For instance:

Uncompiled script in the PowerLanguage .NET Editor

We can also see a script’s compilation status in the right-hand side of the PowerLanguage .NET Editor’s status bar. When the currently open script is compiled, the status bar says ‘VERIFIED’:

Verified script in the PowerLanguage .NET Editor status bar

And when a script isn’t compiled, that message is missing from the status bar:

Saved script in the PowerLanguage .NET Editor status bar

However, even when a script currently isn’t compiled, we can still use it in MultiCharts .NET as long as there is a previous compiled version. For example, while our ‘Example_Strategy’ isn’t compiled, it still has the ‘Ready Status’ of ‘Yes’ when adding it to a chart:

Inserting a compiled MultiCharts .NET study

New, uncompiled scripts cannot be added to a chart on the other hand:

Adding an uncompiled MultiCharts .NET script to the chart

Manually compiling scripts in the PowerLanguage .NET Editor

There are two commands in the PowerLanguage .NET Editor for compiling scripts: ‘Compiled changed studies’ (F7 keyboard shortcut) to only compile the edited scripts and ‘Force recompile all studies’ (Ctrl + F7) to compile all scripts (MultiCharts, 2014). Studies are, by the way, the term that MultiCharts .NET uses for indicators, trading strategies, and functions (MultiCharts Wiki, 2013).

We can access both of these commands through the menu items:

Compile menu in the PowerLanguage .NET Editor

The command for manually compiling changed scripts ( ) and the option to compile all scripts ( ) are also accessible from the toolbar:

Compile toolbar buttons in the PowerLanguage .NET Editor

Compiling MultiCharts .NET scripts automatically

Besides manual compilation, scripts can also be compiled automatically. This happens when a C# or Visual Basic script is edited outside of the PowerLanguage .NET Editor. MultiCharts .NET will then notice these changes and compile the script (MultiCharts, 2014). Thanks to this feature we can conveniently work on scripts in other programs, like Visual Studio, without having to switch back to the PowerLanguage .NET Editor to do the compiling.

Once a script is compiled, either manually or automatically, then the script on the chart is automatically reloaded.

Automatic reloading of MultiCharts .NET scripts

When a script compiles, MultiCharts .NET checks to see if it’s currently in use. When it is, then after the compilation completed successfully, MultiCharts .NET will recreate the instance of the script (MultiCharts, 2014). That means that, after compiling, the script is reloaded and will again process all price bars (from the first till the last).

This automatic script reload has three important features. First, not all of the script’s methods are reloaded: both the Create() method and the constructor, a method that has the same name as the script (Liberty & MacDonald, 2009), are not executed again (Henry MultiCharts, 2014a). This means that, after we change the code in one of those methods, we need to manually remove the script from the chart, Scanner/Watchlist window, or Portfolio Trader and re-add it again before we see the effect of the new code.

Second, changing and compiling a function doesn’t lead to an automatic reload of the indicator or strategy that uses that function. That’s because MultiCharts .NET doesn’t analyse scripts to know if any functions were used and whether these were modified (Henry MultiCharts, 2013). And so scripts that use the edited function need to be removed and re-added to the chart before the effect of the changed function is visible.

Third, automatic script reloading can have unintended consequences, especially for trading strategies since it also turns off automated trading (MultiCharts, 2014). When the recompiled strategy has an open position, MultiCharts .NET issues a warning message asking if we want to keep the position open or not:

Auto-trading disabled due to compiling

Compilation modes in the PowerLanguage .NET Editor

We can choose between two different compilation modes in the PowerLanguage .NET Editor’s toolbar:

Choosing a compile mode in the PowerLanguage .NET Editor

These configuration have the following features (Henry MultiCharts, 2014b; MultiCharts, 2014):

  • ‘Debug’ is used for the development and debugging of scripts. It compiles scripts such that they include additional debug information and features to allow for easy debugging.
  • ‘Release’, on the other hand, compiles scripts so that they run more efficient. This gives them a slightly better (but frequently not really noticeable) improvement in speed and performance. We use ‘Release’ to create the script’s final build (meaning, the script version that’s going to be used in real-time trading).

In other words, ‘Debug’ makes debugging code easier while ‘Release’ is focused on making our code run as efficient as possible. Whichever compilation mode we use, MultiCharts .NET remembers this and compiles future scripts with the same setting (MultiCharts, 2014).

To create your own script and compile it, see creating an indicator, trading strategy, and function. We also need to compile scripts after editing a script’s settings.

Summary

Compiling is the process of turning our script’s code into computer-readable code. We can do this either manually with the ‘Compile changed studies’ (F7) and ‘Force recompile all studies’ (Ctrl + F7) commands, or trigger an automatic compilation by editing and saving a script outside the PowerLanguage .NET Editor. When a script is compiled with the ‘Debug’ configuration extra information and features are added to it for easy debugging. The ‘Release’ compilation mode, on the other hand, optimises the script’s code to run more efficient.


References

Albahari, J. & Albahari, B. (2012). C# 5.0 in a Nutshell: The Definitive Reference (5th edition). Sebastopol, CA: O’Reilly Media.

Henry MultiCharts (2013, December 13). MultiCharts .NET FAQ - forum discussion. Retrieved on August 18, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=45848#p100797

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

Henry MultiCharts (2014b, August 29). TradeManager.TradingData.Orders… callbacks not firing - forum discussion. Retrieved on August 18, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=47086#p107774

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

MultiCharts Wiki (2013, May 6). Using Studies (PowerLanguage Editor). Retrieved on August 18, 2015, from https://www.multicharts.com/trading-software/index.php/Using_Studies_%28PowerLanguage_Editor%29

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.