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

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
                    {
                        
                        [B]public enum MyStopType {Breakeven, Manual, Trail};[/B]
                
                        // 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 [B]MyStopType [/B]StopLossType
                        { get; set; }
                
                        #endregion
                }

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by swestendorf, Today, 11:14 AM
                2 responses
                5 views
                0 likes
                Last Post NinjaTrader_Kimberly  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                4 responses
                12 views
                0 likes
                Last Post xiinteractive  
                Started by Mupulen, Today, 11:26 AM
                0 responses
                1 view
                0 likes
                Last Post Mupulen
                by Mupulen
                 
                Started by Sparkyboy, Today, 10:57 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by TheMarlin801, 10-13-2020, 01:40 AM
                21 responses
                3,917 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Working...
                X