As C# is a strongly typed language, it is necessary to specify data types when declaring variables and class properties in cBots, indicators, and plugins. In contrast, Python is dynamically typed, so variable types are inferred automatically. However, when developing cBots using the cTrader API, the same conceptual types are preserved for consistency between both languages.
cTrader Algo API does not allow all data types to be used as customisable parameters, and this is why it is essential for algorithm developers to understand and navigate across the supported types carefully.
Note
Python cBots, indicators and plugins use customisable parameters declared in their .cs files.
Parameter use cases and UI
cTrader supports only these parameter types with the key use cases and related UI elements reflected in the table below.
C#
Python
Use cases
UI element
int
int
Order volume, number of bars, number of periods, etc.
Number input field (with stepper)
double
float
Price value, order volume, etc.
Number input field (with stepper)
string
str
Custom message, position label, etc.
Text input field
bool
bool
Protection mechanisms, allow trading, allow email, etc.
Dropdown yes/no
DataSeries
api.DataSeries
Source of market prices, etc.
Dropdown list
TimeFrame
api.TimeFrame
Chosen time frame, etc.
Period selector
enum
Enum
Chart drawings alignment, individual risk levels, etc.
Dropdown list
Color
Color
Chart drawings, colour of technical analysis means, custom elements, etc.
Colour picker
DateTime
DateTime
Getting strongly typed date and time in the algo time zone
Date and time picker
DateOnly
DateOnly
Getting strongly typed date
Date picker
TimeSpan
TimeSpan
Getting strongly typed time interval or time of the day
Time picker
Symbol
Symbol
Getting strongly typed single symbol
Symbol picker
Symbol[]
Symbol[]
Getting strongly typed multiple symbols in an array
Multi-symbol picker
Enum[]
Enum[]
Getting strongly typed multiple values of an Enum type in an array
Multi-enum value picker
TimeFrame[]
TimeFrame[]
Getting strongly typed multiple TimeFrame values in an array
Multi-period picker
Warning
You may not be able to use some of the parameter types above if you are using an older version of cTrader or Algo API.
For example, the cTrader UI reflects C#'s bool, double, int and Python's bool, float, int types as follows.
The next three examples show C#'s DataSeries, custom enum, string and Python's api.DataSeries, Enum, str data types (for which we also provide the full code in this guide).
As shown below, C#'s Color and Python's Color parameter type is represented by a colour picker.
Finally, the UI of C#'s TimeFrame and Python's api.TimeFrame data mirrors the period options available in trading charts within the Trade application.
cBot examples
The position label is a C#'s string and Python's str parameter in the following cBot.
In the example below, C#'s double and Python's float data type serves as a parameter to input the order volume in lots. The cBot executes a buy market order after three consecutive red bars.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingcAlgo.API;usingcAlgo.API.Collections;usingcAlgo.API.Indicators;usingcAlgo.API.Internals;namespacecAlgo{[Indicator(AccessRights = AccessRights.None)]publicclassNewIndicator4:Indicator{privateBars_hourlyTimeFrameBars;privateBars_targetTimeFrameBars;[Parameter("Chosen Time Frame")]publicTimeFrameTargetTimeFrame{get;set;}[Output("Main")]publicIndicatorDataSeriesResult{get;set;}protectedoverridevoidInitialize(){_hourlyTimeFrameBars=MarketData.GetBars(TimeFrame.Hour);_targetTimeFrameBars=MarketData.GetBars(TargetTimeFrame);}publicoverridevoidCalculate(intindex){Result[index]=_hourlyTimeFrameBars.HighPrices[index]-_targetTimeFrameBars.HighPrices[index];}}}
There is a playful (colour-blind test) indicator that offers enum colour vision options (for example, normal, colour-blind, and greyscale) for users to determine the colour of a horizontal line drawn on the chart.
To summarise, by choosing the correct data type for the declared variables and class properties, you will be able to create cBots and indicators that can handle even non-standard tasks.