Skip to content

How to Export C# Code

Once you have built your strategy, you can also generate and export the source code to use in a cTrader cBot, this has many benefits as it allows you to create an automated trading system that you can backtest, optimise and add new features by editing the code.

Paid version only

The option to create and export Microsoft C# code to import into cTrader to create cBots is only available in the paid version.

cTrader Risk Management

How to Generate?

When you visit this section after completing your strategy building, you need to click on the Generate button, and you will see the text in the window change and the number of code lines it has created.

Code Sections

The different code sections that are created by the Algo Strategy Building tool as shown below.

  • Namespaces with Using statements.
  • cBot header description as comments that include date, name & description.
  • cBot user parameter settings for general use and optimisation.
  • All indicator declarations.
  • All Market Data for multi-timeframe indicators.
  • All indicator declaration & constructions in the OnStart method.
  • OnTick method to manage trailing stop loss and break-evens.
  • OnBarClosed method to check for trade signals.
  • Custom methods for trade rules and submitting markets orders.
  • Custom methods for risk management.
  • Custom methods for trade alerts, email, telegram and popup windows.

No access rights required

The cBot will not require full access for any of the operations including sending Telegram alerts.

Import into cTrader

Once the code has been created you need to copy and paste it into cTrader, click on the Copy button to add to Windows clipboard. The next step is to open cTrader Automate (Algo) and create a new blank cBot. We created a new cBot and called it algo generated as shown below, you can remove all the code for the new cBot and paste the new code you copied from the strategy builder.

cTrader cBot Risk Management

Build Your cBot

When you have pasted the generated code into the cTrader code editor window, you can go ahead and build it, you can open the Trade Watch window at the bottom of the screen and click on the Log tab to see if the cBot was built successfully.

Once you have built your cBot you can now start it for automatic trading, send trade signals, and also run backtesting and optmisation of the settings.