Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

error CS0117 does not contain a definition for 'value'

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

    #16
    These versions are same same as your sample with the
    ticksString = "12345";
    outside the chart control and dispatcher scope still does not set anything in the

    Label Button 1 should be set to "A" (same as BttonMethods Selector Button 1 value)
    Label Button 2 should be set to "C" ​(same as ButtonMethods Selector Button 2 value)​​

    Same output as



    Code:
                    
                        else if (State == State.Historical)
                        {
                            Button1Label                = Btn1Lbl;
                            Button2Label                = Btn2Lbl;
                            
                            if (ChartControl != null)
                            {
                                ChartControl.Dispatcher.InvokeAsync(() =>
                                {
                                    EnumtoLabel();
                                });
                            }
                        }​
    Code:
    
            
            #region (OnStateChange)
            
                protected override void OnStateChange()
                {    
                    #region (State == State.SetDefaults)
                    
                        if (State == State.SetDefaults)
                        {
                           ...
                    
                            #region BUTTONS PARAMETERS - BUTTONS METHOD ENUM SELECTORS
                    
                                st1EnumVar                    = MyEnum4.X;
                                nd2EnumVar                    = MyEnum4.B;
                        
                            #endregion
                        
                            #region BUTTONS PARAMETERS
                            
                                Button1                        = true;
                                Button1Color                = Brushes.ForestGreen;
                                _button1Ticks                = 4;
                                
                                Button2                        = true;
                                Button2Color                = Brushes.Crimson;
                                _button2Ticks                = 2;
                            
                            #endregion
    
                        }
                        
                    #endregion
                    
                    #region (State == State.Configure)
                    
                        else if (State == State.Configure)
                        {
                        }
                        
                    #endregion
                    
                    #region (State == State.DataLoaded)
                    
                        else if (State == State.DataLoaded)
                        {
                        }
                        
                    #endregion
                    
                    #region (State == State.Historical)
                    
                        else if (State == State.Historical)
                        {
                            Button1Label                = Btn1Lbl;
                            Button2Label                = Btn2Lbl;
                            
                            if (ChartControl != null)
                            {
                                ChartControl.Dispatcher.InvokeAsync(() =>
                                {
                                    EnumtoLabel();
                                    CreateWPFControls();​​
                                });
                            }
                        }
                        
                    #endregion
                        
                    #region (State == State.Terminated)
    
                        else if (State == State.Terminated)
                        {
                            if (ChartControl != null)
                            {
                                ChartControl.Dispatcher.InvokeAsync(() =>
                                {
                                    DisposeWPFControls();
                                });
                            }
                        }
                        
                    #endregion
                }
            
            #endregion​


    Code:
                    
                        else if (State == State.DataLoaded)
                        {
                            Button1Label                = Btn1Lbl;
                            Button2Label                = Btn2Lbl;
                            
                            if (ChartControl != null)
                            {
                                ChartControl.Dispatcher.InvokeAsync(() =>
                                {
                                    EnumtoLabel();
                                });
                            }​
                        }​
    Code:
    
            
            #region (OnStateChange)
            
                protected override void OnStateChange()
                {    
                    #region (State == State.SetDefaults)
                    
                        if (State == State.SetDefaults)
                        {
                           ...
                    
                            #region BUTTONS PARAMETERS - BUTTONS METHOD ENUM SELECTORS
                    
                                st1EnumVar                    = MyEnum4.X;
                                nd2EnumVar                    = MyEnum4.B;
                        
                            #endregion
                        
                            #region BUTTONS PARAMETERS
                            
                                Button1                        = true;
                                Button1Color                = Brushes.ForestGreen;
                                _button1Ticks                = 4;
                                
                                Button2                        = true;
                                Button2Color                = Brushes.Crimson;
                                _button2Ticks                = 2;
                            
                            #endregion
    
                        }
                        
                    #endregion
                    
                    #region (State == State.Configure)
                    
                        else if (State == State.Configure)
                        {
                        }
                        
                    #endregion
                    
                    #region (State == State.DataLoaded)
                    
                        else if (State == State.DataLoaded)
                        {
                            Button1Label                = Btn1Lbl;
                            Button2Label                = Btn2Lbl;
                            
                            if (ChartControl != null)
                            {
                                ChartControl.Dispatcher.InvokeAsync(() =>
                                {
                                    EnumtoLabel();
                                });
                            }​
                        }
                        
                    #endregion
                    
                    #region (State == State.Historical)
                    
                        else if (State == State.Historical)
                        {  
                              CreateWPFControls();​
                        }
                        
                    #endregion
                        
                    #region (State == State.Terminated)
    
                        else if (State == State.Terminated)
                        {
                            if (ChartControl != null)
                            {
                                ChartControl.Dispatcher.InvokeAsync(() =>
                                {
                                    DisposeWPFControls();
                                });
                            }
                        }
                        
                    #endregion
                }
            
            #endregion​

    Comment


      #17
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello PaulMohn,

      This may be due to the advanced custom C# code in your script including converting enums to strings.

      I've modified the script to include the same text as the enum value in the button content.
      [ATTACH]n1315771[/ATTACH]

      If prints are not appearing the code is not being reached or a run-time error has been hit.

      Have I misunderstood the issue?
      Are you not trying to control text appearing in the button content?
      Are you trying to set a public string input value based on the selection of an enum input value?
      Here's a short demo of what is needed:






      In Btton Methods Selector Button 1 Field:
      When I Change selection from
      A to C, Label Button 1 field
      Should Change to C too.
      Insteat Nothing is Set.


      Same for
      In Button Methods Selector Button 2 Field:
      When I Change selection from
      B to X, Label Button 1 field
      Should Change to X too.
      Insteat Nothing is Set.​
      Those are correct:
      Are you not trying to control text appearing in the button content?
      Are you trying to set a public string input value based on the selection of an enum input value?​
      more specifically:

      If the enum imput is C, then the Button 1 content string must be "C" as well.
      same for the 2nd button.

      To do this I used this method:

      Code:
      public void EnumtoLabel()
                  {        
                      #region #1 Buttons
                      
                          #region ENUM LOOP BUTTON LABEL == BUTTON ENUM STRING
              
                              foreach (string value in Enum.GetNames(typeof(MyEnum3)))
                              {
                                  Print("value0: " + value);
                                  
                                  MyEnum3 enumValue = (MyEnum3)Enum.Parse(typeof(MyEnum3), value);
                                  
                                  Print("enumValue: " + enumValue);
                                  Print(" ");
                              
                                  if (st1EnumVar == enumValue)
                                      Btn1Lbl = value;
                                  
                                  Print("value1: " + value);
                                  Print("Btn1Lbl: " + Btn1Lbl);
                              
                                  if (nd2EnumVar == enumValue)
                                      Btn2Lbl = value;
                                  Print("value2: " + value);
                                  Print("Btn2Lbl: " + Btn2Lbl);
                              }
                          
                          #endregion
                      
                      #endregion
                  }​

      In specifics, these should provide for the enum's input being replicated in the Buttons Strings Contents:

      Code:
      
                              
                                  if (st1EnumVar == enumValue)
                                      Btn1Lbl = value;
                                
                              
                                  if (nd2EnumVar == enumValue)
                                      Btn2Lbl = value;​
      Last edited by PaulMohn; 08-27-2024, 08:22 AM.

      Comment


        #18
        Hello PaulMohn,

        It appears that you are not trying to control the text that appears in the button content, but instead are trying to set a public string input value when an enum value is changed.

        For this you would need a custom typeconverter.

        Below is a link to the reference sample which demonstrates.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #19


          The foreach loop needs the break; statement at it's end,
          else xX/yY get reset past the iteration when st1EnumVar == value / nd2EnumVar == value is true

          Code:
                              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);
                                
                                  break;
                                  
                              }​
          In a C# (feel free to answer for other languages) loop, what's the difference between break and continue as a means to leave the structure of the loop, and go to the next iteration? Example: foreach (
          Last edited by PaulMohn; 09-04-2024, 06:54 AM.

          Comment


            #20
            Working sub Enum Filter with foreach and break; :

            https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1315482-error-cs0117-does-not-contain-a-definition-for-value?p=1316855#post1316855


            Code:
            namespace NinjaTrader.NinjaScript.Strategies
            {
                public enum MyMainEnum
                {Item1,Item2,Item3,ItemA,ItemB,ItemC};​
            
                 ...
            
            
                    protected void CreateWPFControls()
                    {​
                                    ...
                                
                                    #region ADD BUTTONS TICKS # ONLY TO STP MOVE ENUM METHODS
                                                    
                                        MyMainEnum[] MySubEnumFilterArray = new MyMainEnum[]
                                        {
                                            MyMainEnum.ItemB,
                                            MyMainEnum.Item2,
                                        };
            
            
                                        foreach (var value in MySubEnumFilterArray)
                                        {
                                            if (EnumValA == value)
                                            {
                                                subTicksCheck0 = ( " + " + _button0Ticks.ToString() );
                                                break;
                                            }
                                            else
                                            {
                                                subTicksCheck0 = string.Empty;
                                            }
                                            
                                            if (EnumValB == value)
                                            {
                                                subTicksCheck1 = ( " + " + _button1Ticks.ToString() );
                                                break;
                                            }
                                            else
                                            {
                                                subTicksCheck1 = string.Empty;
                                            }
                                        }
            
                                    #endregion​
            How do I break out of a foreach loop in C# if one of the elements meets the requirement? For example: foreach(string s in sList){ if(s.equals("ok")){ //jump foreach loop and return ...
            Attached Files
            Last edited by PaulMohn; 09-05-2024, 02:23 AM.

            Comment


              #21
              Working sub Enum Filter with LINQ and .Any / .Equals :​

              https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1315482-error-cs0117-does-not-contain-a-definition-for-value?p=1316857#post1316857


              Code:
              namespace NinjaTrader.NinjaScript.Strategies
              {
                  public enum MyMainEnum
                  {Item1,Item2,Item3,ItemA,ItemB,ItemC};​
              
                   ...
              
              
                      protected void CreateWPFControls()
                      {​
                                      ...
                                  
                                      #region ADD BUTTONS TICKS # ONLY TO STP MOVE ENUM METHODS​
              
                                          MyMainEnum[] MySubEnumFilterArray = new MyMainEnum[]
                                          {
                                              MyMainEnum.ItemB,
                                              MyMainEnum.Item2,
                                          };
                                              
                                          if ( MySubEnumFilterArray.Any(s => s.Equals(EnumValA)) )
                                          {
                                              subTicksCheck0 = ( " + " + _button0Ticks.ToString() );
                                          }
                                          else
                                          {
                                              subTicksCheck0 = string.Empty;
                                          }
                                          
                                          if ( MySubEnumFilterArray.Any(s => s.Equals(EnumValB)) )
                                          {
                                              subTicksCheck1 = ( " + " + _button1Ticks.ToString() );
                                          }
                                          else
                                          {
                                              subTicksCheck1 = string.Empty;
                                          }​
                                  
                                      #endregion
              How do I break out of a foreach loop in C# if one of the elements meets the requirement? For example: foreach(string s in sList){ if(s.equals("ok")){ //jump foreach loop and return ...
              Attached Files
              Last edited by PaulMohn; 09-05-2024, 02:34 AM.

              Comment


                #22
                Working sub Enum Filter with LINQ and .Any / .Equals and ternary operator:​​

                https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1315482-error-cs0117-does-not-contain-a-definition-for-value?p=1316859#post1316859


                Code:
                namespace NinjaTrader.NinjaScript.Strategies
                {
                    public enum MyMainEnum
                    {Item1,Item2,Item3,ItemA,ItemB,ItemC};​
                
                     ...
                
                
                        protected void CreateWPFControls()
                        {​
                                        ...
                                    
                                        #region ADD BUTTONS TICKS # ONLY TO STP MOVE ENUM METHODS​
                
                                            MyMainEnum[] MySubEnumFilterArray = new MyMainEnum[]
                                            {
                                                MyMainEnum.ItemB,
                                                MyMainEnum.Item2,
                                            };
                                                
                                            subTicksCheck0 = ( MySubEnumFilterArray.Any(s => s.Equals(EnumValA)) )
                                                                        ? ( " + " + _button0Ticks.ToString() )
                                                                        : ( string.Empty );
                                            
                                            subTicksCheck1 = ( MySubEnumFilterArray.Any(s => s.Equals(EnumValB)) )
                                                                        ? ( " + " + _button1Ticks.ToString() )
                                                                        : ( string.Empty );​
                                    
                                        #endregion
                Attached Files
                Last edited by PaulMohn; 09-05-2024, 02:58 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                51 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                128 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                69 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X