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

Custom expandable class issue

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

    Custom expandable class issue

    Hello all, I dont really know what to do I made my custom class RangeCondition and I want it to be expandable in PropertyGrid in Parameters window. I think I done it. But in a LOG I have the same error after compiling and refresh it (just for the first time after compile). And this property doesnt remeber its value Would you be so king and help me somehow ??

    Code:
    [TypeConverterAttribute(typeof(ExpandableObjectConv erter))]
    [Serializable()]
    public class RangeCondition: ISerializable
    {
    private OF_OperatorType condoperator = OF_OperatorType.NoOperator; // enumerator defined above
    private OF_ConditionType condtype = OF_ConditionType.OpositeSideDiagonally; // enumerator defined above
    private double multiplier = 1;
    private int increment = 0;
    private int condvalue = 0;
    public NinjaTrader.Indicator.Indicator Reference = null;


    public RangeCondition() {
    Operator = OF_OperatorType.NoOperator;
    Type = OF_ConditionType.OpositeSideDiagonally;
    Multiplier = 1;
    Increment = 0;
    Value = 0;
    }


    public override string ToString()
    {
    string rtn = "no condition";
    if (condoperator!=OF_OperatorType.NoOperator) {
    rtn = "Number ";
    } else {
    return rtn;
    }

    if (condoperator==OF_OperatorType.GreaterThan) rtn+= "> ";
    if (condoperator==OF_OperatorType.GreaterThanOrEqualT o) rtn+= ">= ";
    if (condoperator==OF_OperatorType.LessThan) rtn+= "< ";
    if (condoperator==OF_OperatorType.LessThanOrEqualTo) rtn+= "<= ";

    if (condtype==OF_ConditionType.OpositeSide) rtn+= "OS";
    if (condtype==OF_ConditionType.AvgTradesPerPeriod) rtn+= "AvgTPP";
    if (condtype==OF_ConditionType.Value) rtn+= condvalue+"";

    if (Multiplier>1) rtn+= "*"+Multiplier;
    if (Increment>0) rtn+= "+"+Increment;

    return rtn;
    }


    public void GetObjectData(SerializationInfo serInfo, StreamingContext context)
    {
    serInfo.AddValue("Operator",Operator);
    serInfo.AddValue("Type",Type);
    serInfo.AddValue("Multiplier",Multiplier);
    serInfo.AddValue("Increment",Increment);
    serInfo.AddValue("Value",Value);
    }

    private RangeCondition(SerializationInfo serInfo,StreamingContext context)
    {
    this.Operator = (OF_OperatorType)Enum.Parse(typeof(OF_OperatorType ), serInfo.GetString("Operator"));
    this.Type = (OF_ConditionType)Enum.Parse(typeof(OF_ConditionTy pe), serInfo.GetString("Type"));
    this.Value = serInfo.GetInt32("Value");
    this.Increment = serInfo.GetInt32("Increment");
    this.Multiplier = serInfo.GetDouble("Multiplier");
    }
    .
    .
    .
    and so on
    }

    Error text:
    Failed to set property 'R1_Condition1' for indicator 'TestIndicator':
    Object of type RangeCondition cannot be converted to type RangeCondition.


    Is it a problem of serialization or WHAT ???
    I would appreciate any help.
    Thank you very much.

    Alex

    #2
    Hello Alex,

    Thank you for your post.

    Can you highlight the line the error refers to? Can you also provide the error code (if any)?

    Comment


      #3
      Hello Patrick,
      this error is not during compiling. All code is compiled right. But then - when I do chart refresh to load actual indicator version (F5) I have that error in the LOG and in output window. So I have no clue to which code line it refers. And it has no errror code.

      Failed to set property 'R1_Condition1' for indicator 'TestIndicator': Object of type RangeCondition cannot be converted to type RangeCondition.

      I found out that this error appears always just one time after compile and refresh and indicator does not remeber values for this variables set before compiling (neither default values). But after next indicator refresh or after NT restart this variables have right values until I do new compile and refresh.

      I have 10 properties of RangeCondition type. Definition for the first:
      [Description("")]
      [GridCategory("Range 1 conditions")]
      [Gui.Design.DisplayName("Condition 1")]
      [XmlIgnore()]
      public RangeCondition R1_Condition1
      {
      get { return r1_Condition1; }
      set { r1_Condition1 = (RangeCondition)value; }
      }
      [Browsable(false)]
      public string R1_Condition1Serialize
      {
      get { return SerializeRangeConditionToString(r1_Condition1); }
      set { r1_Condition1 = (RangeCondition)SerializeRangeConditionFromString( value); }
      }


      Thank you very much for your answer.
      Alex

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by BarzTrading, Today, 07:25 AM
      2 responses
      21 views
      1 like
      Last Post BarzTrading  
      Started by devatechnologies, 04-14-2024, 02:58 PM
      3 responses
      20 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by tkaboris, Today, 08:01 AM
      0 responses
      4 views
      0 likes
      Last Post tkaboris  
      Started by EB Worx, 04-04-2023, 02:34 AM
      7 responses
      163 views
      0 likes
      Last Post VFI26
      by VFI26
       
      Started by Mizzouman1, Today, 07:35 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X