Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to get the enum's inputs displayed on the Strategy Prope

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    SampleStrategyTypeConverter script /// Minus Case #5

    Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.



    SampleStrategyTypeConverter script /// Minus Case #5 & #3



    Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.



    SampleStrategyTypeConverter script /// Minus Case #5, #3 and #1



    Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

    Comment


      #17
      NinjaTrader_ChelseaB Hello.

      This modified script prints the following:

      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​
      Why doesn't the strategyInstance.ReadOnlyString value updates to the strategyInstance.EnumValue.ToString() value when changing the strategyInstance.EnumValue.ToString() selected value?

      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


        #18
        Hello PaulMohn,

        I'm uncertain about this, but may have to do with converting the enums to strings.

        Have you tried not doing this and using a switch to set a specific string instead of trying to convert the enums to strings and back?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          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:

          Code:
                  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​
          It does not need the button property to set the Button label — no need to
          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 Files
          Last edited by PaulMohn; 09-05-2024, 04:27 AM.

          Comment


            #20
            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;
                                                
                    ...​
            Attached Files
            Last edited by PaulMohn; 09-05-2024, 04:42 AM.

            Comment


              #21
              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


              Code:
              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;
                                                  
                      ...​
              The point being it does work because the CreateWPFControls() method is called/updates
              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 Files
              Last 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
              93 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              152 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              80 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              53 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              65 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X