Skip to content

Referencing .NET Libraries/Packages

Referencing Local .NET Libraries (DLL Files)

cTrader Automate API allows users to reference .NET libraries from cBots and Custom Indicators.

In order to add a reference to .NET library you need to open Reference Manager window.

You can open Reference Manager window by clicking “Manage References” button in the top of cAlgo editor or by executing “Manage References” command from context menu of your cBot or Custom Indicator.

Image title

OR

Image title

In Reference Manager open Libraries page and click on the Browse button:

Image title

In open file dialog you need to select a .NET dll and click on the Open button.

Image title

Click on the Apply button in Reference Manager to apply the changes.

Image title

Then you need to import namespaces from the Library. Example:

Image title

Finally, you can use classes from the Library in your code:

Image title

Referencing Other Custom Indicators

You can reference and use other cTrader custom indicators on your cBots/Indicators.

For referencing a custom indicator you can use the cTrader Automate Reference manager window or reference the indicator project file from your cTrader indicator/cBot project file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="cTrader.Automate" Version="1.*" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\..\Indicators\Another Indicator\Another Indicator\Another Indicator.csproj" />
  </ItemGroup>
</Project>

The recommend approach is to use the cTrader Automate reference manager window as it shows all custom installed indicators on a separate tab:

Image title

Once you referenced an indicator you can use it by using Indicators.GetIndicator method:

1
2
3
4
5
6
7
8
private MyCustomIndicatorClass _customIndicator;

protected override void OnStart()
{
    // You have to pass all indicator parameters in order they are
    // defined to GetIndicator method
    _customIndicator = Indicators.GetIndicator();
}

Using Nuget packages

You can use the rich library of .NET Nuget packages on your indicators/cBots, you can install a Nuget package on your cTrader indicators/cBots like any other .NET project.

You can use Nuget package manger install command, Visual Studio Nuget manager GUI, or .NET CLI.

Referencing with Visual Studio

You can also use Visual Studio for referencing other .NET libraries or Nuget packages.


Last update: June 26, 2022

Comments