Currency converter
In algo trading, giving cBots and indicators the ability to autonomously convert currencies using current market rates is essential. In this API guide, we cover how this feature is implemented in cTrader.
Currency conversion in one minute!
- The
Convert (double value, Asset from, Asset toandConvert(double value, string from, string to))methods return the exact conversion rate between the specified assets or the assets with the specified names. Access them via the newAssetConverterproperty of theAlgoclass. - The
Assetclass includes its ownConvert(Asset to, double value)andConvert(string to, double value)methods that can be easily invoked from anyAssetobject. - When backtesting, cTrader will automatically use historical conversion rates. This means that you can always expect historically accurate results and fully evaluate the performance of your cBots.
How currency conversion works
The IAssetConverter interface in the cAlgo.API.Internals namespace contains the Convert() method that has the following overloads:
double Convert(double value, Asset from, Asset to)- converts the specified value from thefromasset to thetoasset.double Convert(double value, string from, string to)- converts the specified value from the asset the name of which matches thefromstring to the asset the name of which matches thetostring.
The Algo class now includes the AssetConverter property of the IAssetConverter type. You can access the two methods above by typing the following.
1 | |
The Asset class also has its own Convert() methods with the following overloads:
double Convert(Asset to, double value)- converts the specified value from the asset from which this method is called to thetoasset.double Convert(string to, double value)- converts the specified value from the asset from which this method is called to the asset the name of which matches thetostring.
Consider the example below in which our cBot converts GBP into JPY and then executes a new market order using the calculated value as the order volume.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
If we take a look at the log, we can see that our cBot behaves as expected. At the time when the instance was started, the bid price for GBPJPY equaled 159.619.

Currency conversion in backtesting
cTrader fully supports historical conversion rates in backtesting.
This means that, when you backtest a cBot that uses any of the methods described above, conversion calculations will be performed using historically accurate data rather than the current exchange rates between the specified assets. This feature ensures that the results of backtesting and optimisation are as precise as possible given past market conditions.
Note that cTrader can build accurate conversion chains using potentially unlimited trading instruments. As a result, even if your account deposit currency differs from the base or quote assets of the symbol on which you would like to perform a backtest, cTrader will handle all the necessary calculations to provide you with precise backtesting results.
In summary, conversion rates constitute another valuable tool for making sure that your cBots and indicators perform exactly as expected. As cTrader supports the use of historical data when converting assets in backtesting, you can be sure that all backtesting and optimisation results are historically accurate.