Skip to content

Introduction to trading bots in cTrader

Traders often build trading bots for algorithmic trading, and this article outlines the steps to create an algo for an automated strategy.

cBots are trading bots or automated programs that you can customise to perform trading operations on your behalf. These robots can analyse market conditions, execute trades and manage risk according to rules you define.

In cTrader Windows and Mac, you can develop cBots using either C# or Python, allowing you to work in the programming language that you are most comfortable with. Both languages give you access to the same rich trading API, enabling you to build, test and refine automated strategies with ease.

cBot lifecycle

The flowchart below outlines the key steps from creating a trading bot to starting it:

graph TB
  A([Create a cBot]) ==> B([Save and build the cBot]);
  B ==> C([Add an instance]);
  C ==> D([Start the instance]);

  %% Optional branches with return connections
  A -.-> O([Edit the cBot code]) -.-> B;
  C -.-> P1([Backtest the cBot]);
  P1 -.->  P2([Optimise the cBot]) -.-> D;
  P1 -.-> D;

After you create a cBot, you need to save and build it to validate its project code. Upon a successful build, you can proceed to start an instance of the cBot. Optionally, you can edit the cBot code before building it, or backtest and optimise it after adding an instance to improve performance.

The table below outlines the possible actions for trading bots in cTrader applications:

Action cTrader Windows cTrader Mac cTrader Web cTrader Mobile
Create Yes Yes No No
Edit Yes Yes No No
Save and build Yes Yes No No
Add and manage instance Yes (cloud and local) Yes (cloud and local) Yes (cloud) Yes (cloud)
Backtest Yes Yes No No
Optimise Yes Yes No No
Start Yes (in Cloud and locally) Yes (in Cloud and locally) Yes (in Cloud) Yes (in Cloud)

How trading bots operate

In technical terms, a cBot is a C# or Python class with customisable parameters and methods. By modifying a bot's code, you can fully define its behaviour, including what the robot does on startup, on encountering certain market conditions and on being stopped.

To make a cBot perform trading operations, you need to start an instance of that cBot. Think of an instance as a reference to a specific cBot object. Each instance operates independently, meaning you can run the same cBot across multiple symbols and periods simultaneously.

In cTrader Windows or Mac, you can run trading bots on historical market data to see whether they achieve the desired results, a process called backtesting. By repeating backtests with different settings, you can discover the most effective parameters and settings for a given trading robot, a process known as optimisation.

Beyond trading operations, cBots can interact with files, process external data or connect to custom workflows, making them useful for advanced automation scenarios.

Image title