Skip to content

Customisable parameters in plugins

Customisable parameters are user-editable fields whose values and settings are used in the operations of algorithms. These parameters allow users of a plugin to configure or control the behaviour of that plugin without needing to access or modify its source code.

Plugin customisable parameters in one minute

  • Customisable parameters significantly extend what plugins can achieve, transforming static plugin code into dynamic and configurable logic.
  • Plugin developers use customisable parameters in their code so that the end user can tailor the behaviour of the algo to their preferences.
  • Customisable parameters in plugins improve accessibility and bring plugin operations in line with the established capabilities of cBots and indicators.

You can access and edit the customsiable parameters of a plugin, if available, in the plugins section in settings.

Parameter declaration

Parameters are declared using the [Parameter] attribute placed above a public C# property. The plugin engine reads these attributes at initialisation and creates the parameter panel accordingly.

Note

Python plugins use customisable parameters declared in their .cs files.

The code below tells cTrader to display an API Key text field under an API & SYSTEM SETTINGS group, and whatever a user enters will be assigned to the ApiKey property before the plugin starts.

1
2
[Parameter("API Key", Group = "API & SYSTEM SETTINGS", DefaultValue = " ")]
public string ApiKey { get; set; }

Here is a code example that declares several customisable parameters:

 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
// API & SYSTEM SETTINGS
[Parameter("API Key", Group = "API & SYSTEM SETTINGS", DefaultValue = " ")]
public string ApiKey { get; set; }

[Parameter("Max Retries", Group = "API & SYSTEM SETTINGS", DefaultValue = 3)]
public int MaxRetries { get; set; }

[Parameter("Enable Logging", Group = "API & SYSTEM SETTINGS", DefaultValue = false)]
public bool EnableLogging { get; set; }

// RISK MANAGEMENT

[Parameter("Stop Loss (pips)", Group = "RISK MANAGEMENT", DefaultValue = 40.0, MinValue = 1.0, Step = 1.0)]
public double StopLossPips { get; set; }

[Parameter("Enable Trailing Stop", Group = "RISK MANAGEMENT", DefaultValue = true)]
public bool EnableTrailingStop { get; set; }

[Parameter("Stop Loss Trigger Method", Group = "RISK MANAGEMENT", DefaultValue = StopTriggerMethod.Trade)]
public StopTriggerMethod StopLossTrigger { get; set; }

// TRADE SETTINGS
[Parameter("Trade Direction", Group = "TRADE SETTINGS", DefaultValue = TradeType.Buy)]
public TradeType TradeDirection { get; set; }

// ORDER SETTINGS
[Parameter("Pending Order Type", Group = "ORDER SETTINGS", DefaultValue = PendingOrderType.Limit)]
public PendingOrderType OrderType { get; set; }

[Parameter("Expiry Time (HH:mm:ss)", Group = "ORDER SETTINGS", DefaultValue = "00:30:00")]
public string ExpiryTime { get; set; }

Parameter usage

Once parameters are defined, they can be used inside any method in the plugin code. In most cases, these values will be read inside OnStart() or used during operations.

In this code example, several previously-declared customisable parameters are used in print statements, which are executed when the plugin starts:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
protected override void OnStart()
{
    Print($"API Key: {ApiKey}");
    Print($"Max Retries: {MaxRetries}");
    Print($"Enable Logging: {EnableLogging}");

    Print($"Stop Loss (pips): {StopLossPips}");
    Print($"Enable Trailing Stop: {EnableTrailingStop}");
    Print($"Stop Loss Trigger Method: {StopLossTrigger}");

    Print($"Trade Direction: {TradeDirection}");

    Print($"Pending Order Type: {OrderType}");
    Print($"Expiry Time: {ExpiryTime}");
}

Image title