Skip to content

Thread Safety

How cTrader Runs Algos

cTrader runs each indicator/cBot on a separate sub-process isolated from the cTrader Windows main process. This means that all new instances of indicators and cBots run on separate processes.

This approach allows cTrader to impose code access restrictions on separate processes, improving safety and stability.

Furthermore, separate indicator/cBot processes do not share their resources with the main cTrader Windows process. If something goes wrong with an indicator or a cBot, the underlying issue will not have an effect on cTrader itself.

Methods and Thread Safety

Only a few methods in the API are thread-safe, meaning you can call them from any thread. Everything else should run on the cBot/indicator main thread.

Executing Code on the Main Thread

To run something on the main thread of a cBot/indicator, use the BeginInvokeOnMainThread() method. It accepts an action delegate and you can call it from any running thread.

Sharing Data Between Instances

As each indicator/cBot instance runs on a single child process, you can use static properties or fields to share data between the different instances of the same cBots/indicators.