Restrictions on Parameter's attributes MinValue, MaxValue based on other Parameter values
Created at 23 Nov 2021, 12:16
Restrictions on Parameter's attributes MinValue, MaxValue based on other Parameter values
23 Nov 2021, 12:16
Dear cTrader,
I would like to constrain some bot parameters based on values passed to other parameter. For example, something like this:
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SomeBot : Robot
{
[Parameter("Param1", Group = "General", DefaultValue = 0.0)]
public double Param1 { get; set; }
[Parameter("Param2", Group = "General", DefaultValue = 1.0, MinValue = Param1)]
public double Param2 { get; set; }
}
}
Note above that `Param2` must have a value greater of equal to `Param1` because of `MinValue = Param1`.
What I do at the moment is to check validity in the `OnStart` method, and call `Stop()` if parameters do not have valid values.
Is there a better approach for this? I would like to avoid many invalid bot instantiations during optimization.
amusleh
23 Nov 2021, 13:42
Hi,
Right now you can't do such a thing, if you want to see this feature on cTrader you can open a thread for it on suggestions section of forum.
The simple way to verify or put that kind of limitations on parameters is to use the cBot OnStart or indicator initialize method, but if you want to do it on a more user friendly way you can use Windows Forms, get all your cBot or indicator parameters from a Windows form.
That way you can customize the form inputs based on your needs without using the cTrader parameters window.
The form will popup when user starts your cBot and it will have a button for Saving the user provided values, you can design it the way you want to.
@amusleh