Parameter Types in cTrader Automate¶
In this article and its corresponding video we will demonstrate how you can declare and use parameters in your cBots and indicators. We will develop a simple indicator and we will show you how to configure its parameters from the cTrader UI. We will also explain what kind of parameters you can use in a cTrader cBot or indicator and illustrate how they are declared and used in your code.
Parameters are configurable values that can be set by the user when adding an indicator on a chart or before the execution of a cBot. Parameters are a useful feature for cBots and indicators as they allow you and the users of your algos to configure your algorithms without having to do any 'hard coding'.
Using Parameters in Indicators
You can use parameters in indicators to configure variables affecting indicator outputs such as the periods to be considered or the data source that needs to be used.
Using Parameters in cBots
In cBots, you can use parameters to configure variables such as stop loss or take profit levels or any other settings that affect execution.
As shown in this tutorial, cTrader supports eight parameter types.
Different parameter types are represented differently in the cTrader UI.
Creating a Simple Indicator With Parameters¶
To demonstrate how you can use parameters in custom indicators, we will create a new indicator and call it 'Standard Deviation'.
To calculate the standard deviation we first need to calculate the moving average of the price. Subsequently, we will declare the parameters needed for a moving average indicator starting with the moving average period.
Any public property that has one of the supported types can become an indicator parameter. To transform our
MaPeriod property into a parameter, all we have to do is add the required declaration.
Parameter attribute instructs cTrader to present this property as a parameter in the indicator parameters panel using the defined name (
As shown below, the
Parameter attribute also allows you to define some properties of the parameter such as the displayed name, the default value, the group in which this parameter will be placed in, the maximum and minimum values, as well as the step that the parameter will change when up and down arrows are pressed (only for numerical values).
We will now add the rest of the parameters needed for a moving average indicator. The
MaType parameter will help us determine the moving average type. It is an
enum that will appear as a dropdown menu in the cTrader UI.
Source parameter will give users the option to specify the data source for our moving average indicator. This parameter is of the
Now that the required parameters are declared we will define and initialise our moving average.
1 2 3 4 5 6
At this point, we are ready to implement the calculation for our standard deviation. The default code template already contains the
Output property which we can use to display the results of the calculation.
Last but not least, we will implement the standard deviation calculation in the
1 2 3 4 5 6 7 8 9 10 11 12 13
If add our indicator to a chart, we should see all our parameters in the 'Add instance' window.
Adding Additional Parameters¶
With our standard deviation completed, we can also add a horizontal line that will serve as a visual threshold for the indicator. For this purpose we will need to add some more parameters.
The first one will be a boolean parameter that will determine if our line will be shown or not.
LineLevel parameter will allow us to determine the price level at which the line should be drawn.
We will also add a parameter allowing for choosing the line colour.
With all the necessary parameters in place, we can write the code to draw the line on the chart to which our indicator is attached.
1 2 3 4
If we build the indicator again and add a new instance, we will be able to hide/show the line, move it up or down and select the colour of our choice as the line colour.
As shown in the below example, parameters can also be used to make sure that our indicator is only shown when added to charts for a specific timeframe.
Initialize() method we will check the time frame of the chart to which our indicator is attached. If it is not equal to the value of the
TF parameter, we will prevent the indicator from being displayed.
1 2 3 4 5 6 7 8 9 10 11 12
We hope that this guide has been helpful in understanding parameters and how they work in cTrader algo trading. To learn more about other features, consult our extensive technical documentation and subscribe to our YouTube channel to be alerted every time we publish a new video.