Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

enum as input parameter + event ?

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

    enum as input parameter + event ?

    Hello
    I can't find in strategy builder parameters option the enum.
    How to create it ?
    I found this sample https://forum.ninjatrader.com/forum/...pe-enum?t=3420 but the traitment of the option is into the "loop" and i would like to do it outside to do it only one time so I would like create an event when selected item change. Is it possible in c# ok but in a NT8 indicator ???
    A litle sample please, if it is possible...
    Thank you for your help​

    #2
    Hello bicou,

    Thank you for writing in.

    Due to the limitations of the Strategy Builder, an enum as an input parameter would only be available in an unlocked script in the NinjaScript Editor. The sample you have linked does not use a loop; it uses a switch statement with different cases based on the different enum options available. Switch statements are a general C# concept and are not specific to NinjaScript. For more information, please see the following publicly available link:
    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


    You mentioned you would like to, "do it only one time so I would like create an event when selected item change." What selected item are you referring to, and what kind of event would you like to happen when that item changes? Please provide an example or explanation of what your use case is and what you would like to be able to do in your script so I may better assist you.

    I look forward to your reply.

    Comment


      #3
      Thank you for your reply.
      Indeed, the term "loop" is wrong, I meant in the "OnBarUpdate()".
      I'm actually referring to the "onChange" when selecting an entry in the enum.
      The idea is to run the "switch" only once and store the result in a global variable so that it can be used anywhere in the "OnBarUpdate()" without any testing.
      Thank you for your help​

      Comment


        #4
        Hello bicou,

        Thank you for your reply.

        The following snippet is from lines 33 and 34 of the SampleUniversalMovingAverage script:
        Code:
                // Create a variable that stores the user's selection for a moving average
                private UniversalMovingAverage    maType    = UniversalMovingAverage.SMA;
        ​
        We can also see the following in the properties of the script:
        Code:
                // Creates the user definable parameter for the moving average type.
                [Display(GroupName = "Parameters", Description="Choose a Moving Average Type.")]
                public UniversalMovingAverage MAType
                {
                    get { return maType; }
                    set { maType = value; }
                }
        ​
        What this does is saves the enum selection from the indicator properties to the variable maType. You can use the maType variable in OnBarUpdate() without having to do the switch statement. The switch statement is simply there to execute logic that varies depending on which maType is selected. You could do something as simple as add a print statement to OnBarUpdate() that will tell you the maType selected such as the following:
        Code:
                    Print("The selected MA type is: " + maType);
        ​
        If you then go to the indicator properties and change the enum to a different value, the script will be reloaded and your print statement will reflect the change in selection.

        I hope this helps to clarify and address your question. Please let us know if we may be of further assistance.

        Comment


          #5
          Thank you, I understand, it's very clear.
          I tend to want to "reinvent the wheel"...​

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X