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

Show parameter in the settings when a bool value is true

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

    Show parameter in the settings when a bool value is true

    Hi,
    I have got a public property for using as parameter in a strategy, but I want to give it a public access when a bool value returns true. Does ninjatrader 8 allow that. If yes, what will be the syntax please? If not, then any work around?

    #2
    Hello asmmbillah,

    Thank you for the post.

    Yes this is possible, it would require using a type converter. There is a sample of that concept in the following link. Keep in mind that instead of IndicatorBaseConverter you would create a StrategyBaseConverter.




    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Tried the sample along with the strategy ref from the link, doesn't work. And also where exactly it should be added '[TypeConverter("NinjaTrader.NinjaScript.Strategies. MyCustomConveter")]' ? Because if I add it before the main strategy class, it starts showing various unnecessary properties. Please advise.

      Comment


        #4
        Hello asmmbillah,

        The code you provided needs to go on the class exactly the same as the indicator sample. The type converters type would need to be changed in the strategy to StrategyBaseConverter. Did you do that?




        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          yes I did. see my code below:

          [TypeConverter("NinjaTrader.NinjaScript.Strategies. MyCustomConveter")]
          public class mainStrategy: Strategy
          {

          [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
          [Display(Name = "Toggle show/hide", Order = 1, GroupName = "Additional Parameters")]
          public bool ShowHideToggle
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name = "MaxDailyStopLoss", Description = "MaxDailyStopLoss", Order = 2, GroupName = "Additional Parameters")]
          public int MaxDailyStopLoss
          { get; set; }
          }
          // below outside the main strategy class

          // custom converter class for strategies
          public class MyCustomConveter : StrategyBaseConverter
          {
          public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
          {
          mainStrategy strategy = component as mainStrategy;

          PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context)
          ? base.GetProperties(context, component, attrs) : TypeDescriptor.GetProperties(component, attrs);

          if (strategy == null || propertyDescriptorCollection == null)
          return propertyDescriptorCollection;

          PropertyDescriptor maxDailyStopLoss = propertyDescriptorCollection["MaxDailyStopLoss"];

          propertyDescriptorCollection.Remove(maxDailyStopLo ss);

          if (strategy.ShowHideToggle)
          {
          propertyDescriptorCollection.Add(maxDailyStopLoss) ;
          }

          return propertyDescriptorCollection;
          }
          public override bool GetPropertiesSupported(ITypeDescriptorContext context)
          { return true; }
          }

          And also it show attached screenshot's unnecessary parameters.
          Attached Files
          Last edited by asmmbillah; 06-10-2021, 01:05 PM.

          Comment


            #6
            Hello asmmbillah,

            I was unable to find another example using a strategy so I just copied the Indicator and renamed the types in the file. Here is an example attached.

            Please let me know if I may be of further assistance.
            Attached Files
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Started by Waxavi, Today, 02:10 AM
            1 response
            20 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Working...
            X