Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

want to return custom dataseries

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

    want to return custom dataseries

    I created a custom dataseries and I want to return and show it in databox
    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?

    Code:
    #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

    #2
    Hello junkone,

    Thank you for writing in.

    You are seeing this error because your are attempting to return a string when the type for your property is Series<string>.

    If you wish to return the entire Series, you will need to remove the index.

    Example:
    Code:
    public Series<string> MarketDirection
    {
         get { return direction; }
    }
    Please note that the data box is only going to be showing your indicator plots; as this indicator does not have any plots, the data box will not contain any information pertaining to your indicator.

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      thanks, but I still don't see the values in the databox. I have a chart where I plotted the donchian 100 and moved my cursor to the area where the crossover just happened. but the values that I exposed don't show on databox

      my expectation is that the marketdirection values will be shown in the databox.
      #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,previouslast100barh igh,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);
      }
      }




      protected override void OnBarUpdate()
      {
      //Add your custom indicator logic here
      if(CurrentBar<200)
      return;
      if (BarsInProgress > 0)
      return;
      try
      {
      //Print("Got here1");

      if((CrossAbove(High,DonchianChannel(100).Upper[1],1)) && direction[0] !=DIR_LONG)
      {
      direction[0] =DIR_LONG;
      Print("Got first Donchian high BO" + Times[0].ToString()+ CurrentBar);
      }
      if((CrossBelow(Low,DonchianChannel(100).Lower[1],1)) && direction[0] !=DIR_SHORT)
      {
      direction[0] =DIR_SHORT;
      Print("Got first Donchian low BO" + Times[0].ToString() + CurrentBar );
      }

      // 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


      [Browsable(true)]
      [XmlIgnore]
      public Series<string> MarketDirection
      {
      get { return direction; }
      }
      #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()
      {
      return STSVer2(Input);
      }

      public STSVer2 STSVer2(ISeries<double> input)
      {
      if (cacheSTSVer2 != null)
      for (int idx = 0; idx < cacheSTSVer2.Length; idx++)
      if (cacheSTSVer2[idx] != null && cacheSTSVer2[idx].EqualsInput(input))
      return cacheSTSVer2[idx];
      return CacheIndicator<STSVer2>(new STSVer2(), input, ref cacheSTSVer2);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.STSVer2 STSVer2()
      {
      return indicator.STSVer2(Input);
      }

      public Indicators.STSVer2 STSVer2(ISeries<double> input )
      {
      return indicator.STSVer2(input);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.STSVer2 STSVer2()
      {
      return indicator.STSVer2(Input);
      }

      public Indicators.STSVer2 STSVer2(ISeries<double> input )
      {
      return indicator.STSVer2(input);
      }
      }
      }

      #endregion

      Comment


        #4
        I did not read ur comment properly and understandthe issue with databox. however my values keep getting reset and I think its due to this as I am synchronizing my custom dataseries. how do I fix it?
        else if (State == State.Historical)
        {
        // Syncs a Series object to the primary bar object

        direction = new Series<string>(BarsArray[0]);


        }

        Comment


          #5
          Hello junkone,

          You will want to instantiate your Series from within State.Configure.

          State.Historical will be called on every historical bar, and this will cause the direction Series to continually be assigned to a new Series<string> instance.

          Please, let us know if we may be of further assistance.
          Zachary G.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by terkk, Today, 01:16 PM
          1 response
          15 views
          0 likes
          Last Post NinjaTrader_Heath  
          Started by TraderElegante, Today, 12:14 PM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by dgee949, Today, 11:44 AM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_JustinD  
          Started by NinjaTrader_Kate, Today, 12:01 PM
          0 responses
          20 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by efeuvejota01, Today, 11:42 AM
          3 responses
          36 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Working...
          X