the code below has custom dataseries called direction which gets a value of long when the high touches the 100 bar donchian high and keeps the same value stored in every bar until it hits 100 bar donchian low.
however when I try to expose this attribute to public Series<string> MarketDirection, I get compile error.
can you help me fix this compile error?
#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.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 { public class STSVer2 : Indicator { private DateTime first100barhigh,first100barlow,previouslast100barhigh,previouslast100barlow; private bool firstLongBO, firstShortBO=false; public string currentState="STARTED"; private Series<string> direction; private const string DIR_LONG ="LONG"; private const string DIR_SHORT ="SHORT"; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "STSVer2"; Calculate = Calculate.OnEachTick; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; 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; MaximumBarsLookBack = MaximumBarsLookBack.Infinite; } else if (State == State.Historical) { // Syncs a Series object to the primary bar object direction = new Series<string>(BarsArray[0]); } else if (State == State.Configure) { // Add a 5 minute Bars object - BarsInProgress index = 1 AddDataSeries(BarsPeriodType.Minute, 30); } } private int mostRecentUpper() { int barid=CurrentBar-1; int mru=0; while(barid>1){ if (High[barid] > DonchianChannel(100).Upper[barid+1]) { mru=barid; break; } barid-=1; } return mru; } private int mostRecentLower() { int barid=CurrentBar-1; int mrl=0; while(barid>1){ if (Low[barid] < DonchianChannel(100).Lower[barid+1]) { mrl=barid; break; } barid-=1; } return mrl; } protected override void OnBarUpdate() { /* 1. watch for first donchian breakout 2. take the first 9 ema and exit as it breaks out to new highs 3. watch for pullback on 30 min 4. take the retracement move back up trailing stop pre bar low 5. cancel retracemetn when it hits other side of donchian */ //Add your custom indicator logic here if(CurrentBar<200) return; if (BarsInProgress > 0) return; try { //Print("Got here1"); if(High[0]>DonchianChannel(100).Upper[1] && direction[0] !=DIR_LONG) { direction[0] =DIR_LONG; Print("Got first Donchian high BO" + Times[0].ToString()); } if(Low[0]<DonchianChannel(100).Lower[1] && direction[0] !=DIR_SHORT) { direction[0] =DIR_SHORT; Print("Got first Donchian low BO" + Times[0].ToString()); } if(IsFirstTickOfBar){ direction[0]=direction[1]; } switch (State) { case State.Historical: break; case State.Realtime: break; } } catch (Exception eX) { PrintTo = PrintTo.OutputTab1; Print("Exception " + eX.StackTrace); } } #region Properties [Range(1, int.MaxValue)] [NinjaScriptProperty] [Display(Name="Period", Order=1, GroupName="Parameters")] public int Period { get; set; } [Browsable(false)] [XmlIgnore] public Series<string> MarketDirection { get { return direction[0]; } } #endregion } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private STSVer2[] cacheSTSVer2; public STSVer2 STSVer2(int period) { return STSVer2(Input, period); } public STSVer2 STSVer2(ISeries<double> input, int period) { if (cacheSTSVer2 != null) for (int idx = 0; idx < cacheSTSVer2.Length; idx++) if (cacheSTSVer2[idx] != null && cacheSTSVer2[idx].Period == period && cacheSTSVer2[idx].EqualsInput(input)) return cacheSTSVer2[idx]; return CacheIndicator<STSVer2>(new STSVer2(){ Period = period }, input, ref cacheSTSVer2); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.STSVer2 STSVer2(int period) { return indicator.STSVer2(Input, period); } public Indicators.STSVer2 STSVer2(ISeries<double> input , int period) { return indicator.STSVer2(input, period); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.STSVer2 STSVer2(int period) { return indicator.STSVer2(Input, period); } public Indicators.STSVer2 STSVer2(ISeries<double> input , int period) { return indicator.STSVer2(input, period); } } } #endregion
Comment