Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Property

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

    Strategy Property

    Is it possible to create a custom property for a strategy and provide a list of values for the dropdown menu?
    Attached Files

    #2
    Hello RiversideDude,

    Thanks for your post.

    Yes, you can create custom properties and a drop down of selectable choices (enum). Here are some references in our tips section:

    http://ninjatrader.com/support/forum...ead.php?t=5782
    http://ninjatrader.com/support/forum...ead.php?t=4770

    For creating an enum to provide the dropdown, you can find two examples in this NT8 indicator in the forums: http://ninjatrader.com/support/forum...d=7&linkid=682

    (Note: Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No')
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      How would I do this for string values in NT 8?

      Thanks!!

      Comment


        #4
        Hello RiversideDude,

        Can you provide an example of what you are wanting to do?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I would like to add a property "Strategy Type" to my strategy with the following values:

          Breakeven
          Manual
          Trail

          This changes the logic of how my strategy will function. I would rather use strings instead of integers, if possible.

          Thanks!!
          Last edited by RiversideDude; 03-15-2017, 01:52 PM.

          Comment


            #6
            Hello RiversideDude,

            Thanks for your reply.

            You can use an enum for this. Please review the code of the indicator I provided in the previous post.
            The first thing you will see is the enum D3SpotIndicatorMethod with a list of names of indicators. In the OnBarUpdate() you will see a switch statement that reacts based on what the user selected (Method). The user selection is provided in the public D3SpotIndicatorMethod Method in the region Properties.

            You would be able to implement in the same way and have the drop down selectable.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thank you, thank you!!

              Comment


                #8
                Using enum Types to create Dropdown List for Strategies/Indicators

                Here's what I did to obtain an dropdown list of string values for properties for a strategy. (Rather than having to download the above indicator zip).

                1. Declare an enum type for your property at the class level. I think this needs to be declared public.
                2. In the Properties section of your code simply use the enum type instead of an int or string, for example.

                It is really that simple.

                For the example requested by RiversideDude:
                Code:
                namespace NinjaTrader.NinjaScript.Strategies
                {
                    public class MyWinningStrategy : Strategy
                    {
                        
                        public enum MyStopType {Breakeven, Manual, Trail};
                
                        // more declarations
                        protected override void OnStateChage() {...}
                        protected override void OnBarUpdate() {...}
                
                        #region Properties
                
                        [NinjaScriptProperty]
                        [Display(Name="StopLossType", Description="Type to Stop Losss", Order=2, GroupName="Trade Parameters")]
                        public MyStopType StopLossType
                        { get; set; }
                
                        #endregion
                }

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by MaybellMcKee, Today, 10:18 PM
                0 responses
                3 views
                0 likes
                Last Post MaybellMcKee  
                Started by Lance El Camino, Today, 04:14 PM
                1 response
                12 views
                0 likes
                Last Post s.kinra
                by s.kinra
                 
                Started by jtrading82, Today, 04:56 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_ShawnB  
                Started by dmking, Today, 06:00 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_EricB  
                Started by WHICKED, Today, 03:23 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X