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

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.
    JesseNinjaTrader Customer Service

    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 andrewtrades, Today, 04:57 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          6 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X