Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Switch case

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

    Switch case

    Hello all.

    I'm looking to add a multiple parameter choice, using a scrolling windows.
    I tried with switch case:
    ===============================================
    public enum CaseType {Case1, Case2};

    protected override void Initialize()
    {
    ParameterSettings();
    }
    protected void ParameterSettings()
    {
    switch(Case_input)
    {
    case CaseType.Case1:
    Case_A = 50;
    break;
    case CaseType.Case2:
    Case_B = 60;
    break;

    }

    }

    Properties

    [Description("")]
    [Category("Parameters")]
    public CaseType Case_input
    {
    get { return caseType; }
    set { caseType = value;ParameterSettings(); }
    }
    ================================================== ======
    I always get the following error:
    The type or namespace name '<name>' could not be found (are you missing a using directive or an assembly reference?) with the row number specified.

    Is there something am I missing?
    Anybody can put me on th right way?

    Thanks.

    Max

    #2
    Please highlight the line of code in question. Thank you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      The code is between "=====".
      Do you have any examples on the matter?

      Thanks.

      Comment


        #4
        MAX,

        Please provide the exact line in question as referenced by the error message.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          This is the original code for the indicator:
          =========================================

          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          [Description("Enter the description of your new custom indicator here")]
          public class MyCaseSwitch : Indicator
          {
          public enum CaseType {Case1, Case2};
          #region Variables
          // Wizard generated variables
          // User defined variables (add any user defined variables below)
          private double Case_A = 0;
          private double Case_B = 0;
          #endregion

          /// <summary>
          /// This method is used to configure the indicator and is called once before any bar data is loaded.
          /// </summary>
          protected override void Initialize()
          {
          CalculateOnBarClose = true;
          Overlay = false;
          PriceTypeSupported = false;
          ParameterSettings();
          }
          protected void ParameterSettings()
          {
          switch(Case_input)
          {
          case CaseType.Case1:
          Case_A = 50;
          break;
          case CaseType.Case2:
          Case_B = 60;
          break;
          }
          }
          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.
          }

          #region Properties
          [Description("")]
          [Category("Parameters")]
          public CaseType Case_input
          {
          get { return caseType; }
          set { caseType = value;ParameterSettings(); }
          }
          #endregion
          }
          }

          #region NinjaScript generated code. Neither change nor remove.
          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          public partial class Indicator : IndicatorBase
          {
          private MyCaseSwitch[] cacheMyCaseSwitch = null;

          private static MyCaseSwitch checkMyCaseSwitch = new MyCaseSwitch();

          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          public MyCaseSwitch MyCaseSwitch(CaseType case_input)
          {
          return MyCaseSwitch(Input, case_input);
          }

          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          public MyCaseSwitch MyCaseSwitch(Data.IDataSeries input, CaseType case_input)
          {
          checkMyCaseSwitch.Case_input = case_input;
          case_input = checkMyCaseSwitch.Case_input;

          if (cacheMyCaseSwitch != null)
          for (int idx = 0; idx < cacheMyCaseSwitch.Length; idx++)
          if (cacheMyCaseSwitch[idx].Case_input == case_input && cacheMyCaseSwitch[idx].EqualsInput(input))
          return cacheMyCaseSwitch[idx];

          MyCaseSwitch indicator = new MyCaseSwitch();
          indicator.BarsRequired = BarsRequired;
          indicator.CalculateOnBarClose = CalculateOnBarClose;
          indicator.Input = input;
          indicator.Case_input = case_input;
          indicator.SetUp();

          MyCaseSwitch[] tmp = new MyCaseSwitch[cacheMyCaseSwitch == null ? 1 : cacheMyCaseSwitch.Length + 1];
          if (cacheMyCaseSwitch != null)
          cacheMyCaseSwitch.CopyTo(tmp, 0);
          tmp[tmp.Length - 1] = indicator;
          cacheMyCaseSwitch = tmp;
          Indicators.Add(indicator);

          return indicator;
          }

          }
          }

          // This namespace holds all market analyzer column definitions and is required. Do not change it.
          namespace NinjaTrader.MarketAnalyzer
          {
          public partial class Column : ColumnBase
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.MyCaseSwitch MyCaseSwitch(CaseType case_input)
          {
          return _indicator.MyCaseSwitch(Input, case_input);
          }

          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          public Indicator.MyCaseSwitch MyCaseSwitch(Data.IDataSeries input, CaseType case_input)
          {
          return _indicator.MyCaseSwitch(input, case_input);
          }

          }
          }

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          public partial class Strategy : StrategyBase
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.MyCaseSwitch MyCaseSwitch(CaseType case_input)
          {
          return _indicator.MyCaseSwitch(Input, case_input);
          }

          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          public Indicator.MyCaseSwitch MyCaseSwitch(Data.IDataSeries input, CaseType case_input)
          {
          if (InInitialize && input == null)
          throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

          return _indicator.MyCaseSwitch(input, case_input);
          }

          }
          }
          #endregion
          ================================================== ==========

          The error is:

          NinjaScript File Error Code Line Column
          Indicator\MyCaseSwitch.cs The type or namespace name 'CaseType' could not be found (are you missing a using directive or an assembly reference?) CS0246 - click for info 87 42
          Indicator\MyCaseSwitch.cs The type or namespace name 'CaseType' could not be found (are you missing a using directive or an assembly reference?) CS0246 - click for info 96 66
          Indicator\MyCaseSwitch.cs The type or namespace name 'CaseType' could not be found (are you missing a using directive or an assembly reference?) CS0246 - click for info 136 52
          Indicator\MyCaseSwitch.cs The type or namespace name 'CaseType' could not be found (are you missing a using directive or an assembly reference?) CS0246 - click for info 145 76
          Indicator\MyCaseSwitch.cs The type or namespace name 'CaseType' could not be found (are you missing a using directive or an assembly reference?) CS0246 - click for info 163 52
          Indicator\MyCaseSwitch.cs The type or namespace name 'CaseType' could not be found (are you missing a using directive or an assembly reference?) CS0246 - click for info 172 76


          Hope this help. Thanks.

          Comment


            #6
            MAX,

            Please create your enum outside the scope of the Indicator. See this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=3420
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            637 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            571 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X