Compile and build algorithms in cTrader
You can use two types of compilers when compiling/building cTrader algos:
- Embedded compiler
- .NET SDK compiler
By default, cTrader uses the embedded compiler but we recommend you change it to the .NET SDK compiler if you have one installed on your local machine.
Compiling CSPROJ files and retrieving cBots
cTrader Algo allows you to generate and save algorithms by compiling .csproj files. Use the following code to execute the operation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
If you set AccessRights to None, you must specify paths to directories inside the algo data folder. This configuration means algos are not allowed to compile files outside of their data folders.
If you set AccessRights to FullAccess, you can specify the path to any directory or location for both the .csproj file and generated algorithm.
If you intend to use a relative file path, the base directory must exist along this path: ..Documents\Algo\Data\{Algo type}\{Algo name}.
After you start the cBot locally, the algorithm will be saved in the specified directory.
Switching compilers
To change to a different compiler, click Settings in the bottom-left corner of the UI to open the settings window, then switch to the Algo tab.

Open the Select compiler dropdown and choose a suitable compiler from the available options.
Embedded compiler
The embedded compiler is built-in to the cTrader Windows platform. In comparison to the .NET SDK compiler, it has limited features. For instance, the embedded compiler does not support any third-party .NET packages and frameworks such as WinForms and WPF.
.NET SDK compiler
Using the .NET SDK compiler is strongly recommended for large projects or extensions that use third-party .NET libraries. The .NET SDK compiler also supports additional features such as build parameters.
The Select compiler menu enables choosing any .NET SDK compiler you have installed on your local machine. If no versions of the .NET SDK are installed, you can always click the Install .NET SDK button to be taken to the download page for the latest stable release.
Parameters
cTrader offers customisable parameters that you can specify to when using .NET CLI when building your cBots/indicators in external IDEs. They are defined below:
| Name | Default value | Description |
|---|---|---|
| AlgoName | $(MSBuildProjectName) | Specifies the .algo file name.This property does not affect the AssemblyName. |
| AlgoBuild | True | Enables building .algo files. |
| AlgoPublish | True | Enables copying .algo files to the MyDocuments directory of the current user after a successful build. |
| IncludeSource | False | Includes the source directory to the target .algo file. |
| IncludeSymbols | False (Release)True (Debug) | Includes the debug symbols to the target .algo file. |
Handling an additional error
If you reference the cTrader.Automate NuGet package in your class library project that does not contain any cTrader algo classes in it (such as Robot for a cBot), you will encounter the "Assembly must contain algo type" error when you try to build the project. This error arises since the AlgoBuild parameter equals True by default.
To fix the issue, simply set AlgoBuild to False in your .NET project file as seen in the example below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AlgoBuild>false</AlgoBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="1.*-*" />
</ItemGroup>
</Project>