Restrictions on Parameter's attributes MinValue, MaxValue based on other Parameter values

Created at 23 Nov 2021, 12:16
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AM

amml

Joined 27.04.2021

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. 


@amml
Replies

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

amml
23 Nov 2021, 14:19

Thanks, amusleh. Yes, I'm using OnStart to verify validity. I like your suggestion of implementing my own UI using Windows form and resolving this limitation from there. Many thanks.


@amml