cTrader Pro
Import the C# cBot into cTrader Automate, build it yourself, run a backtest, and what differs from MetaTrader 5.
This feature is part of Pro.
cTrader exports a C# cBot (.cs) for cTrader Automate. It can export 106 of 119 parts. It does not export some instruments. Getting the source is part of Pro.
Build the cBot
-
In the Builder toolbar, choose cTrader (C#).

cTrader (C#) selected in the Builder toolbar. -
Click Download .cs. The file is saved as
EA_Builder.cs. -
In cTrader, open the Automate tab and create a new cBot.
-
Replace the code of the new cBot with the whole content of the file.
-
Click Build. The Builder does not compile it. The cBot is built on your computer.
The class is named EABuilderStrategy, in the namespace EABuilder. It is written for the cTrader Automate API (the cAlgo.API namespace).
How the cBot decides
OnBar runs when a new bar starts, so the bar that just closed is the latest closed bar. The decision uses only closed bars. It is sent as a market order, which the platform fills at the first tick of the new bar, about the next bar open.
Stop loss and take profit are set on the position right after the fill, as absolute prices that the server holds. Limit and stop orders can still fill inside a bar.
Gaps
The code does not model gaps. A market order is filled by the platform at the first tick of the new bar, at whatever price the platform has then. The price can differ from the previous close after a weekend or news gap, so the entry price and the result can differ from the Miner. When a bar opened beyond a stop, cTrader closed the position at the opening price in all 122 such trades of the comparison runs. The MetaTrader 5 tester closed at the stop level. The comparison runs behind Match check counted gap opens as one of the causes of a difference.
Inputs
| Setting | What it does | Values |
|---|---|---|
TZ | The offset in hours from UTC. Server time is the bar open time plus TZ. | Number, default 0 |
LabelPrefix | The label on this cBot’s orders, so it only manages its own positions. | Text, default EAB |
LotSize | Lot size, or the inputs of the money-management part. The cBot turns lots into volume with the symbol’s lot size, rounds down to the volume step and keeps it within the minimum and maximum. | Number, the lot size of the strategy (0.01 if it has none) |
| One input per setting of a part | For example the periods of an indicator or the stop loss in pips. | Set in the Builder, editable in cTrader |
Run a backtest
- In Automate, select the cBot and open the Backtesting tab.
- Choose the symbol and timeframe named on the
Checked under:line at the top of the file. - Choose a date range and the data source, then start it.
Expect the numbers to differ from the Miner, because spread, commission and swap are what the cTrader account and the tester data charge. The code does not model them. The spread filter reads the live spread.
Results are an approximation of past data. They do not predict future results.
Differences from MetaTrader 5
| Topic | In cTrader |
|---|---|
| Account type | A netting account merges same-side orders into one position and nets opposite orders. The MetaTrader 5 export assumes a hedging account. Test on the account type you will trade. |
| Trailing stop and break-even | Evaluated at the bar close. MetaTrader 5 does it on every tick. |
| OCO orders | cTrader Automate has no OCO order that was found in its documentation. The second leg is cancelled at the next bar, and both legs can fill inside the same bar. |
| Volume | Volume series use tick volume, which may not match MetaTrader volumes. |
| Indicator start values | EMA and RMA start values differ slightly from MetaTrader. The values converge. |
| Minimum stop distance | The code does not adjust SL and TP to the broker’s limit. |
Instruments that are not exported
cTrader does not export these instruments, because the platform decides their pip size and the Builder does not guess it. The export is refused with a message. MetaTrader 5 and MetaTrader 4 export them.
| Instrument | Symbol in the Miner |
|---|---|
| Gold | XAUUSD |
| Silver | XAGUSD |
| WTI crude oil | LIGHTCMDUSD |
| Brent crude oil | BRENTCMDUSD |
| S&P 500 index | USA500IDXUSD |
| Nasdaq 100 index | USATECHIDXUSD |
| Dow Jones index | USA30IDXUSD |
| DAX index | DEUIDXEUR |
| FTSE 100 index | GBRIDXGBP |
| Nikkei 225 index | JPNIDXJPY |
Match status
The header of the .cs file reads Match with the platform tester: not verified, and no match mark is shown for cTrader exports today. Comparison runs on cTrader exist, and most of them matched. See Match check.
If the build fails
- Check that you replaced the whole code of a new cBot and did not paste inside the old class.
- Read the first message in the build output.
- If the export was refused, no file was saved. See Blocks that can’t be exported.
Next steps
- Read Blocks that can’t be exported for the blocked parts.
- Read Match check for the comparison.
- Go back to the Export overview.