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 thanajo, 05-04-2021, 02:11 AM
                3 responses
                469 views
                0 likes
                Last Post tradingnasdaqprueba  
                Started by Christopher_R, Today, 12:29 AM
                0 responses
                10 views
                0 likes
                Last Post Christopher_R  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                166 responses
                2,237 views
                0 likes
                Last Post sidlercom80  
                Started by thread, Yesterday, 11:58 PM
                0 responses
                4 views
                0 likes
                Last Post thread
                by thread
                 
                Started by jclose, Yesterday, 09:37 PM
                0 responses
                9 views
                0 likes
                Last Post jclose
                by jclose
                 
                Working...
                X