Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PropertyDescriptor in Custom BarType

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

    PropertyDescriptor in Custom BarType

    Hi.
    I'd like to know if there is a way to add a custom parameter for my custom bartype that can be set by the user in the DataSeries Window.

    I know that we can remove / rename Properties, but is there a way to actually add one ?
    Because I need a boolean, and of course I can rename another property and use the integer value as a boolean, but this is a bit ugly.

    Some threads on stackoverflow forum show how to create a CustomPropertyDescriptor derived from PropertyDescriptor. Then I was able to add this CustomPropertyDescriptor to the PropertyDescriptorCollection and I can see now the boolean checkbox.

    Except that when I change the boolean value, the change is not taken into account in the code, and it keeps the default value.

    Inside the State == State.Configure section, I've added the following piece of code
    Code:
    if (Properties.Find("CustomMode", true) == null)
    {
          Properties.Add(new CustomModePropertyDescriptor(false));
    }
    The "CustomModePropertyDescriptor" class is derived from the abstract class PropertyDescriptor and it exposes my boolean. The readonly mode is set to false and its Name property is "CustomMode".

    If someone knows how to do that...
    Note I've asked on the NT8 forum, but if you have a custom bartype with custom parameters on NT7, I'm interested too.

    Thanks in advance,

    -----------------------------------------------
    Christophe - Ninja-Addons.com
    CEO Azur Investment Technologies "AzurITEC" sas
    http://www.ninja-addons.com - http://www.neat-markets.com
    3rd Party Add-On Vendor

    #2
    Hello AzurITec_Chris,

    Thank you for writing in.

    I will be looking into this and will return with my findings.

    Thank you for your patience.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thanks Zachary. Jesse also answered me by e-mail the same thing.
      Just to help you with more info, here is a piece of code I've written.
      You can see that the custom boolean parameter is added to the window settings, but if you click the checkbox and then apply, the checkbox is unchecked automatically.
      When I run the code step by step with VS, it shows that the custom property is added to the property collection but is not persistent.

      Code:
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      
      #endregion
      
      //This namespace holds Bars types in this folder and is required. Do not change it. 
      namespace NinjaTrader.NinjaScript.BarsTypes
      {
          public class MyCustomBarsType : BarsType
          {
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Name = "CustomBarType";
                      BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType)101, BarsPeriodTypeName = "CustomBarType", Value = 1 };
                      BuiltFrom = BarsPeriodType.Tick;
                      DaysToLoad = 5;
                      IsIntraday = true;
                  }
                  else if (State == State.Configure)
                  {
                      Name = "CustomBarType";
      
                      Properties.Remove(Properties.Find("BaseBarsPeriodType", true));
                      Properties.Remove(Properties.Find("ReversalType", true));
                      Properties.Remove(Properties.Find("PointAndFigurePriceType", true));
      
                      if (Properties.Find("CustomParam", true) == null) Properties.Add(new CustomPropertyDescriptor(false));
      
                      SetPropertyName("Value", "Body Size (tick)");
                      SetPropertyName("Value2", "Minimum timespan (sec)");
                  }
              }
      
              public override int GetInitialLookBackDays(BarsPeriod barsPeriod, TradingHours tradingHours, int barsBack)
              {
                  return 1; //replace with your bars logic
              }
      
              protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
              {
                  
              }
      
              public override void ApplyDefaultBasePeriodValue(BarsPeriod period)
              {
                  //replace with any default base period value logic
              }
      
              public override void ApplyDefaultValue(BarsPeriod period)
              {
                  //replace with any default value logic
              }
      
              public override string ChartLabel(DateTime dateTime)
              {
                  return "custom label logic here";
              }
      
              public override double GetPercentComplete(Bars bars, DateTime now)
              {
                  return 1.0d; //replace with your bar percent logic
              }
      
          }
      
          public class CustomPropertyDescriptor : PropertyDescriptor
          {
              public bool CustomParam { get; set; }
      
              public CustomPropertyDescriptor(bool value) : base("CustomParam", null) { CustomParam = value; }
      
              public override AttributeCollection Attributes { get { return new AttributeCollection(null); } }
      
              public override bool CanResetValue(object component) { return true; }
      
              public override Type ComponentType { get { return CustomParam.GetType(); } }
      
              public override string DisplayName { get { return "Custom Param"; } }
      
              public override string Description { get { return "Description"; } }
      
              public override object GetValue(object component) { return CustomParam; }
      
              public override bool IsReadOnly { get { return true; } }
      
              public override string Name { get { return "CustomParam"; } }
      
              public override Type PropertyType { get { return CustomParam.GetType(); } }
      
              public override void ResetValue(object component) { }
      
              public override bool ShouldSerializeValue(object component) { return true; }
      
              public override void SetValue(object component, object value) { CustomParam = (bool)value; }
          }
      }
      Thanks again,

      -----------------------------------------------
      Christophe - Ninja-Addons.com
      CEO Azur Investment Technologies "AzurITEC" sas
      http://www.ninja-addons.com - http://www.neat-markets.com
      3rd Party Add-On Vendor

      Comment


        #4
        Hello,

        Thank you for the reply.

        Yes from my tests using a custom PropertyDescriptor the outcome is the same. I currently have a question in to development on this item to see if it is even possible to add to the existing collection in this type.

        The types that do support adding to the PropertyDescriptorCollection all have overrides to inherit from already such as the DrawingTools:

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)

        The types that do not have this override, I will need clarification to see if it will still be possible or if internally this was not added due to limitations of the type.

        Once I have further information I will reply back.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello,

          To comment back on the prior post, I had received a explanation from development on this topic.

          Custom Property and Property Descriptors are not supported in BarTypes or ChartStyles unfortunately. This is due to an underlying design choice carried over from NT7 where we use an interface to pass the BarType/ChartStyles around. Only items declared in the interface will pass.

          Because of this, a vote was added to allow for custom properties in these types SFT-1269

          Unfortunately it is not currently possible to add a completely new property, instead you would need to utilize the existing properties that are already in the type such as Value and Value2, and use the Rename method that already exists in the other types.


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

          Comment


            #6
            Thanks for the explanation.
            The problem, is that value and value2 are already used by my bartype.
            Other properties are like BaseBarsPeriodType, ReversalType, PointAndFigurePriceType are enum so even renamed they are useless (except if you know a way to rename the enum...).

            Would it be possible to add a boolean value, like value3 in the BarsPeriod class, so we can access to it, rename it and do whatever we want with it.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by frankthearm, Today, 09:08 AM
            7 responses
            29 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by NRITV, Today, 01:15 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by maybeimnotrader, Yesterday, 05:46 PM
            5 responses
            25 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by quantismo, Yesterday, 05:13 PM
            2 responses
            18 views
            0 likes
            Last Post quantismo  
            Started by adeelshahzad, Today, 03:54 AM
            5 responses
            33 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X