Strategy Dev: Using Parameters

Estimated reading time: 1 min

Defining Parameters

As a strategy developer, you can define parameters that the user will have to provide for adjusting the strategy. This requires implementing  the onSendParam method and using one of the AddParameter helper to declare the parameter. Depending on the type of parameters there are different methods, four types of parameters are available:
Numeric addNumericParameter
Bool addBooleanParameter
String addStringParameter
List addListParameter
Once a parameter is declared, it will be available in the UI and the user will have have the possibility to define the desired value.   Strategy_Parameters   The AddParameter methods take the following parameters:
  • Parameter name (string)
  • Default value (matching the type of parameter)
  • List of options (only for List)
Below you can find an example of each type of parameter. Exemple
_mt.addStringParameter(‘Parameter Name’, ‘Blue’) _mt.addNumericParameter(‘Parameter Name’, 1000) _mt.addListParameter(SETTING_MATYPE_LONG, ‘EMA’, ‘NONE,SMA,EMA,WMA,DEMA,TEMA,TRIMA,KAMA,MAMA,FAMA,HMA’)

AddNumericParameter

AddNumericParameter is used for letting the user define a numeric value (Integer or Float). It takes 2 parameters, the name of the parameter and the default value.
_mt.addNumericParameter(‘My Value’, 1000)

AddBooleanParameter

AddBooleanParameter  is used for letting the user define a numeric boolean value (True or False). It takes 2 parameters, the name of the parameter and the default value.
_mt.addBooleanParameter(‘State’, False)

AddStringParameter

AddStringParameter  is used for letting the user define a litteral value (String). It takes 2 parameters, the name of the parameter and the default value.
_mt.addStringParameter(‘Color’, ‘Blue’)

AddListParameter

AddListParameter  is used for letting the user chose a value from a list. This one takes 3 parameters, on top of the name of the parameter and the default value, it also requires the list of possible values separated by ‘,‘.
_mt.addListParameter(‘Preset’, ‘EMA 10/30’, ‘EMA 7/21,EMA 10/30,EMA 50/200’)
 

Retrieving and using Parameters

After declaring parameters that the user can fill in, it’s required to retrieve the value which he has defined. There is another helper located in the MachinaTraderCommon library for this purpose and it is called GetParameter.

GetParameter

The parameters which are defined by the strategy and set by the end user can be retrieved at any time by using the _mt.getParameter function. getParameter takes a single parameter which corresponds to the parameter which has been defined in the AddParameter helper:
userColor = str(_mt.GetParameter(‘Color’))
Was this article helpful?
Dislike 0
Views: 96