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

Referencing an indicator with an enum

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

    Referencing an indicator with an enum

    I have an indicator called 'jhlMA' which allows the choice of several moving average methods via an 'enum' and a 'switch'.

    Say, for example, I want to reference this indicator within a strategy or another indicator's NinjaScript. I know with a standard SMA I would use:

    Code:
    double simple = SMA(Input,20)[0];
    The jhlMA includes an 'enum' and a 'switch', the enum is below:

    Code:
    public enum MAType 
    
    		{
    		EMA,
    		JMA,
    		HMA,
    		LinReg,
    		MMA,
    		SMA,
    		TMA,
    		WMA,
    		McGinleyDynamic,
    		Butterworth2,
    		Butterworth3
    		}
    So when I reference this in my strategy/indicator I need to say:

    Code:
    double whatever = jhlMA(??????,int period)[0];
    It wants me to input the enum method where the '??????' is.

    I assume it wants 'MAType' but I'm not sure about the correct syntax to use:

    Code:
    double whatever = jhlMA(MAType(),int period)[0]; //???
    double whatever = jhlMA(jhlMA.MAType,int period)[0]; //???
    double whatever = jhlMA(MAType(),int period)[0]; //???
    I've tried but I can't work it out. I have several of these to reference so to get this one under my belt would be great. Thanks in advance
    Attached Files

    #2
    Welcome to our forums - have you tried MAType.SMA for example for the call?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      It seems to want either of these statements instead if I allow intellisense to help me:

      Code:
      double myjhl = JHL.Utility.MA.construct(MAType type, int period)
      double myjhl = JHL.Utility.MAType.SMA
      I am still fairly new to C# but I have a basic idea of classes, objects and instances.

      "JHL.Utility" is the namespace. "JHL.Utility.MA" is the class.
      I have a feeling that 'JHL.Utility.MAType.SMA' should be placed where MAType is:

      Code:
      double myjhl = JHL.Utility.MA.construct(JHL.Utility.MAType.SMA,20);
      On trying this I get error CS0029 "Cannot implicitly convert JHL.Utility.MA to double".

      I assume this means an 'override' [0] needs to be placed in here somewhere. Am I close?

      I still get a little confused with C# "calling". Thanks again.

      Comment


        #4
        Okay. I think I've missed some important code. I copied from another indicator's ideas and I did this:

        I added this to the variable section

        Code:
        private jhlMA myjhl;
        OnStartUp() section

        Code:
        //myjhl = jhlMA(JHL.Utility.MAType.SMA,20);
        OnBarUpdate() section

        Code:
        Value.Set(myjhl[0]);
        I'm getting a plot, but it's "0". This might be due to the jhlMA throwing a "Null" at startup error. So going with this code, does this look right. I'm sorry for the confusion.

        Comment


          #5
          Sim22, thanks for the follow up, but reviewing this further I think you're missing code actually here - with the cs you posted you're just having the one supplying the utility methods but not the main SMA / average logic to build on. Best would be perhaps getting in touch with the original author, as I don't think the usage was meant this way.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thanks Bertrand,

            I actually chose this indicator as an example to get help for enumerations. I actually have at least a couple of other indicators of my own in which to reference but don't know how to do it. However, I will get in touch with the author as you suggested. Cheers.

            Comment


              #7
              Right, and I don't think the enum call is the issue here - the utility code itself as is would not be sufficient to make this work.

              For working with enums generally, this sample would be helpful - http://www.ninjatrader.com/support/f...ead.php?t=3420
              BertrandNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Barry Milan, Yesterday, 10:35 PM
              5 responses
              16 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by DanielSanMartin, Yesterday, 02:37 PM
              2 responses
              13 views
              0 likes
              Last Post DanielSanMartin  
              Started by DJ888, 04-16-2024, 06:09 PM
              4 responses
              12 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by terofs, Today, 04:18 PM
              0 responses
              11 views
              0 likes
              Last Post terofs
              by terofs
               
              Started by nandhumca, Today, 03:41 PM
              0 responses
              8 views
              0 likes
              Last Post nandhumca  
              Working...
              X