Visual Studio

Editing cBots and Indicators in Visual Studio

Microsoft Visual Studio is a powerful IDE which can be used for development of cBots and Custom Indicators.

In order to edit cBots or Custom Indicators in Microsoft Visual Studio, you need to obtain Microsoft Visual Studio version 2012, 2013, 2015, or 2017. Express editions of Microsoft Visual Studio do not support Add-Ins and extensions, so cTrader Automate does not work with them. If you have a proper version of Microsoft Visual Studio installed, you can perform the “Edit in Visual Studio” command from the context menu of a cBot or a Custom Indicator:

If it is the first execution of the “Edit in Visual Studio” command, the VSIX installer will be launched:

The VSIX installer will install Visual Studio Extension which is required for the development of the cBots and Custom Indicators. In the VSIX Installer select the versions of Visual Studio which you are going to use for the cBots and Custom Indicators development. If you select several versions of Visual Studio, the latest version will be used on the “Edit in Visual Studio” command. After Visual Studio Extension is installed, Visual Studio will be opened:

After you make changes in the code of your cBot or Custom Indicator you need to apply those changes by executing the Build command:

After the build is finished, cTrader Automate will load a new .algo file. If you start your cBot, you will see that all your changes are applied:

All the instances of your cBot must be stopped when you perform the Build command from the Visual Studio. Otherwise, a new .algo file will not be loaded and the following warning will pop-up:

However, the Custom Indicators are reloaded on the fly and you don’t need to stop your Custom Indicators anyhow.

You can visit Visual Studio Resources to find out more information about Microsoft Visual Studio.

Debugging cBots and Indicators in Visual Studio

Microsoft Visual Studio is a powerful IDE which can be used for debugging your cBots or Custom Indicators. The following steps describe how to debug a cBot in Visual Studio, however, you can debug Custom Indicators in the same way.

Open your cBot in Visual Studio as described in the Editing section above. After Visual Studio is opened, you need to build your cBot in the “Debug” mode:

The debug impossible if you build your cBot in the “Release” mode or by using the Build command in cTrader Automate.

After you build your cBot in the “Debug” mode you can set the Breakpoints.

To set a Breakpoint:

In the source code editor, right-click a line of code where you want to set a breakpoint. In the context menu select Breakpoint and then Insert Breakpoint. After you place your breakpoints you need to attach Visual Studio to cTrader Automate process. Select “Attach to Process” in the “Debug” menu of Visual Studio.

In the Available Processes section of the Attach to process window select cTrader.exe process where you are going to run your cBot. Please note that attaching Visual Studio Debugger to cTrader process can interrupt the process and can affect the Advanced Protection, running cBots or other functionality. Please do not attach the Visual Studio Debugger to cTrader processes running under live accounts.

When done click Attach.

After that, you need to start or backtest your cBot. When execution of your cBot will reach the breakpoint Visual Studio will be switched to the break mode:

In the break mode you can hover the cursor over a variable and see its value in the tooltip:

You can observe values of all local variables in the Locals Window:

By using the Debug Toolbar you can Step in the break mode:

You can visit Visual Studio Resources to find out more information about Debugging in Visual Studio.

Useful links: