Dropdown Options for Parameters
Dropdown Options for Parameters
26 May 2015, 01:36
Is there a way to create a list of options to appear in a dropdown for parameters?
Like this?
Replies
deklin
28 May 2015, 03:59
This does not work. How can I do it?
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = "B")] public string[3] ABC {"A", "B", "C"} protected override void OnStart() { Print(ABC); } } }
@deklin
botmaster
28 May 2015, 16:32
RE:
deklin said:
This does not work. How can I do it?
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = "B")] public string[3] ABC {"A", "B", "C"} protected override void OnStart() { Print(ABC); } } }hmm.. I don't have the platform in front of me. Have you tried an Enum?
enum enmABC{ A, B, C}; [Parameter(DefaultValue = enmABC.A)] public enmABC ABC;
https://msdn.microsoft.com/en-us/library/sbbt4032.aspx
@botmaster
Spotware
12 Jun 2015, 12:44
Dear Traders,
Currently the enum parameters are not supported.
We plan to support them in the future. Please vote for this idea: http://vote.spotware.com/forums/229166-ideas-and-suggestions-for-ctrader-and-calgo/suggestions/5502949-custom-parameters
@Spotware
snowchilli
23 Jan 2020, 07:45
RE: RE:
botmaster said:
enum enmABC{ A, B, C}; [Parameter(DefaultValue = enmABC.A)] public enmABC ABC;
gives this error
Error CS0052: Inconsistent accessibility: field type 'cAlgo.Robots.NewcBot.enmABC' is less accessible than field 'cAlgo.Robots.NewcBot.ABC'
Solution:
public enum enmABC{ A, B, C};
[Parameter(DefaultValue = enmABC.A)]
public enmABC ABC;
However, the above does not show as a parameter for a cBot in cTrader 3.6
What change is needed to make the parameter show as such, when e.g. an instance is added to the bot?
Ideally with a label and group title for the parameter, perhaps as such...
public enum enmABC{ A, B, C};
[Parameter("Alphabet", Group="Wordcraft", DefaultValue = enmABC.A)]
public enmABC ABC;
@snowchilli
PanagiotisCharalampous
23 Jan 2020, 08:32
Hi snowchilli,
You did not add a getter and a setter. See below the correct way to do this
[Parameter(DefaultValue = enmABC.B)]
public enmABC ABC { get; set; }
Best Regards,
Panagiotis
@PanagiotisCharalampous
snowchilli
24 Jan 2020, 03:38
RE:
PanagiotisCharalampous said:
Hi snowchilli,
You did not add a getter and a setter. See below the correct way to do this
[Parameter(DefaultValue = enmABC.B)] public enmABC ABC { get; set; }
Best Regards,
Panagiotis
Thank you for the correction.
The pre-correction code had built without errors or warnings in cTrader 3.6.
Would have been nice, if cTrader had issued an alert.
@snowchilli
PanagiotisCharalampous
24 Jan 2020, 08:35
Hi snowchilli,
There is no problem with the code. The errors or warnings that you get come from the C# compiler, not from cTrader. The code is a valid C# code. But instead of a property, you declared a variable.
Best Regards,
Panagiotis
@PanagiotisCharalampous
patzoot@gmail.com
30 Dec 2020, 21:33
RE:
PanagiotisCharalampous said:
Hi snowchilli,
You did not add a getter and a setter. See below the correct way to do this
[Parameter(DefaultValue = enmABC.B)] public enmABC ABC { get; set; }
Best Regards,
Panagiotis
Hi,
Just to confirm; there hasn't been any introduction since the last thread for the option of a dropdown menu to change the color of items such as lines? I'm attempting (with my limited programming skills) to make use of the enum function to create a list of colors as a means to change the colors of items drawn but seem to get stuck where the identifier for enmABC is to be placed. I'd want it to use the color choice the user picked as an identifier. Any suggestions as to how I may correct this or even an alternative method?
[Parameter("Sell Point Colour", DefaultValue = enmABC.DarkGray, Group = "Colour Settings")]
public enmABC SellPC { get; set; }
public enum enmABC
{
DarkOrchid,
DarkGray,
MintCream
}
string colour = enmABC.().ToString();
double z = AverageEntryPrice(TradeType.Sell);
Chart.DrawHorizontalLine("spoint", z, Color.FromName(colour), 2, LineStyle.Solid);
@patzoot@gmail.com
PanagiotisCharalampous
04 Jan 2021, 08:46
Hi there,
Here is a correct example
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
[Parameter("Sell Point Colour", DefaultValue = enmABC.Yellow, Group = "Colour Settings")]
public enmABC SellPC { get; set; }
public enum enmABC
{
Blue,
Yellow,
Orange
}
protected override void OnStart()
{
string colour = SellPC.ToString();
Chart.DrawHorizontalLine("spoint", Symbol.Ask, Color.FromName(colour), 2, LineStyle.Solid);
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
Best Regards,
Panagiotis
@PanagiotisCharalampous
botmaster
27 May 2015, 23:26 ( Updated at: 21 Dec 2023, 09:20 )
RE:
deklin said:
Have you tried inline arrays?
@botmaster