Skip to content

Creating and Running a cBot

Creating a cBot

cTrader Automate allows building cBots that trade automatically based on the technical analysis signals.

Select the cBots tab from the left-hand side of the platform. You’ll see the complete list of all available cBots. You can search the cBots by their names with the advanced search by the cBots name to the upper left.

1. To create a new cBot click New to the upper right of the cBots tab. The new cBot will appear to the bottom of the cBots list and its code will be displayed in the source code editor to the right. You can rename your cBot at any time by typing in the new name or by right-clicking the cBot preview and selecting Rename from the drop-down menu. Alternatively, select the cBot and press F2.

Image title

The cBot will be created with the code from the default code template:

  using System;
  using System.Linq;
  using cAlgo.API;
  using cAlgo.API.Indicators;
  using cAlgo.API.Internals;
  using cAlgo.Indicators;

  namespace cAlgo.Robots
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
            // Put your initialization logic here

        protected override void OnTick()
            // Put your core logic here

        protected override void OnStop()
            // Put your deinitialization logic here

Note that the cBot attribute (Robot) with the optional properties such as TimeZone and AccessRights, precedes the cBot class (NewcBot) declaration.

The OnStart method is called upon initialization of the cBot. The OnTick method is called each time there is a new tick and the OnStop method is called when the cBot stops.

There are two methods that can be called by the Robots and contain the main logic of your trading strategy - the OnBar() and the OnTick() method.

By placing your code-logic inside the OnBar() method, your robot is getting called once, at the open of every bar.

By placing your code-logic inside the OnTick() method, your robot is getting called once, on every incoming tick. The OnTick() method is considered CPU intensive.

2. Add your cBot code to the code editor. You can edit your cBot using the code examples from the API Reference Explorer to the right or just copy and paste your code from another source.

Image title

Note that you can find the examples of working cBots in the cBot Code Samples section by clicking Find more cBots on to the bottom of the cBots list.

Image title

Save your code by clicking Save to the upper left of the editor or pressing Ctrl+S on your keyboard. Alternatively, right-click on your cBot in the cBots tab and select Save from the drop-down menu.

Image title

3. Before you can use your algorithm to trade, you need to convert it into a working cBot. To build a cBot, click the Build icon to the top of the code editor or in the cBot menu.

If the build succeeded you will be notified with the respective message in the Build Result viewer.

Image title

If the build fails, the error(s) description will be printed. Clicking on an error description in the Build Result viewer will show you the exact place in the code where this error occurs.

Try fixing the code and build your cBot again.

Image title

Note that if you see a red dot in the Build button, it means that the changes were made to the code since the last build. Also, an asterisk will appear next to the cBot name.

Image title

Running a cBot

Now your cBot is ready. To start using it, create a new instance of your cBot - click the plus icon (+) and select a Symbol to trade from the drop-down list or using the advanced search.

Image title

Alternatively, select Add Instance from the cBot Quick Menu by clicking on the arrow or right-clicking on a cBot. In this case, an instance with EURUSD symbol by default will be created.

Note that you can change the symbol for an instance as long as your cBot instance is not running.

Image title

The new instance of the cBot will be added below and its details will expand to the right automatically.

To start a cBot click the Play button to the upper right of your cBot instance preview. Before you start your cBot, you can select a symbol to trade and set the cBot Parameters.

Note that only parameters that you have enabled for your cBot will be available for setting.

Image title

Alternatively, click the Play button to the top of the cBot chart to the right.

Image title

A cBot cannot be built and no settings can be changed when its instance is running.

To stop a cBot click the Stop button to the upper right of the cBot instance preview or to the top of the cBot chart to the right.

Image title

Click Stop All to the upper right of the cBots list to stop all the running cBot instances at a time.

Image title

cBot Parameters

Each cBot depending of its type has a set of configurable parameters that can be not only configured in the cBots code directly, but also in the UI.

Click the cog icon in the cBot instance tab to open its settings.

Image title

Alternatively, you can find the cBot Parameter panel directly under the chart.

Image title

Last update: June 26, 2022