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

Enumeration private scope impossible with "Properties" and Ninja generated Code

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

    Enumeration private scope impossible with "Properties" and Ninja generated Code

    Hello,

    Can anyone pls explain how I can define an C# enum to use as a property to select a value when I attach the indicator to the chart, yet limit the scope of the enum to be private and not public.

    For example I want to define an C# enum as:
    public enum enum_TradeTypes { Buy = 1, Sell= 2 }

    and later select Buy or Sell from properties with I load the indicator.

    My problem is, that I must define the scope as "public" and above and outside the scope of statement ...
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator

    Otherwise I get this compile error in section namespace NinjaTrader.MarketAnalyzer ...
    "The type or namespace name 'enum_TradeTypes' could not be found (are you missing a using directive or an assembly reference?)"

    However, when I do define 'enum_TradeTypes' above and outside the scope of 'namespace NinjaTrader.Indicator', it will compile and execute OK, BUT the scope of the enum is so public that it is now available for ALL indicators in Ninjatrader to use and code with.

    Basically I want to define C# structures to use in indicators/strategies, available for 'property' selection BUT have a scope that is 'private' to the indicator/strategy and not 'public' to all of namespace NinjaTrader.Indicator.

    Thank you

    #2
    I found this link and it explain the solution.... Thanks

    Comment


      #3
      Hello rayko,

      This is all going to be dependent on where you are declaring it inside of NinjaScript. If you define it outside of the "public class <IndicatorName> : Indicator" then it will have to be declared as public but if you declare it inside of this then you may set this to private so it can only be accessed from this particular Indicator.

      For example:

      Code:
      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
              // Will be accessible any Indicators or Strategies that include the "namespace Indicator"
      	public enum PublicEnum { Test11, Test22, }
      
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          [Description("Enter the description of your new custom indicator here")]
          public class TestEnum : Indicator
          {
                      // Will only be accessible inside of this "TestEnum" indicator
      		private enum privateEnum { Test1, Test2,}
      			
      		privateEnum Testing;
      		PublicEnum Testing2;
      
                      protected override void OnBarUpdate()
                      {
                              //Do something
                      }
             }
      }
      Let me know if you have any questions.
      JCNinjaTrader Customer Service

      Comment


        #4
        Originally posted by rayko View Post
        Hello,

        Can anyone pls explain how I can define an C# enum to use as a property to select a value when I attach the indicator to the chart, yet limit the scope of the enum to be private and not public.

        For example I want to define an C# enum as:
        public enum enum_TradeTypes { Buy = 1, Sell= 2 }

        and later select Buy or Sell from properties with I load the indicator.

        My problem is, that I must define the scope as "public" and above and outside the scope of statement ...
        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator

        Otherwise I get this compile error in section namespace NinjaTrader.MarketAnalyzer ...
        "The type or namespace name 'enum_TradeTypes' could not be found (are you missing a using directive or an assembly reference?)"

        However, when I do define 'enum_TradeTypes' above and outside the scope of 'namespace NinjaTrader.Indicator', it will compile and execute OK, BUT the scope of the enum is so public that it is now available for ALL indicators in Ninjatrader to use and code with.

        Basically I want to define C# structures to use in indicators/strategies, available for 'property' selection BUT have a scope that is 'private' to the indicator/strategy and not 'public' to all of namespace NinjaTrader.Indicator.

        Thank you
        If you want to expose the enum instance as a property, you must declare the enum public. Use a custom namespace to restrict access to the enum.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Kaledus, Today, 01:29 PM
        0 responses
        3 views
        0 likes
        Last Post Kaledus
        by Kaledus
         
        Started by PaulMohn, Today, 12:36 PM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by yertle, Yesterday, 08:38 AM
        8 responses
        37 views
        0 likes
        Last Post ryjoga
        by ryjoga
         
        Started by rdtdale, Today, 01:02 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by alifarahani, Today, 09:40 AM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X