Enum rename Label string
unknown
csharp
a year ago
6.6 kB
17
Indexable
public enum MyEnum
{
A,
B,
C,
X,
Y,
Z
}
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class MyXConverterStrat : Strategy
{
private string xX, yY;
private string Btn1Lbl, Btn2Lbl;
private int _button1Ticks, _button2Ticks;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
...
st1EnumVar = MyEnum.X;
nd2EnumVar = MyEnum.B;
foreach (string value in Enum.GetNames(typeof(MyEnum)))
{
MyEnum enumValue = (MyEnum)Enum.Parse(typeof(MyEnum), value);
if (xEnum == enumValue)
btn1Lbl = value;
if (YEnum == enumValue)
btn2Lbl = value;
}
Button1Label = Btn1Lbl;
Button2Label = Btn2Lbl;
_button1Ticks = 4;
_button2Ticks = 2;
Button1Color = Brushes.ForestGreen;
Button2Color = Brushes.Crimson;
...
}
...
protected void CreateWPFControls()
{
#region BUTTONS ARRAY AND LOOP
MyEnum[] MyEnumArray1 = new MyEnum[]
{
MyEnum.B,
MyEnum.C,
};
foreach (var value in MyEnumArray1)
{
Print("value " + value);
Print("st1EnumVar " + st1EnumVar);
Print("nd2EnumVar " + nd2EnumVar);
xX = ( ( st1EnumVar == value ) ? ( " + " + _button1Ticks.ToString() ) : string.Empty );
yY = ( ( nd2EnumVar == value ) ? ( " + " + _button2Ticks.ToString() ) : string.Empty );
Print("xX " + xX);
Print("yY " + yY);
}
// all of the buttons are basically the same so to save lines of code I decided to use a loop over an array
buttonsArray = new System.Windows.Controls.Button[2];
for (int i = 0; i < 2; ++i)
{
System.Windows.Media.Brush ButtonBackground;
string ButtonLabels, ButtonTicks;
switch(i)
{
case 0:
ButtonLabels = Button1Label;
ButtonBackground = Button1Color;
ButtonTicks = xX;
break;
case 1:
ButtonLabels = Button2Label;
ButtonBackground = Button2Color;
ButtonTicks = yY;
break;
default:
ButtonLabels = "";
ButtonBackground = null;
ButtonTicks = "1";
break;
}
buttonsArray[i] = new System.Windows.Controls.Button()
{
Content = string.Format("{0}{1}",ButtonLabels,ButtonTicks),
Height = 25,
Margin = new Thickness(0,0,0,0),
Padding = new Thickness(0,0,0,0),
Style = basicButtonStyle,
FontFamily = new FontFamily("Agency Fb"),
FontSize = 11,
FontWeight = FontWeights.Bold
};
buttonsArray[i].BorderBrush = Brushes.DimGray;
buttonsArray[i].Background = ButtonBackground;
}
#endregion
}
...
}
...
#region Properties
[Display(Name="st1EnumVar Button Methods", Description="", Order=1, GroupName="Button Parameters")]
[RefreshProperties(RefreshProperties.All)]
public MyEnum st1EnumVar
{ get; set; }
[Display(Name="nd2EnumVar Button Methods", Description="", Order=2, GroupName="Button Parameters")]
[RefreshProperties(RefreshProperties.All)]
public MyEnum nd2EnumVar
{ get; set; }
[NinjaScriptProperty]
[Display(Name="Label Button 1", Order=3, GroupName="Buttons Parameters")]
public string Button1Label
{ get; set; }
[NinjaScriptProperty]
[Display(Name="Label Button 2", Order=4, GroupName="Buttons Parameters")]
public string Button2Label
{ get; set; }
[NinjaScriptProperty]
[Range(0, int.MaxValue)]
[Display(Name="Button1Ticks", Order=5, GroupName="Buttons Parameters")]
public int _Button1Ticks
{
get { return _button1Ticks; }
set { _button1Ticks = value; }
}
[NinjaScriptProperty]
[Range(0, int.MaxValue)]
[Display(Name="Button2Ticks", Order=6, GroupName="Buttons Parameters")]
public int _Button2Ticks
{
get { return _button2Ticks; }
set { _button2Ticks = value; }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name="Button1Color", Order=7, GroupName="Buttons Parameters")]
public System.Windows.Media.Brush Button1Color
{ get; set; }
[Browsable(false)]
public string Button1ColorSerializable
{
get { return Serialize.BrushToString(Button1Color); }
set { Button1Color = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name="Button2Color", Order=8, GroupName="Buttons Parameters")]
public System.Windows.Media.Brush Button2Color
{ get; set; }
[Browsable(false)]
public string Button2ColorSerializable
{
get { return Serialize.BrushToString(Button2Color); }
set { Button2Color = Serialize.StringToBrush(value); }
}
#endregion
}
}Editor is loading...
Leave a Comment