Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
how to get the enum's inputs displayed on the Strategy Prope
Collapse
X
-
NinjaTrader_ChelseaB Hello.
This modified script prints the following:
Why doesn't the strategyInstance.ReadOnlyString value updates to the strategyInstance.EnumValue.ToString() value when changing the strategyInstance.EnumValue.ToString() selected value?EnumValue: MyCustom2
ReadOnlyString: MyCustom2
EnumValue: MyCustom2
ReadOnlyString: MyCustom2
EnumValue: MyCustom2
ReadOnlyString: MyCustom2
strategyInstance.ReadOnlyString: MyCustom2
strategyInstance.EnumValue.ToString(): MyCustom3
strategyInstance.EnumValue: MyCustom3
strategyInstance.ReadOnlyString1: MyCustom2
value: MyCustom3
strategyInstance.ReadOnlyString: MyCustom3
strategyInstance.EnumValue.ToString(): MyCustom2
strategyInstance.EnumValue: MyCustom2
strategyInstance.ReadOnlyString1: MyCustom3
value: MyCustom3
strategyInstance.ReadOnlyString: MyCustom3
strategyInstance.EnumValue.ToString(): MyCustom1
strategyInstance.EnumValue: MyCustom1
strategyInstance.ReadOnlyString1: MyCustom3
value: MyCustom2
The prints look right but no difference in the windows strategyInstance.ReadOnlyString field when changing the strategyInstance.EnumValue.ToString() selected value :
I takes clicking the strategyInstance.ReadOnlyString Window field then the strategyInstance.EnumValue.ToString() one for it to print.
Ticking the bool checkboxes do update the strategyInstance.ReadOnlyString as desired. But not when changing the strategyInstance.EnumValue.ToString() selected value. That is the end use needed.
Will you take a look and test on your side with the attached script to pinpoint accurately what the issue is and potential fix?Attached Files
Comment
-
NinjaTrader_ChelseaB Hello,
Turns out this is working:
https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1315837-how-to-get-the-enum-s-inputs-displayed-on-the-strategy-prope?p=1316866#post1316866
By creating some new class scope string variables
private string enumtoLabel0,enumtoLabel1;
Then using an exact copy of the MymainEnum enum inside the protected void CreateWPFControls() scope,
then LINQ for matching the enums' Main values to the Properties UI Chart Windows actual selected values:
It does not need the button property to set the Button label — no need toCode:protected void CreateWPFControls() { ... #region ENUM VALUEs TO SET THE BUTTONS LABELS VALUES MymainEnum[] MymainEnumFilterArray = new MymainEnum[] { MymainEnum.Item1, MymainEnum.Item2, MymainEnum.Item3, MymainEnum.ItemA, MymainEnum.ItemB, MymainEnum.ItemC, }; if ( MymainEnumFilterArray.Any(s => s.Equals(EnumValA)) ) { enumtoLabel0 = EnumValA.ToString(); } if ( MymainEnumFilterArray.Any(s => s.Equals(EnumValB)) ) { enumtoLabel1 = EnumValB.ToString(); } #endregion
use the (State == State.SetDefaults) scope strings.
Nor using the TypeConverter extra classes / methods.
region BUTTONS PARAMETERS
//Button0Label = "Btn0Lbl";
Button0Color = Brushes.ForestGreen;
_button0Ticks = 4;
//[NinjaScriptProperty]
//[Display(Name="Label Button 0 On", Order=1, GroupName="Button #0 Parameters")]
//public string Button0Label
//{ get; set; }
It works as expected and is good enough for now.
Still curious and will test to see how to do that from the Properties / (State == State.SetDefaults) scope strings approach.Attached FilesLast edited by PaulMohn; 09-05-2024, 04:27 AM.
Comment
-
Or simple assignment via extra string is working too:
https://pastecode.io/s/iko2375n
Code:namespace NinjaTrader.NinjaScript.Strategies { ... public class _EnumtoLabel : Strategy { #region #4 CLASS VARIABLES - CreateWPFControls() - BUTTONS : ENUM TO BUTTONS LABELS STRING VARIABLES private string enumtoLabel0,enumtoLabel1; #endregion ... protected void CreateWPFControls() { #region BUTTONS #region BUTTONS ARRAY AND LOOP #region ENUM VALUEs TO SET THE BUTTONS LABELS VALUES enumtoLabel0 = EnumValA.ToString(); enumtoLabel1 = EnumValB.ToString(); #endregion #region BUTTONS CREATING LOOP 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 = enumtoLabel0; ButtonBackground = Button0Color; ButtonTicks = subTicksCheck0; break; case 1: ButtonLabels = enumtoLabel1; ButtonBackground = Button1Color; ButtonTicks = subTicksCheck1; break; ...Last edited by PaulMohn; 09-05-2024, 04:42 AM.
Comment
-
Or no assignment via extra string but assignment
to the Properties UI Chart Windows actual selected values straight to the
CreateWPFControls() loop/switch variables is working too:
https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1315837-how-to-get-the-enum-s-inputs-displayed-on-the-strategy-prope?p=1316873#post1316873
The point being it does work because the CreateWPFControls() method is called/updatesCode:namespace NinjaTrader.NinjaScript.Strategies { ... public class _EnumtoLabel : Strategy { ... protected void CreateWPFControls() { #region BUTTONS #region BUTTONS ARRAY AND LOOP #region BUTTONS CREATING LOOP 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 = EnumValA.ToString(); ButtonBackground = Button0Color; ButtonTicks = subTicksCheck0; break; case 1: ButtonLabels = EnumValB.ToString(); ButtonBackground = Button1Color; ButtonTicks = subTicksCheck1; break; ...
every time the Chart Properties Windows is reloaded/it's "Apply" Button is clicked.
The buttons being recreated every time.
No need for the TypeConverter approach then.
This code is a simplified version of what I'm trying to do: string day = Thursday; DateTime dt = DateTime.Now; if (day == dt.DayOfWeek) { // start the program } I need to read a day of the w...Attached FilesLast edited by PaulMohn; 09-10-2024, 12:53 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, 03-13-2026, 05:17 AM
|
0 responses
86 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
151 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
79 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
53 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
61 views
0 likes
|
Last Post
|

Comment