Simple On/Off switch as ParameterAttribute

Created at 31 Mar 2022, 06:28
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!
AN

AnthonyY

Joined 16.01.2022

Simple On/Off switch as ParameterAttribute
31 Mar 2022, 06:28


Hi

I am trying to make a simple On/Of switch drop down for cBot Parameters so when I choose one of the choices not having to type it will start executing orders but for testing purposes this piece of code show what I am after..

VS Code gives no error while cTrader gives Error CT0111: Parameter type ..... not supported pointing to EnuOnOff class

here is the code:

public class EnuOnOff

        {

            enum OnOff

            {

                Off,

                On

            }

        }

        [Parameter("Engage?", DefaultValue = "(On/Off?", Group = "OnOff")]

        public EnuOnOff OnOff { get; set; }

Error occurred after implemented this part:

 if (OnOff.ToString() != "Off")

            {

                PlaceStopLimitOrder(TradeType.Buy, Symbol.Name, riskVar, TargetTp, 30);

            }

 

Thank you!

 


@AnthonyY
Replies

amusleh
31 Mar 2022, 10:09

Hi,

To create multi option parameters you can use .NET enums, here is an example:

using cAlgo.API;

namespace NewcBot
{
    [Robot(AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter("Switch", DefaultValue = Switch.On)]
        public Switch SwitchParameter { get; set; }

        protected override void OnStart()
        {
            if (SwitchParameter == Switch.On)
            {
                Print("Switch in On");
            }
            else
            {
                Print("Switch in Off");
            }
        }


    }

    public enum Switch
    {
        On,
        Off
    }
}

 


@amusleh

AnthonyY
31 Mar 2022, 17:09

RE:

amusleh said:

Hi,

To create multi option parameters you can use .NET enums, here is an example:

using cAlgo.API;

namespace NewcBot
{
    [Robot(AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter("Switch", DefaultValue = Switch.On)]
        public Switch SwitchParameter { get; set; }

        protected override void OnStart()
        {
            if (SwitchParameter == Switch.On)
            {
                Print("Switch in On");
            }
            else
            {
                Print("Switch in Off");
            }
        }


    }

    public enum Switch
    {
        On,
        Off
    }
}

 

Thank you! That worked perfect, take care!


@AnthonyY