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

show high and lows for last 5 days

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

    show high and lows for last 5 days

    Hello,
    I am trying to show like a bubble or something similar so that if there is a new high or a new low for the last 5 days to display it on the chart.. I am trying to get this thing working but no luck.. anyone willing to help?

    something like this bubble (h 1102): http://readtheprospectus.files.wordp...09/04/spv3.png

    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Muestra el máximo y el mínimo de varios días atrás
        /// </summary>
        [Description("Muestra el máximo y el mínimo de varios días atrás")]
        public class ZiHiLoDiarios : Indicator
        {
            #region Variables
            private int dias = 3;
    		
    		private double[] dsHigh;
    		private double[] dsLow;
    		
    		private double lastHigh = double.MinValue;
    		private double lastLow	= double.MaxValue;
    		private const double nonValue = -999.99;
    		private Font fontText;
            #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()
            {
    			Add(new Plot( new Pen( Color.FromArgb( 160, 255,0,0), 1 ), PlotStyle.Dot, "High Día 0"));
                Add(new Plot( new Pen( Color.FromArgb( 255, 255,0,0), 2 ), PlotStyle.Line, "High Día -1"));
    			Add(new Plot( new Pen( Color.FromArgb( 255, 192,0,192), 2 ), PlotStyle.Line, "High Día -2"));
    			Add(new Plot( new Pen( Color.FromArgb( 255, 255,192,128), 2 ), PlotStyle.Line, "High Día -3"));
    			Add(new Plot( new Pen( Color.FromArgb( 160, 0,128,0), 1 ), PlotStyle.Dot, "Low Día 0"));
                Add(new Plot( new Pen( Color.FromArgb( 255, 0,128,0), 2 ), PlotStyle.Line, "Low Día -1"));
    			Add(new Plot( new Pen( Color.FromArgb( 255, 0,128,192), 2 ), PlotStyle.Line, "Low Día -2"));
    			Add(new Plot( new Pen( Color.FromArgb( 255, 0,192,192), 2 ), PlotStyle.Line, "Low Día -3"));
                CalculateOnBarClose	= true;
                Overlay				= true;
                PriceTypeSupported	= false;
    			
    			fontText = new Font("Arial", 14);
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if ( CurrentBar == 0 )
    			{
    				dsHigh 	= new double[dias];
    				dsLow	= new double[dias];
    				
    				for ( int i = 0; i < dias; i++ )
    				{
    					dsHigh[i]	= nonValue;
    					dsLow[i]	= nonValue;
    				}
    			}
    			
    			
    			if ( Bars.SessionBreak )
    			{
    				for ( int i = 0; i < dias-1; i++ )
    				{
    					dsHigh[i] = dsHigh[i+1];
    					dsLow[i] = dsLow[i+1];
    				}
    				dsHigh[dias-1] = lastHigh;
    				dsLow[dias-1] = lastLow;
    				
    				lastHigh = double.MinValue;
    				lastLow = double.MaxValue;
    			}
    			
    			lastHigh	=	( High[0]	> lastHigh ) 	? High[0] 	: lastHigh;
    			lastLow		=	( Low[0]	< lastLow ) 	? Low[0] 	: lastLow;
    			
                Plot0.Set( lastHigh );
    			Plot4.Set( lastLow );
    			
    			
    			if ( dsHigh[dias-1] != nonValue ) 
    			{
    				Plot1.Set( dsHigh[dias-1] );
    				DrawText( "High1", true, "H1", 10, dsHigh[dias-1], Color.Black, fontText, StringAlignment.Center, Color.Transparent, Color.Yellow, 160);
    			}
    			if ( dsLow[dias-1] != nonValue ) 
    			{
    				Plot5.Set( dsLow[dias-1] );
    				DrawText( "Low1", true, "L1", 10, dsLow[dias-1], Color.Black, fontText, StringAlignment.Center, Color.Transparent, Color.Yellow, 160);
    			}
    			
    			if ( dsHigh[dias-2] != nonValue ) 
    			{
    				Plot2.Set( dsHigh[dias-2] );
    				DrawText( "High2", true, "H2", 10, dsHigh[dias-2], Color.Black, fontText, StringAlignment.Center, Color.Transparent, Color.Yellow, 160);
    			}
    			if ( dsLow[dias-2] != nonValue )
    			{
    				Plot6.Set( dsLow[dias-2] );
    				DrawText( "Low2", true, "L2", 10, dsLow[dias-2], Color.Black, fontText, StringAlignment.Center, Color.Transparent, Color.Yellow, 160);
    			}
    			
    			if ( dsHigh[dias-3] != nonValue ) 
    			{
    				Plot3.Set( dsHigh[dias-3] );
    				DrawText( "High3", true, "H3", 10, dsHigh[dias-3], Color.Black, fontText, StringAlignment.Center, Color.Transparent, Color.Yellow, 160);
    			}
    			if ( dsLow[dias-3] != nonValue ) 
    			{
    				Plot7.Set( dsLow[dias-3] );
    				DrawText( "Low3", true, "L3", 10, dsLow[dias-3], Color.Black, fontText, StringAlignment.Center, Color.Transparent, Color.Yellow, 160);
    			}
            }
    		
            #region Properties
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries Plot0
            {
                get { return Values[0]; }
            }
    		[Browsable(false)]
            [XmlIgnore()]
            public DataSeries Plot1
            {
                get { return Values[1]; }
            }
    		[Browsable(false)]
            [XmlIgnore()]
            public DataSeries Plot2
            {
                get { return Values[2]; }
            }
    		[Browsable(false)]
            [XmlIgnore()]
            public DataSeries Plot3
            {
                get { return Values[3]; }
            }
    		[Browsable(false)]
            [XmlIgnore()]
            public DataSeries Plot4
            {
                get { return Values[4]; }
            }
    		[Browsable(false)]
            [XmlIgnore()]
            public DataSeries Plot5
            {
                get { return Values[5]; }
            }
    		[Browsable(false)]
            [XmlIgnore()]
            public DataSeries Plot6
            {
                get { return Values[6]; }
            }
    		[Browsable(false)]
            [XmlIgnore()]
            public DataSeries Plot7
            {
                get { return Values[7]; }
            }
    
            [Description("Número de días para mostrar su High & Low")]
            [Category("Parameters")]
    		[Browsable(false)]
            public int Dias
            {
                get { return dias; }
                set { dias = Math.Max(1, value); }
            }
            #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 ZiHiLoDiarios[] cacheZiHiLoDiarios = null;
    
            private static ZiHiLoDiarios checkZiHiLoDiarios = new ZiHiLoDiarios();
    
            /// <summary>
            /// Muestra el máximo y el mínimo de varios días atrás
            /// </summary>
            /// <returns></returns>
            public ZiHiLoDiarios ZiHiLoDiarios(int dias)
            {
                return ZiHiLoDiarios(Input, dias);
            }
    
            /// <summary>
            /// Muestra el máximo y el mínimo de varios días atrás
            /// </summary>
            /// <returns></returns>
            public ZiHiLoDiarios ZiHiLoDiarios(Data.IDataSeries input, int dias)
            {
                checkZiHiLoDiarios.Dias = dias;
                dias = checkZiHiLoDiarios.Dias;
    
                if (cacheZiHiLoDiarios != null)
                    for (int idx = 0; idx < cacheZiHiLoDiarios.Length; idx++)
                        if (cacheZiHiLoDiarios[idx].Dias == dias && cacheZiHiLoDiarios[idx].EqualsInput(input))
                            return cacheZiHiLoDiarios[idx];
    
                ZiHiLoDiarios indicator = new ZiHiLoDiarios();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                indicator.Input = input;
                indicator.Dias = dias;
                indicator.SetUp();
    
                ZiHiLoDiarios[] tmp = new ZiHiLoDiarios[cacheZiHiLoDiarios == null ? 1 : cacheZiHiLoDiarios.Length + 1];
                if (cacheZiHiLoDiarios != null)
                    cacheZiHiLoDiarios.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheZiHiLoDiarios = 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>
            /// Muestra el máximo y el mínimo de varios días atrás
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.ZiHiLoDiarios ZiHiLoDiarios(int dias)
            {
                return _indicator.ZiHiLoDiarios(Input, dias);
            }
    
            /// <summary>
            /// Muestra el máximo y el mínimo de varios días atrás
            /// </summary>
            /// <returns></returns>
            public Indicator.ZiHiLoDiarios ZiHiLoDiarios(Data.IDataSeries input, int dias)
            {
                return _indicator.ZiHiLoDiarios(input, dias);
            }
    
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// Muestra el máximo y el mínimo de varios días atrás
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.ZiHiLoDiarios ZiHiLoDiarios(int dias)
            {
                return _indicator.ZiHiLoDiarios(Input, dias);
            }
    
            /// <summary>
            /// Muestra el máximo y el mínimo de varios días atrás
            /// </summary>
            /// <returns></returns>
            public Indicator.ZiHiLoDiarios ZiHiLoDiarios(Data.IDataSeries input, int dias)
            {
                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.ZiHiLoDiarios(input, dias);
            }
    
        }
    }
    #endregion
    Last edited by usrscom; 04-21-2014, 01:43 PM.

    #2
    Hello usrscom,

    Welcome to the NinjaTrader Support Forums!

    Looking at your code it looks like you are getting some compile errors.

    So DrawText() is either going to take 12 arguments or 5 arguments. You are passing it in 11 right now.

    DrawText( "High1", true, "H1", 10, dsHigh[dias-1],Color.Black, fontText, StringAlignment.Center, Color.Transparent, Color.Yellow, 160);



    You may want to pass it in 12 arguments, so you would need to add a yPixelOffset to be in a compilable state for example:

    DrawText( "High1", true, "H1", 10, dsHigh[dias-1], 4, Color.Black, fontText, StringAlignment.Center, Color.Transparent, Color.Yellow, 160);

    You also may want to add a CurrentBar check to make sure you have enough bars before you start processing your Indicator like:

    if(CurrentBar < 20)
    return;




    That should get your indicator visible on a chart for you to take a look at it.
    JCNinjaTrader Customer Service

    Comment


      #3
      thanks, where exactly do I put

      if(CurrentBar < 20)
      return;

      Comment


        #4
        Hello,

        You would want to place the CurrentBar check after your first one for when it is equal to 0.

        Code:
        if ( CurrentBar == 0 )
        			{...
        
        if(CurrentBar < 20) return;
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          maybe im just doing something wrong? because its not showing anything http://screencast.com/t/EylKpgjtINaA

          Comment


            #6
            Hello,

            Are there any errors in the Log Tab of the Control Center?
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              finally got it working.. thanks so much
              Last edited by usrscom; 04-22-2014, 07:59 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Segwin, 05-07-2018, 02:15 PM
              14 responses
              1,789 views
              0 likes
              Last Post aligator  
              Started by Jimmyk, 01-26-2018, 05:19 AM
              6 responses
              837 views
              0 likes
              Last Post emuns
              by emuns
               
              Started by jxs_xrj, 01-12-2020, 09:49 AM
              6 responses
              3,293 views
              1 like
              Last Post jgualdronc  
              Started by Touch-Ups, Today, 10:36 AM
              0 responses
              13 views
              0 likes
              Last Post Touch-Ups  
              Started by geddyisodin, 04-25-2024, 05:20 AM
              11 responses
              63 views
              0 likes
              Last Post halgo_boulder  
              Working...
              X