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

Creating DropDown Box in Parameters

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

    Creating DropDown Box in Parameters

    Hello

    I am trying to create a drop down box in the parameters. I have referenced http://www.ninjatrader.com/support/f...ad.php?t=44719 but don't know that I am acquiring all of the necessary information

    In the box, I want to have the options for "No Trend" "Up" & "Down". This user defined variable will then be used int the strategy in order to tell the strategy in which direction to trade.

    Here is the code in question:

    Variables:
    Code:
     #region Variables
    
    		private string trendDirection = noTrend; // holds direction of trend to determine direction of trade
    		private string noTrend; // user defined stating no trend
    		private string up; // user defined stating Up Trend 
    		private string down; // user defied stating Down Trend
            #endregion
    Here is my "switch" code. Currently does not have any logic written in

    Code:
     protected override void OnBarUpdate()
            {
    			switch (trendDirection)
    			{
    				case trendDirection = noTrend:
    				{}
    				
    				case trendDirection = up:
    				{}
    				
    				case trendDirection = down:
    				{}
    			
    			}
    		}
    And here is the code for the bit of the properties that may be in question:
    Code:
            #region Properties
    		[Description("Direction")]
    		[GridCategory("Parameters")]
    		public string Direction
    		{
    			get { return trendDirection; }
    			set { trendDirection = value; }
    		}
    The list of errors that I am getting are:
    "Field initializer cannot reference the non-static field, method, or property..."
    "A Constant Value is Expected" (3x)

    Would you be able to help me fix these errors in order to get a proper drop down menu in the properties with those 3 parameters?

    Thank you for your help

    #2
    Hello jg123,

    I have compiled an example of using an Enum for a dropdown in an Indicator.
    This will allow you to use the dropdown and I have demonstrated how to use the Enum in an IF statement.
    I have attached the .cs file to this post for your reference.


    Code:
    namespace NinjaTrader.Indicator
    {
        [Description("Enter the description of your new custom indicator here")]
        public class EnumExample : Indicator
        {
    	private TrendDirection direction = TrendDirection.NoTrend;
    		
            protected override void Initialize()
            {
                Overlay				= false;
            }
            protected override void OnBarUpdate()
            {
    			if(direction == TrendDirection.Up)
    				Print("Up");
    			else if(direction == TrendDirection.Down)
    				Print("Down");
    			else if(direction == TrendDirection.NoTrend)
    				Print("no Trend");
            }
    		
    		#region Properties
    		
    		[Description ("")]
    		[GridCategory ("Parameters")]
    		[Gui.Design.DisplayName ("Strategy")]
    		public TrendDirection Direction {
    			get { return direction; }
    			set { direction = value; }
    		}
    		
    		#endregion
        }
    }
    
    public enum TrendDirection
    {
    	NoTrend,
    	Up,
    	Down
    }
    Please let me know if I may be of additional assistance.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse

      I noticed that this is an indicator. Does it work just the same if I code it in my strategy?

      Comment


        #4
        Hello jg123,

        Yes this would be identical in a Strategy.

        One note about the provided example, If you have imported the example and use the exact same public Enum in a strategy you will get an error stating it already exists in the namespace.

        Please make sure to change the name of the public items or remove the example i provided before copying that code into a strategy.

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          What purpose does Overlay serve in your example?

          Are there differences in using Overlay between an indicator and strategy?

          Comment


            #6
            Hello bltdavid,

            The Overlay setting is for indicators to tell the indicator that it has to either overlay on the chart or not

            Overlay should not be available to use in the Strategy base as this is a indicator base item.

            Here is a link to the help guide reference on Overlay


            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks, when I tried to use Overlay in a strategy, I quickly figured that out.

              Sometimes the Ninja documentation is not as clear or obvious as it could be.

              Overlay, for example, is specific to the Indicator class, but the documentation never states that simple but important detail in a plain way.

              Comment


                #8
                Ah-hah, I just realized something even further ...

                (slaps forehead)

                Everything documented under the Indicator section of the help guide is for the Indicator class.
                Likewise for the Strategy section of the help guide.

                Doh, that's why the documentation does not "plainly" say it is specific to Indicators, it is a Property of the base Indicator class, which is inferred by it's location under the Indicator section of the help guide. It's plain just by where it's located.

                I'll be darned, I just realized this context relationship in the help guide is pretty important. It's not just an organization table of contents easy-to-find kind of thing, it's a real programming relationship thing.

                I take back my earlier critique of Overlay documentation, it's perfectly fine.

                Comment


                  #9
                  Wow, I spend an entire day looking through this forum and the web for a way to create user defined dropdown with my own words in a Strategy.. and finally found this. Thank you Thank you!

                  Originally posted by NinjaTrader_Jesse View Post
                  Hello jg123,

                  I have compiled an example of using an Enum for a dropdown in an Indicator.
                  This will allow you to use the dropdown and I have demonstrated how to use the Enum in an IF statement.
                  I have attached the .cs file to this post for your reference.


                  Code:
                  namespace NinjaTrader.Indicator
                  {
                      [Description("Enter the description of your new custom indicator here")]
                      public class EnumExample : Indicator
                      {
                  	private TrendDirection direction = TrendDirection.NoTrend;
                  		
                          protected override void Initialize()
                          {
                              Overlay				= false;
                          }
                          protected override void OnBarUpdate()
                          {
                  			if(direction == TrendDirection.Up)
                  				Print("Up");
                  			else if(direction == TrendDirection.Down)
                  				Print("Down");
                  			else if(direction == TrendDirection.NoTrend)
                  				Print("no Trend");
                          }
                  		
                  		#region Properties
                  		
                  		[Description ("")]
                  		[GridCategory ("Parameters")]
                  		[Gui.Design.DisplayName ("Strategy")]
                  		public TrendDirection Direction {
                  			get { return direction; }
                  			set { direction = value; }
                  		}
                  		
                  		#endregion
                      }
                  }
                  
                  public enum TrendDirection
                  {
                  	NoTrend,
                  	Up,
                  	Down
                  }
                  Please let me know if I may be of additional assistance.

                  Comment


                    #10
                    Check this out, hope it helps.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ETFVoyageur, Today, 07:05 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post ETFVoyageur  
                    Started by Orion815, 05-02-2024, 08:39 AM
                    2 responses
                    18 views
                    0 likes
                    Last Post Orion815  
                    Started by suroot, 02-25-2017, 04:43 AM
                    11 responses
                    2,552 views
                    0 likes
                    Last Post Zilvercat  
                    Started by Rogers101, 05-05-2024, 11:30 AM
                    16 responses
                    50 views
                    0 likes
                    Last Post Rogers101  
                    Started by ninza33, Today, 12:31 PM
                    2 responses
                    12 views
                    0 likes
                    Last Post ninza33
                    by ninza33
                     
                    Working...
                    X