Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there a built in way to use Price Types as an enum in the object's constructor?

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

    Is there a built in way to use Price Types as an enum in the object's constructor?

    Howdy.

    I know I can create an enum myself to allow user selection of different price types, where I would just use a switch or a series of IF statements to select between the different price types...

    But I'm asking is there a built in way, when declaring an Object Constructor in the properties section for example, I.e., the way you define user inputs... if there is a built in way to do this w/o creating the enums myself?

    Thanks!

    #2
    Hello forrestang,

    User inputs would be generated by making a public property, you could make a public PriceType property to make a user input for that.

    Code:
    public PriceType MyPriceType {get;set;}
    If you also wanted this to be part of the indicators parameters when you call it from code you could add the NinjaScriptPropertyAttribute to it https://ninjatrader.com/support/help...criptAttribute

    I look forward to being of further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello forrestang,

      User inputs would be generated by making a public property, you could make a public PriceType property to make a user input for that.

      Code:
      public PriceType MyPriceType {get;set;}
      If you also wanted this to be part of the indicators parameters when you call it from code you could add the NinjaScriptPropertyAttribute to it https://ninjatrader.com/support/help...criptAttribute

      I look forward to being of further assistance.
      Thanks for this!

      Comment


        #4
        Howdy.. I have one more question.... and it is about inserting this captured value into an indicator, like an SMA for example. It seems simple but just doesn't quite work.

        So to run through the program with the essential bits....

        I have at the class level declared a variable as such:
        Code:
        public class SessionMovingAverage : Indicator
        {
            //Input Vars
                private PriceType myPriceType = PriceType.Close;
            ............

        All the way at the bottom, I created an object constructor as such:
        Code:
        [NinjaScriptProperty]
        [Display(Name="Price Type", Description="Used Price", Order=8, GroupName="Parameters")]
        public PriceType MyPriceType
        {
            get {return myPriceType;}
            set {myPriceType = value;}
        }

        Now, this does create the User Input as I want, and I can switch, and works just fine.

        In the script, I am trying to take this price value, and insert it into an SMA like so:
        Code:
            //MyMA1[0] = SMA(Typical,barCnt1)[0];     //[COLOR=#e74c3c]<---Manually inputting works just fine[/COLOR]
            MyMA1[0] = SMA(myPriceType,barCnt1)[0];   //[COLOR=#e74c3c]<---Doing this does not work[/COLOR]
            Print(Time[0] + " " + myPriceType);
        The above is just creating an SMA, with the price type, and the barCnt1 var is simply a length taken from elsewhere.

        So the question is, how do I insert the captured price type into that SMA? As you see in the above snippet above, I can print out the variable, and it prints out the expected value of "Close, High, Low, etc" of whatever I set it to in the user input screen.
        Last edited by forrestang; 09-30-2021, 08:32 AM.

        Comment


          #5
          Thinking about this more...

          I guess the input to the SMA indicator has to be a dataseries, where the PriceType variable is a pricetype.

          For example, the following works because Input represents a data series containing whatever the user input data series is for the indicator:
          Code:
          MyMA1[0] = SMA(Input,barCnt1)[0];
          So it seems, I would need a way to initialize a dataseries, with the value of the priceseries.. and wanting to do this without creating a bunch of conditional logic

          Comment


            #6
            Hello forrestang,

            The PriceType is an enum so that specifically could not be passed to the indicator, you could instead use that enum as a condition and pass the various series to the indicator depending on the price type.

            Code:
            SMA mySma = SMA(12);
            if(MyPriceType == PriceType.Median)
            {
                mySma = SMA(Median, 12);
            }
            The alternative would be to pass Input as you had shown but only if the script you created is also getting input from a series by being called by another script. You would otherwise use a condition like above if you wanted to make your script choose which series the indicator gets.


            I look forward to being of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            571 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            331 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
            549 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            550 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X