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

Need help Session High Low Indicator

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

    Need help Session High Low Indicator

    Hi,

    Can someone please help me write a script for Session High Low Indicator. I have tried the ninja's built-in indicator but they don't work as I want to, they either have stairs or extend to much left or right. I just want high low lines on the session (not stair steps ).

    Thanks

    #2
    Code:
    // 
    // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    
    #region Using declarations
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Plots the open, high, and low values from the session starting on the current day.
        /// </summary>
        [Description("Plots the open, high, and low values from the session starting on the current day.")]
        public class CurrentDayOHL : Indicator
        {
            #region Variables
    		private DateTime 	currentDate 	    =   Cbi.Globals.MinDate;
    		private double		currentOpen			=	double.MinValue;
            private double		currentHigh			=	double.MinValue;
    		private double		currentLow			=	double.MaxValue;
    		private bool		plotCurrentValue	=	false;
    		private bool		showOpen			=	true;
    		private bool		showHigh			=	true;
    		private bool		showLow				=	true;
    		#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.Orange, 2), PlotStyle.Square, "Current Open"));
    			Add(new Plot(new Pen(Color.Green, 2), PlotStyle.Square, "Current High"));
    			Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Square, "Current Low"));
    			Plots[0].Pen.DashStyle = DashStyle.Dash;
    			Plots[1].Pen.DashStyle = DashStyle.Dash;
    			Plots[2].Pen.DashStyle = DashStyle.Dash;
    			
    			AutoScale 			= false;
                Overlay				= true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if (!Bars.BarsType.IsIntraday)
    			{
    				DrawTextFixed("error msg", "CurrentDayOHL only works on intraday intervals", TextPosition.BottomRight);
    				return;
    			}
    			
    			bool sameDay = true;
    
    			if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == double.MinValue)
    			{
    				currentOpen 	= 	Open[0];
    				currentHigh 	= 	High[0];
    				currentLow		=	Low[0];
    				sameDay         =   false;
    			}
    
    			currentHigh 	= 	Math.Max(currentHigh, High[0]);
    			currentLow		= 	Math.Min(currentLow, Low[0]);
    
    			if (ShowOpen)
    			{
    				if (!PlotCurrentValue || !sameDay)
    					CurrentOpen.Set(currentOpen);
    				else
    					for (int idx = 0; idx < CurrentOpen.Count; idx++)
    						CurrentOpen.Set(idx, currentOpen);
    			}
    
    			if (ShowHigh)
    			{
    				if (!PlotCurrentValue || currentHigh != High[0])
    					CurrentHigh.Set(currentHigh);
    				else
    					for (int idx = 0; idx < CurrentHigh.Count; idx++)
    						CurrentHigh.Set(idx, currentHigh);
    			}
    
    			if (ShowLow)
    			{
    				if (!PlotCurrentValue || currentLow != Low[0])
    					CurrentLow.Set(currentLow);
    				else
    					for (int idx = 0; idx < CurrentLow.Count; idx++)
    						CurrentLow.Set(idx, currentLow);
    			}
    			
    			currentDate 	= 	Bars.GetTradingDayFromLocal(Time[0]); 
            }
    
            #region Properties
            [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries CurrentOpen
            {
                get { return Values[0]; }
            }
    
            [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries CurrentHigh
            {
                get { return Values[1]; }
            }
    
            [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries CurrentLow
            {
                get { return Values[2]; }
            }
    
    		[Browsable(true)]
    		[Gui.Design.DisplayNameAttribute("Show open")]
            public bool ShowOpen
            {
                get { return showOpen; }
    			set { showOpen = value; }
            }
    		
    		[Browsable(true)]
    		[Gui.Design.DisplayNameAttribute("Show high")]
            public bool ShowHigh
            {
                get { return showHigh; }
    			set { showHigh = value; }
            }
    
    		[Browsable(true)]
    		[Gui.Design.DisplayNameAttribute("Plot current value only")]
    		public bool PlotCurrentValue
    		{
    			get { return plotCurrentValue; }
    			set { plotCurrentValue = value; }
    		}
    		
    		[Browsable(true)]
    		[Gui.Design.DisplayNameAttribute("Show low")]
            public bool ShowLow
            {
                get { return showLow; }
    			set { showLow = 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 CurrentDayOHL[] cacheCurrentDayOHL = null;
    
            private static CurrentDayOHL checkCurrentDayOHL = new CurrentDayOHL();
    
            /// <summary>
            /// Plots the open, high, and low values from the session starting on the current day.
            /// </summary>
            /// <returns></returns>
            public CurrentDayOHL CurrentDayOHL()
            {
                return CurrentDayOHL(Input);
            }
    
            /// <summary>
            /// Plots the open, high, and low values from the session starting on the current day.
            /// </summary>
            /// <returns></returns>
            public CurrentDayOHL CurrentDayOHL(Data.IDataSeries input)
            {
                if (cacheCurrentDayOHL != null)
                    for (int idx = 0; idx < cacheCurrentDayOHL.Length; idx++)
                        if (cacheCurrentDayOHL[idx].EqualsInput(input))
                            return cacheCurrentDayOHL[idx];
    
                lock (checkCurrentDayOHL)
                {
                    if (cacheCurrentDayOHL != null)
                        for (int idx = 0; idx < cacheCurrentDayOHL.Length; idx++)
                            if (cacheCurrentDayOHL[idx].EqualsInput(input))
                                return cacheCurrentDayOHL[idx];
    
                    CurrentDayOHL indicator = new CurrentDayOHL();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    CurrentDayOHL[] tmp = new CurrentDayOHL[cacheCurrentDayOHL == null ? 1 : cacheCurrentDayOHL.Length + 1];
                    if (cacheCurrentDayOHL != null)
                        cacheCurrentDayOHL.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cacheCurrentDayOHL = tmp;
                    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>
            /// Plots the open, high, and low values from the session starting on the current day.
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.CurrentDayOHL CurrentDayOHL()
            {
                return _indicator.CurrentDayOHL(Input);
            }
    
            /// <summary>
            /// Plots the open, high, and low values from the session starting on the current day.
            /// </summary>
            /// <returns></returns>
            public Indicator.CurrentDayOHL CurrentDayOHL(Data.IDataSeries input)
            {
                return _indicator.CurrentDayOHL(input);
            }
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// Plots the open, high, and low values from the session starting on the current day.
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.CurrentDayOHL CurrentDayOHL()
            {
                return _indicator.CurrentDayOHL(Input);
            }
    
            /// <summary>
            /// Plots the open, high, and low values from the session starting on the current day.
            /// </summary>
            /// <returns></returns>
            public Indicator.CurrentDayOHL CurrentDayOHL(Data.IDataSeries 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.CurrentDayOHL(input);
            }
        }
    }
    #endregion

    Comment


      #3
      Originally posted by Bdg820 View Post
      Hi,

      Can someone please help me write a script for Session High Low Indicator. I have tried the ninja's built-in indicator but they don't work as I want to, they either have stairs or extend to much left or right. I just want high low lines on the session (not stair steps ).

      Thanks
      You can download it here:



      Depending on the session template selected, the indicator displays full session high and low or regular session high and low. You may deactivate any further options not needed or set some of the plots to transparent.

      For you purposes, have a look at the anaCurrentDayOHLV43 indicator.

      Comment


        #4
        Hi Jossfx,

        Thanks, but there's an error coming up on Line 24 column 18

        Comment


          #5
          Hello Bdg820,

          Can you please expand the error column so it shows the full error and then take a screenshot and attach it to your response?

          To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.
          http://windows.microsoft.com/en-us/w...#1TC=windows-8

          Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

          http://take-a-screenshot.org/

          Thank you in advance.
          Michael M.NinjaTrader Quality Assurance

          Comment


            #6
            Session High Low

            Hi Michael M,
            Thanks for your response. I tried to send the attachment but it keeps saying file to big. So i will try to copy and paste. The code is from the post below from Jossfx. The indicator does not show in the indicator list either.

            The error message I'm getting is :
            NinjaScript File,Error,Code,Line,Column,
            Indicator\SessionHL.cs,The namespace 'NinjaTrader.Indicator' already contains a definition for 'CurrentDayOHL',CS0101 - click for info,24,18,


            Thanks

            Comment


              #7
              Session High Low

              Hi Michael M,
              The attachment is not working please copy code from Jossfx post below.
              thanks
              Last edited by Bdg820; 10-07-2015, 04:48 AM.

              Comment


                #8
                Hello Bdg820,

                Thank you for the update. The code provided by jossfx is the built-in CurrentDayOHL indicator. The reason you cannot get this to work is because its using the same exact code that you already have installed. Please delete your SessionHL.cs file. Then please navigate to the following page: http://ninjatrader.com/support/forum...d=4&linkid=343
                Then please download this indicator called SessionPivotsV43.
                Then please import the downloaded indicator by opening up NinjaTrader and navigating to File -> Utilities -> Import NinjaScript..
                For more information, please see our help guide here: http://ninjatrader.com/support/helpG...ightsub=import

                Please let me know if I may be of further assistance,
                Michael M.NinjaTrader Quality Assurance

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by xiinteractive, 04-09-2024, 08:08 AM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by Johnny Santiago, 10-11-2019, 09:21 AM
                95 responses
                6,193 views
                0 likes
                Last Post xiinteractive  
                Started by Irukandji, Today, 09:34 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by RubenCazorla, Today, 09:07 AM
                1 response
                6 views
                0 likes
                Last Post RubenCazorla  
                Started by TraderBCL, Today, 04:38 AM
                3 responses
                26 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X