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

How To Set One Parameter To False if Another is Set To True

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

    How To Set One Parameter To False if Another is Set To True

    Hello,

    I have two input parameters in my strategy of type bool which the user may change.

    If one of the parameters is set to 'true', the other should automatically be forced to 'false'.

    Any help on the syntax would be greatly appreciated!

    Many thanks!

    #2
    Hello MercuryScripter,

    Thank you for your inquiry.

    You could do this by using an IF, ELSE IF like so:

    Code:
    [FONT="Courier New"]if (boolean1)
    {
    boolean2 = false;
    }
    else if (boolean2)
    {
    boolean1 = false;
    }[/FONT]
    Please, let us know if we can be of further assistance!
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ZacharyG View Post
      Hello MercuryScripter,

      Thank you for your inquiry.

      You could do this by using an IF, ELSE IF like so:

      Code:
      [FONT="Courier New"]if (boolean1)
      {
      boolean2 = false;
      }
      else if (boolean2)
      {
      boolean1 = false;
      }[/FONT]
      Please, let us know if we can be of further assistance!
      Hello, thank you. This is what I am doing and it is not working. I must be putting the conditional in the wrong location. Would you kindly suggest where I should put the code? Also, these values may be toggled from a chart toolbar generated by the strategy; so while the strategy is enabled, these values may be toggled which is why I am not sure putting it in under onstartup would work.

      Code:
      private bool iBool1 = true;
      [Description("")]
      [GridCategory("\tLogistics")]
      [NinjaTrader.Gui.Design.DisplayName ("1. Parameters")]
             public bool Bool1
              {
                 get { return iBool1; }
      	   set { iBool1 = value;}
              }
      	if (Bool1) {Bool2 = false;}
      
      private bool iBool2 = true;
      [Description("")]
      [GridCategory("\tLogistics")]
      [NinjaTrader.Gui.Design.DisplayName ("1. Parameters")]
             public bool Bool2
              {
                 get { return iBool2; }
      	   set { iBool2 = value;}
              }
      	if (Bool2) {Bool1 = false;}
      Last edited by MercuryScripter; 05-27-2015, 08:38 AM.

      Comment


        #4
        Hello MercuryScripter,

        Because you'd like this logic to run more than one time, put it under your OnBarUpdate() method. Be sure it's the first block of code before your other logic in there.

        Code:
        [FONT="Courier New"]protected override void OnBarUpdate()
        {[INDENT]if (boolean1)
        {[INDENT]boolean2 = false;[/INDENT]
        }
        else if (boolean2)
        {[INDENT]boolean1 = false;[/INDENT]
        }[/INDENT]
        ...
        }[/FONT]
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ZacharyG View Post
          Hello MercuryScripter,

          Because you'd like this logic to run more than one time, put it under your OnBarUpdate() method. Be sure it's the first block of code before your other logic in there.

          Code:
          [FONT="Courier New"]protected override void OnBarUpdate()
          {[INDENT]if (boolean1)
          {[INDENT]boolean2 = false;[/INDENT]
          }
          else if (boolean2)
          {[INDENT]boolean1 = false;[/INDENT]
          }[/INDENT]
          ...
          }[/FONT]
          Thanks Zach. Is it possible that I can link the user inputs somehow so that inside of the strategy settings window if I set one value to true, the other automatically switches to false?

          Comment


            #6
            EDITED: Ensure that bool1 = value; and bool2 = value; are still in the setter methods as well! Code edited below.

            Hello MercuryScripter,

            You would be able to do this in your setter methods for your Properties.

            For example:

            Code:
            [FONT="Courier New"]public bool Bool1
            {[INDENT]get { return bool1; }
            set { bool1 = value;
             if (bool2) bool1 = false; }[/INDENT]
            }
            
            ...
            
            public bool Bool2
            {[INDENT]get { return bool2; }
            set { bool2 = value;
            if (bool1) bool2 = false; }[/INDENT]
            }[/FONT]
            Please, let us know if we may be of further assistance!
            Last edited by NinjaTrader_ZacharyG; 05-27-2015, 10:18 AM.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ZacharyG View Post
              Hello MercuryScripter,

              You would be able to do this in your setter methods for your Properties.

              For example:

              Code:
              [FONT="Courier New"]public bool Bool1
              {[INDENT]get { return bool1; }
              set { if (bool2) bool1 = false; }[/INDENT]
              }
              
              ...
              
              public bool Bool2
              {[INDENT]get { return bool2; }
              set { if (bool1) bool2 = false; }[/INDENT]
              }[/FONT]
              Please, let us know if we may be of further assistance!
              Thanks Zach. Actually this is very close, however, this implementation locks both fields at their originally set values and does not allow for user toggle.
              Last edited by MercuryScripter; 05-27-2015, 10:21 AM.

              Comment


                #8
                Hello MercuryScripter,

                You are unable to change strategy parameters once a strategy is running; if you'd like to change the parameters, you would have to disable the strategy first before you can change anything.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ZacharyG View Post
                  Hello MercuryScripter,

                  You are unable to change strategy parameters once a strategy is running; if you'd like to change the parameters, you would have to disable the strategy first before you can change anything.
                  Hello Zach, right. I am unable to change the parameters within a disabled strategy using implementation suggestion which you provided.
                  Last edited by MercuryScripter; 05-27-2015, 10:58 AM.

                  Comment


                    #10
                    Hello MercuryScripter,

                    Here is the code for you to handle that:

                    Code:
                    [FONT="Courier New"]public bool Bool1
                    {[INDENT]get { return bool1; }
                    set { bool1 = value;
                    if (value == true) bool2 = false; }[/INDENT]
                    }
                    
                    ...
                    
                    public bool Bool2
                    {[INDENT]get { return bool2; }
                    set { bool2 = value; 
                    if (value == true) bool1 = false; }[/INDENT]
                    }[/FONT]
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you Zach! This is perfect! Exactly what I was looking for! Really appreciate your help!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Barry Milan, Yesterday, 10:35 PM
                      5 responses
                      16 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by DanielSanMartin, Yesterday, 02:37 PM
                      2 responses
                      13 views
                      0 likes
                      Last Post DanielSanMartin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      4 responses
                      13 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by terofs, Today, 04:18 PM
                      0 responses
                      11 views
                      0 likes
                      Last Post terofs
                      by terofs
                       
                      Started by nandhumca, Today, 03:41 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post nandhumca  
                      Working...
                      X