Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

When I change parameter value in strategy settings, I want preselect other values

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

    When I change parameter value in strategy settings, I want preselect other values

    Hi,

    is it possible when I change value of 1 parameter in strategy settings to set other values to predefined values? so i do not need to do this manually? I want to change value on top, and when i do so, it will change values of other fields..

    Click image for larger version

Name:	image.png
Views:	107
Size:	601.3 KB
ID:	1248350

    #2
    Hello, thanks for writing in. The best example to study will be the type converter example:


    Referencing Use case 1, in public class MyConverter notice the use of PropertyDescriptorCollection, which gets all the properties of the attached class (in this case, the indicator object you want to modify its properties) and the use of PropertyDescriptor which will let you change the properties value. See the C# documentation for PropertyDescriptor here:

    https://learn.microsoft.com/en-us/do...r?view=net-7.0

    Kind regards,
    -ChrisL​
    Last edited by NinjaTrader_ChrisL; 04-25-2023, 11:57 AM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris I am afraid the first link does not work :-/

      Comment


        #4
        I fixed it, sorry the forum likes to put a space in my links when I paste them in.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Cool I already get to all properties, can i access only my custom properties? not all that strategy has?

          Comment


            #6

            I do not have list of properties. Anyway I found a way.
            can I access to value ResourceType?
            Code:
                    [Display(ResourceType = typeof(Custom.Resource), Name = "Session A Begin", GroupName = filterTradingTimeGroup, Order = filterTradingTimeOrder + 2)]
                    [Description("Počáteční čas seance")]
                    public TimeSpan FilterTTSessionABegin {
                        get { return tFilterTTSessionABegin; }
                        set { tFilterTTSessionABegin = value; }
                    }
            ​
            ​I gues If i access ResourceType and it equals to Custom.Resource i would have it

            Comment


              #7
              Hi, I changed the Type Converter example that I linked above in the "Use Case 1" portion of the MyConverter class to change other integers based on the value of another integer:

              HTML Code:
                  public class MyConverter : IndicatorBaseConverter // or StrategyBaseConverter
                  {
                      public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
                      {
                          // we need the indicator instance which actually exists on the grid
                          SampleIndicatorTypeConverter indicator = component as SampleIndicatorTypeConverter;
              
                          // base.GetProperties ensures we have all the properties (and associated property grid editors)
                          // NinjaTrader internal logic determines for a given indicator
                          PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context)
                                                                                      ? base.GetProperties(context, component, attrs)
                                                                                      : TypeDescriptor.GetProperties(component, attrs);
              
                          if (indicator == null || propertyDescriptorCollection == null)
                              return propertyDescriptorCollection;
              
              
                          #region Use Case #1: Now it's changing integer values based on the value of another integer:
              
                          PropertyDescriptor toggleValue1 = propertyDescriptorCollection["ToggleValue1"];
                          PropertyDescriptor toggleValue2 = propertyDescriptorCollection["ToggleValue2"];
              
                          //Important, instead of checking "ShowHideToggle" boolean property, check the value of an int property we added to the SampleIndicatorTypeConverter indicator:
                          //[RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
                          //[Display(Name = "IntegerToggle", Order = 1, GroupName = "Use Case #1")]
                          //public int IntegerToggle
                          //{ get; set; }​
                          if (indicator.IntegerToggle == 6)
                          {
                              toggleValue1.SetValue(indicator, 10);
                              toggleValue2.SetValue(indicator, 11);
                          }
              
              
                          #endregion
              
              
                      }
              
                      // Important: This must return true otherwise the type convertor will not be called
                      public override bool GetPropertiesSupported(ITypeDescriptorContext context)
                      { return true; }
                  }​
              Last edited by NinjaTrader_ChrisL; 04-25-2023, 03:42 PM.
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by futtrader, 04-21-2024, 01:50 AM
              5 responses
              56 views
              0 likes
              Last Post NinjaTrader_Eduardo  
              Started by PeakTry, Today, 10:49 AM
              0 responses
              2 views
              0 likes
              Last Post PeakTry
              by PeakTry
               
              Started by llanqui, Today, 10:32 AM
              0 responses
              5 views
              0 likes
              Last Post llanqui
              by llanqui
               
              Started by StockTrader88, 03-06-2021, 08:58 AM
              45 responses
              3,992 views
              3 likes
              Last Post johntraderuser2  
              Started by TAJTrades, Today, 09:46 AM
              0 responses
              8 views
              0 likes
              Last Post TAJTrades  
              Working...
              X