Clickalgo Knowledge Center
Return to Website

Reference a cTrader cBot Assembly DLL

An assembly or DLL is nothing more than a library of common functionality that you import into your project so you do not have to re-invent the wheel, the .NET framework is made up of many assemblies ranging from database connectivity to complex mathematical equations. Most traders will use it to simply reference 3rd party indicators. In more simple terms: A chunk of (precompiled) code that can be executed by the .NET runtime environment. A .NET program consists of one or more assemblies. 

The following assumes that you are using the development environment that is integrated into cTrader.

 

How to Reference a Custom Indicator

You need to make sure that you are in the Automate panel of cTrader where you create your cBot template and to add a reference to the external assembly just follow these steps.

  • Right-click your mouse on the cBot and choose from the available options Manage References

 

ctrader add dll reference

 

The next screen you will see will be the Library window as shown below, on the left, there are 3 options.

 

Indicators

This is where you will select the 3rd party indicators you wish to you with your cBot. if they are greyed out then you will not be able to reference them as they do not contain any source code, you can only reference indicators that have the source code included.

 

.NET Framework

Choose this option if you wish to use an assembly available in the .NET framework, a common one is a System.Windows.Forms for displaying popup-windows for messages.

 

Libraries

This option will allow you to navigate your filesystem and select a custom assembly to include, this could be one that you made yourself or any other.

 

cTrader Reference a DLL

 

Declaring New Assembly In the cBot Code

Now that your assembly is attached to your cBot or indicator you will need to import the namespace into the code so that you can start calling methods and properties from inside the referenced assembly. this might be tricky if you do not know the namespace and the best method to find the namespace is to use the Microsoft Visual Studio editor and when you start typing the libraries name IntelliSense will show you the complete namespace to include.

Tip

Probably the best method to import the namespace after the assembly has been attached to the project is to use Visual Studio and start writing the client code as shown below for opening a message box, if the namespace has not been declared then it will highlight with a red line under the method, just move your mouse over the red line and you will see a yellow lightbulb, click on this light bulb and you will see a list of suggestions, click on the first option called using System.Windows.Forms to automatically import your namespace.

 

ctrader import dll tip

 

New to Microsoft Visual Studio?

If you have never used Microsoft Visual Studio before, just follow the link below for an introduction to help you get started.