AH
Enum fuction creation
25 Dec 2023, 10:00
public enum CustomType
{
Low,
Medium,
High
}
[Parameter("P1", Group = "new type", DefaultValue = Low)]
public CustomType P1 { get; set; }
switch (P1 )
{
case CustomType
.Low:
fpsvsmasS_val = FPvsMAsVarsB ;
break;
case CustomType
.Medium:
fpsvsmasS_val = FPvsMAsVarsS;
break;
case CustomType
.High
:
fpsvsmasS_val = FPvsMAsVarsS;
break;
}
Hello guys, I have a custom enum list which I will use several times on my code,
Is there a way to set that enum list on a function to reduce lines of my code?
Thanks in advanced
ctrader.guru
27 Dec 2023, 08:32
Try this approach
using cAlgo.API; namespace cAlgo.Robots { [Robot(AccessRights = AccessRights.None)] public class Test : Robot { public enum CustomType { Low, Medium, High } [Parameter("P1", Group = "new type", DefaultValue = CustomType.Low)] public CustomType P1 { get; set; } private double fpsvsmasS_val { get { switch (P1) { case CustomType.Low: return FPvsMAsVarsB; case CustomType.Medium: return FPvsMAsVarsS; case CustomType.High: return FPvsMAsVarsS; } return 0; } } private double FPvsMAsVarsB = 10; private double FPvsMAsVarsS = 20; protected override void OnStart() { Print("Value of 'fpsvsmasS_val' : {0}", fpsvsmasS_val); Stop(); } protected override void OnTick() { } protected override void OnStop() { } } }
@ctrader.guru