Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NinjaScript property advanced options

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

    NinjaScript property advanced options

    Hi.

    I'd like to set up some properties in a strategy, that wood be linked to each others.

    For example, let's say I have these 2 properties :

    [NinjaScriptProperty]
    [Display(Name="Use value 1 ?", Order=1, GroupName="Value Set Up")]
    public bool IsValue1Used
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Your value 1 :", Order=2, GroupName="Value Set Up")]
    public int value1
    { get; set; }

    I would like to be able to do make the property "value1" visible in the parameters window only when the user click on the "IsValue1Used" property check box.

    __________________________________________________ ___________

    And, secondly, let's say I have these 2 properties :

    [NinjaScriptProperty]
    [Display(Name="Choice 1", Order=1, GroupName="Choice")]
    public bool IsChoice1
    { get; set; }

    [NinjaScriptProperty]
    [Display(Name="Choice 2", Order=2, GroupName="Choice")]
    public bool IsChoice2
    { get; set; }

    I would like to have only one check box ticked at a time. Meaning that if the user check the Choice1, and then check the Choice 2 : the Choice1 will automatically be unchecked.

    Is that all possible ?

    Thanx in advance for your support.
    Last edited by thanajo; 05-04-2021, 02:15 AM.

    #2
    Hello thanajo,

    These items are possible by using a type converter. There is an existing sample that shows how to set up a visibility toggle like the first item you described.

    The second item could be controlled either in the type converter by using property descriptors or also by using logic in the get set of the properties. I have attached a sample of the second item.

    https://ninjatrader.com/support/help...r_to_custo.htm


    Code:
    private bool isChoice1;
    private bool isChoice2;
    [RefreshProperties(RefreshProperties.All)]
    [NinjaScriptProperty]
    [Display(Name = "Choice 1", Order = 1, GroupName = "Choice")]
    public bool IsChoice1
    {
        get
       {
          return isChoice1;
       }
       set
       {
          if (value == true)
          {
             IsChoice2 = false;
          }
          isChoice1 = value;
        }
    }
    
    [RefreshProperties(RefreshProperties.All)]
    [NinjaScriptProperty]
    [Display(Name = "Choice 2", Order = 2, GroupName = "Choice")]
    public bool IsChoice2
    {
       get
       {
          return isChoice2;
       }
       set
       {
          if (value == true)
          {
             IsChoice1 = false;
          }
          isChoice2 = value;
       }
    }

    I look forward to being of further assistance.

    Comment


      #3
      Wonderful ! Thank you very much for this reply.

      Comment


        #4
        Hello Jesse,

        I use the code you provided and I got my ninjatrader Cashed...

        I have 3 properties that I would want to implement this true/false conditions


        Here my Code, what I did wrong?

        Code:
        [RefreshProperties(RefreshProperties.All)]
        [NinjaScriptProperty]
        [Display(Name="Active ReversalPattern / Activar Estrategia ReversalPattern", Description="How Many Trades System will Enter / Cuántas operaciones se realizarán", Order=1, GroupName="2. Strategy Type / Tipo de Estrategia")]
        public bool ReversalPattern
        {
        get
        {
        return ReversalPattern;
        }
        set
        {
        if (value == true)
        {
        EngulfingBar = false;
        TimeRange = false;
        }
        ReversalPattern = value;
        }
        }
        
        [RefreshProperties(RefreshProperties.All)]
        [NinjaScriptProperty]
        [Display(Name="Active Engulfing Bar Strategy / Activar Estrategia Vela Envolvente", Description="How Many Trades System will Enter / Cuántas operaciones se realizarán", Order=1, GroupName="2. Strategy Type / Tipo de Estrategia")]
        public bool EngulfingBar
        {
        get
        {
        return EngulfingBar;
        }
        set
        {
        if (value == true)
        {
        ReversalPattern = false;
        TimeRange = false;
        }
        EngulfingBar = value;
        }
        }
        
        [RefreshProperties(RefreshProperties.All)]
        [Display(Name="Active Time Range Strategy / Activar Estrategia Rango Horario", Description="How Many Trades System will Enter / Cuántas operaciones se realizarán", Order=1, GroupName="2. Strategy Type / Tipo de Estrategia")]
        public bool TimeRange
        {
        get
        {
        return TimeRange;
        }
        set
        {
        if (value == true)
        {
        EngulfingBar = false;
        ReversalPattern = false;
        }
        TimeRange = value;
        }
        }



        Thanks!!!

        Comment


          #5
          Hi, I solve the problem:

          The main issue in the code was that it resulted in an infinite loop of property calls when attempting to set their values. This occurred because the same variable was used to both store the value and access the property's value. For instance, in the ReversalPattern property's set method, the value was assigned directly to ReversalPattern, effectively triggering an infinite loop as it recursively called itself. To resolve this, private variables were introduced to store the property values, preventing the recursive calls and resolving the issue.

          Code:
          [RefreshProperties(RefreshProperties.All)]
                  [NinjaScriptProperty]
                  [Display(Name="Active ReversalPattern / Activar Estrategia ReversalPattern", Description="How Many Trades System will Enter / Cuántas operaciones se realizarán", Order=1, GroupName="2. Strategy Type / Tipo de Estrategia")]
                  public bool ReversalPattern
                  {
                      get
                      {
                          return _reversalPattern;
                      }
                      set
                      {
                          if (value == true)
                          {
                              EngulfingBar = false;
                              TimeRange = false;
                          }
                          _reversalPattern = value;
                      }
                  }
                  
                  [RefreshProperties(RefreshProperties.All)]
                  [NinjaScriptProperty]
                  [Display(Name="Active Engulfing Bar Strategy / Activar Estrategia Vela Envolvente", Description="How Many Trades System will Enter / Cuántas operaciones se realizarán", Order=1, GroupName="2. Strategy Type / Tipo de Estrategia")]
                  public bool EngulfingBar
                  {
                      get
                      {
                          return _engulfingBar;
                      }
                      set
                      {
                          if (value == true)
                          {
                              ReversalPattern = false;
                              TimeRange = false;
                          }
                          _engulfingBar = value;
                      }
                  }
                  
                  [RefreshProperties(RefreshProperties.All)]
                  [Display(Name="Active Time Range Strategy / Activar Estrategia Rango Horario", Description="How Many Trades System will Enter / Cuántas operaciones se realizarán", Order=1, GroupName="2. Strategy Type / Tipo de Estrategia")]
                  public bool TimeRange
                  {
                      get
                      {
                          return _timeRange;
                      }
                      set
                      {
                          if (value == true)
                          {
                              EngulfingBar = false;
                              ReversalPattern = false;
                          }
                          _timeRange = value;
                      }
                  }​


          Maybe helps someone here.

          Regards,
          TN

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          38 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          64 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 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