When I now want to use the indicator in my Strategy, I can only specify two properties, "HigherTimeFrameBarPeriod" and "Period". I cannot specify the enum properties. Why?
HTFMovingAverage()
#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds Indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators.Isak { public class HTFMovingAverage : Indicator { private CustomEnumNamespace.UniversalMovingAverage maType = CustomEnumNamespace .UniversalMovingAverage .SMA; private CustomEnumNamespace.BarsPeriodType bpType = CustomEnumNamespace .BarsPeriodType .Minute; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "HTFMovingAverage"; Calculate = Calculate.OnBarClose; IsOverlay = true; BarsRequiredToPlot = 1; IsAutoScale = false; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; HigherTimeFrameBarPeriod = 60; Period = 20; AddPlot(Brushes.Magenta, "HTF Plot"); } else if (State == State.Configure) { // We use a switch which allows NinjaTrader to only execute code pertaining to our case switch (bpType) { // If the bpType is defined as Minute then... case CustomEnumNamespace.BarsPeriodType.Minute: { // Sets the secondary data series bar period type to Minute AddDataSeries(BarsPeriodType.Minute, HigherTimeFrameBarPeriod); break; } // If the bpType is defined as Day then... case CustomEnumNamespace.BarsPeriodType.Day: { // Sets the secondary data series bar period type to Minute AddDataSeries(BarsPeriodType.Day, HigherTimeFrameBarPeriod); break; } } } } protected override void OnBarUpdate() { if (BarsInProgress == 0 && CurrentBars[0] > 0) { // extend the larger time frame for each primary bar so there are consecutive bars set so we can see it on the chart if (!Values[0].IsValidDataPoint(0)) Values[0][0] = Values[0][1]; } if (BarsInProgress == 1 && CurrentBars[1] > 0) { // We use a switch which allows NinjaTrader to only execute code pertaining to our case switch (maType) { // If the maType is defined as an EMA then... case CustomEnumNamespace.UniversalMovingAverage.EMA: { // Sets the plot to be equal to the EMA's plot Values[0][0] = EMA(Closes[1], Period)[0]; break; } // If the maType is defined as a HMA then... case CustomEnumNamespace.UniversalMovingAverage.HMA: { // Sets the plot to be equal to the HMA's plot Values[0][0] = HMA(Closes[1], Period)[0]; break; } // If the maType is defined as a SMA then... case CustomEnumNamespace.UniversalMovingAverage.SMA: { // Sets the plot to be equal to the SMA's plot Values[0][0] = SMA(Closes[1], Period)[0]; break; } // If the maType is defined as a WMA then... case CustomEnumNamespace.UniversalMovingAverage.WMA: { // Sets the plot to be equal to the WMA's plot Values[0][0] = WMA(Closes[1], Period)[0]; break; } // If the maType is defined as a VMA then... case CustomEnumNamespace.UniversalMovingAverage.VMA: { // Sets the plot to be equal to the WMA's plot Values[0][0] = VMA(Closes[1], Period, Period)[0]; break; } } } } #region Properties [Display(GroupName = "Parameters", Description = "Choose a Moving Average Type.")] public CustomEnumNamespace.UniversalMovingAverage MAType { get { return maType; } set { maType = value; } } [Display(GroupName = "Parameters", Description = "Choose Bars Period Type")] public CustomEnumNamespace.BarsPeriodType BPType { get { return bpType; } set { bpType = value; } } [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "MA Period", GroupName = "NinjaScriptParameters", Order = 0)] public int Period { get; set; } [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "HTF Bar Period", GroupName = "NinjaScriptParameters", Order = 0)] public int HigherTimeFrameBarPeriod { get; set; } #endregion } } /* Creates an enum in a custom namespace that is assigned to UniversalMovingAverage. Basically it assigns a numerical value to each item in the list and the items can be referenced without the use of their numerical value. For more information on enums you can read up on it here: http://www.csharp-station.com/Tutorials/Lesson17.aspx */ namespace CustomEnumNamespace { public enum UniversalMovingAverage { EMA, HMA, SMA, WMA, VMA } public enum BarsPeriodType { Minute, Day } }
Comment