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

Enum is not available within another indicator/strategy

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

    Enum is not available within another indicator/strategy

    NOTE: Please see second post before reading all this code. Thank you!

    I am having trouble with referencing another indicator within a strategy because the "enum" is not recognized.....

    Here is the partial code of the primary indicator, one which allows to choose between a RSI or momentum plot:

    Variables section:

    Code:
    [COLOR="Blue"]private int[/COLOR] anyIndicatorPeriod = 5;
    [COLOR="blue"]private int[/COLOR] anyIndicatorSmooth = 1; 
    [COLOR="blue"]private int[/COLOR] zerovalue = 0;
    [COLOR="blue"]private[/COLOR] DataSeries AnyInd;
    [COLOR="blue"]private[/COLOR] zBMIndicatorMethodEnum zmyBMMethod = zBMIndicatorMethodEnum.MOM;
    AnyInd is initialized in Initialize()....

    Body section:

    Code:
    [COLOR="blue"]protected override void[/COLOR] OnBarUpdate() 
    		{	
    			[COLOR="blue"]switch[/COLOR] (zmyBMMethod) 
    				{
    				[COLOR="blue"]case[/COLOR] zBMIndicatorMethodEnum.RSI:
    				
    					AnyInd.Set(RSI(anyIndicatorPeriod,anyIndicatorSmooth)[0]);
    				
    				[COLOR="blue"]break[/COLOR];
    					
    				[COLOR="blue"]default[/COLOR]:
    
    					AnyInd.Set(Momentum(anyIndicatorPeriod)[0]);
    				
    				[COLOR="blue"]break[/COLOR];
    				}
    			
    			if (CurrentBar < anyIndicatorPeriod) [COLOR="blue"]return[/COLOR];
    			
    		       ZeroLine.Set(zerovalue);
    
                     }
    
    		[COLOR="blue"]public enum[/COLOR] zBMIndicatorMethodEnum [COLOR="SeaGreen"]//compiles when placed here [U]within[/U] "[COLOR="Blue"]namespace[/COLOR]" [/COLOR]
    		{
    			RSI,
    			MOM
    		}
    		
           
        }
    }
    [COLOR="SeaGreen"]//public enum zBMIndicatorMethodEnum //followed example in SampleUniversalMovingAverage and placed AFTER namespace but would not compile
    //{
    //	RSI,
    //			
    //	MOM,
    //}[/COLOR]
    With the above code it compiled and plotted and the "enum" worked as it should.

    So.... I tried accessing this indicator within a host strategy using "AnyInd" crossing above "ZeroLine" letting the NinjaTrader strategy wizard do the code for me.

    Code:
    if (CrossAbove(zzzskBMomentumtest(20, 1, NinjaTrader.Indicator.zzzskBMomentumtest[COLOR="Red"][B]+[/B][/COLOR]zBMIndicatorMethodEnum.RSI, 50).AnyInd, zzzskBMomentumtest(20, 1, NinjaTrader.Indicator.zzzskBMomentumtest[COLOR="red"][B]+[/B][/COLOR]zBMIndicatorMethodEnum.RSI, 50).ZeroLine, 1))
    When compiling this strategy NT says "The name 'zBMIndicatorMethodEnum' does not exist in the current context". It also suggests my indicator above is a "type", not vaild in the given context.

    Notice the "+" in the above code. When I add a "." here instead, the "enum" is not recognized by Intellisense.

    I am still confused about where to place the "public enum" in the indicator to be publically available to my host strategy. The SampleUniversalMovingAverage actually has the "public enum" outside of "namespace". Mine does not compile if I do this. I am simply a 'cut and paste' coder with an understanding of logic so maybe I am missing something so simple.

    I am in asian timezone so I may not get back to you until US evening.

    Thank you in advance

    Simon
    Attached Files
    Last edited by Sim22; 05-20-2014, 02:47 AM. Reason: Solved

    #2
    I just placed a "." in place of the "+" and the damn thing worked.

    So, this actually works now. However, I am still not sure as to where an "enum" should be placed, within or outside the "namespace"

    Would someone please clarify that for me.

    Comment


      #3
      Glad to hear you could fix that, for the enum placement the supported approach would be shown in this sample, it's placed outside the NT indicator namespace - http://www.ninjatrader.com/support/f...ead.php?t=3420
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Thanks Bertrand,

        however it won't compile if I place the enum outside of the namespace, below Properties.

        The error I get is CS0426:

        The type name 'zBMIndicatorMethodEnum' does not exist in the type 'NinjaTrader.Indicator.zzzskBMomentumtest'

        Comment


          #5
          Would you mind sending me what you have completed to far to support at ninjatrader dot com so I could give it a quick run on our end?

          Thanks,
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Okay, thanks Bertrand

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mattbsea, Today, 05:44 PM
            0 responses
            3 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            31 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Started by tkaboris, Today, 05:13 PM
            0 responses
            2 views
            0 likes
            Last Post tkaboris  
            Started by GussJ, 03-04-2020, 03:11 PM
            16 responses
            3,282 views
            0 likes
            Last Post Leafcutter  
            Started by WHICKED, Today, 12:45 PM
            2 responses
            20 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Working...
            X