Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Hollow Renko Bars

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

    Hollow Renko Bars

    Is there any way to configure the renko bars to be hollow instead of solid? This is just a personal preference, not a right or wrong issue.

    If not, will the bar type be extendable like it was in 6.5?

    #2
    You can set the color of the bars to be transparent and then they will be hollow. The outline will only be one color though. If you need different behavior you can modify/create your own bar type just like in 6.5.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      One color was not what I had in mind, but I'll check it out.

      Comment


        #4
        Ok, single color is not so great, but you can get a monochrome effect by setting UpColor to transparent and DownColor and Outline to the color of your choice. See picture for example.
        Attached Files

        Comment


          #5
          Real Hollow Bars

          Ok, I decided to play with the ChartStyles to figure out why hollow bars are not possible, and I ended up fixing the OpenClose style to properly allow hollow bars (see attached image). Below is my proposed OpenCloseStyle code that implements a few changes to allow the hollow bars.

          The major changes are the following:
          * only use one brush, saving a resource
          * enable Pen2 so a different outline can be used for up/down bars
          * updates to helper methods
          * update PaintBars() to handle everything
          * generally tighten up the PaintBars() code a bit

          When coloring bars, the order of precedence is to use the set CandleOutlineColor if not empty, then the set BarColor if not empty, and then the default up/down Pen color.

          To generate hollow bars, the up/down colors can be set to Transparent, and the two Pen color control the painting. If a study then overrides the colors, that would properly recolor the bars.

          This same pattern can be applied to the CandleStyle as well, and I would be happy to do so if Ninja takes and runs with this code (as I pray they do after some review).

          Code:
          	public class OpenCloseStyle : ChartStyle
          	{
          		private static bool	registered	= Chart.ChartStyle.Register(new OpenCloseStyle());
          		
          		private	SolidBrush	brush		= new SolidBrush(Color.LightGreen);
          
          		/// <summary>
          		/// </summary>
          		public OpenCloseStyle() : base(ChartStyleType.OpenClose)
          		{
          			this.DownColor		= Color.Red;
          			this.UpColor		= Color.LightGreen;
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <returns></returns>
          		public override object Clone()
          		{
          			OpenCloseStyle ret	= new OpenCloseStyle();
          			ret.BarWidth		= BarWidth;
          			ret.DownColor		= DownColor;
          			ret.Pen			= Gui.Globals.Clone(Pen);
          			ret.Pen2			= Gui.Globals.Clone(Pen2);
          			ret.UpColor			= UpColor;
          			return ret;
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <returns></returns>
          		public override string DisplayName
          		{ 
          			get { return "Open/Close"; }
          		}
          
          		/// <summary>
          		/// </summary>
          		public override void Dispose()
          		{
          			base.Dispose();
          
          			brush.Dispose();
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <param name="barWidth"></param>
          		/// <returns></returns>
          		public override int GetBarPaintWidth(int barWidth)
          		{
          			// middle line + 2 * half of the body width + 2 * border line
          			return (int) (1 + 2 * (barWidth) + 2 * Pen.Width);
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <param name="propertyDescriptor"></param>
          		/// <param name="chartStyle"></param>
          		/// <param name="attributes"></param>
          		/// <returns></returns>
          		public override PropertyDescriptorCollection GetProperties(PropertyDescriptor propertyDescriptor, ChartStyle chartStyle, Attribute[] attributes)
          		{
          			PropertyDescriptorCollection properties = base.GetProperties(propertyDescriptor, chartStyle, attributes);
          
          			// here is how you change the display name of the property on the properties grid
          			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "BarWidthUI",	"\r\r\rBar width");
          			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "DownColor",		"\r\r\rColor for down bars");
          			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "Pen",			"\r\r\rUp bars outline");
          			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "Pen2",		"\r\r\rDown bars outline");
          			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "UpColor",		"\r\r\rColor for up bars");
          
          			return properties;
          		}
          
          		/// <summary>
          		/// </summary>
          		public override bool IsTransparent
          		{
          			get { return UpColor == Color.Transparent && DownColor == Color.Transparent && Pen.Color == Color.Transparent &&  Pen2.Color == Color.Transparent; }
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <param name="chartControl"></param>
          		/// <param name="graphics"></param>
          		/// <param name="bars"></param>
          		/// <param name="panelIdx"></param>
          		/// <param name="fromIdx"></param>
          		/// <param name="toIdx"></param>
          		/// <param name="bounds"></param>
          		/// <param name="max"></param>
          		/// <param name="min"></param>
          		public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min)
          		{
          			int		BoxSize	= bars.Period.Value;
          			double	TickSize	= bars.Instrument.MasterInstrument.TickSize;
          			double	offset	= BoxSize * TickSize;
          
          			int		barWidthValue = bars.BarsData.ChartStyle.BarWidthUI;
          
          			for (int idx = fromIdx; idx <= toIdx; idx++)
          			{
          				int barWidth	= GetBarPaintWidth(barWidthValue);
          				double closeValue	= bars.GetClose(idx);
          				int close		= chartControl.GetYByValue(bars, closeValue);
          				double openValue	= bars.GetOpen(idx);
          				int open 		= chartControl.GetYByValue(bars, openValue);
          				int x			= chartControl.GetXByBarIdx(bars, idx);
          
          				double previousOpenVal	= (idx != 0 ? bars.GetOpen(idx - 1) : openValue);
          				double previousCloseVal	= (idx != 0 ? bars.GetClose(idx - 1) : closeValue);
          
          			      bool upTrend = (previousOpenVal < previousCloseVal);
          				bool upBar = upTrend;
          				
          				// flip open if direction is reverse of trend
          				if (upTrend && closeValue < openValue)
          				{
          					upBar = false;
          					open = chartControl.GetYByValue(bars, openValue - offset);
          				}
          				else if (!upTrend && closeValue > openValue)
          				{
          					upBar = true;
          					open = chartControl.GetYByValue(bars, openValue + offset);
          				}
          
          				Pen pen = upBar ? Pen : Pen2;
          				Color	orgPenColor = pen.Color;
          				Color barColor = chartControl.GetBarColor(bars, idx);
          				Color olColor  = chartControl.GetCandleOutlineColor(bars, idx);
          				if (olColor != Color.Empty) pen.Color = olColor;
          				else if (barColor != Color.Empty) pen.Color = barColor;
          				
          				if (open == close)
          					graphics.DrawLine(pen, x - barWidth / 2, close, x + barWidth / 2, close);
          				else
          				{
          					brush.Color = barColor != Color.Empty ? barColor :
          							  upBar ? UpColor : DownColor;
          
          					graphics.FillRectangle(brush, x - barWidth / 2 + 1, Math.Min(close, open) + 1,
          						barWidth - 1, Math.Max(open, close) - Math.Min(close, open) - 1);
          
          					graphics.DrawRectangle(pen, x - (barWidth / 2) + (pen.Width / 2), Math.Min(close, open), barWidth - pen.Width, Math.Max(open, close) - Math.Min(close, open));
          				}
          				pen.Color = orgPenColor;
          			}
          		}
          	}
          Attached Files

          Comment


            #6
            Hollow Candlesticks

            Ok, the following is the same method applied to CandleStyle:

            Code:
            	public class CandleStyle : ChartStyle
            	{
            		private static bool	registered	= Chart.ChartStyle.Register(new CandleStyle());
            		
            		private	SolidBrush	brush		= new SolidBrush(Color.LightGreen);
            
            		/// <summary>
            		/// </summary>
            		public CandleStyle() : base(ChartStyleType.CandleStick)
            		{
            			this.DownColor		= Color.Red;
            			this.UpColor		= Color.LightGreen;
            		}
            
            		/// <summary>
            		/// </summary>
            		/// <returns></returns>
            		public override object Clone()
            		{
            			CandleStyle ret		= new CandleStyle();
            			ret.BarWidth		= BarWidth;
            			ret.DownColor		= DownColor;
            			ret.Pen			= Gui.Globals.Clone(Pen);
            			ret.Pen2			= Gui.Globals.Clone(Pen2);
            			ret.UpColor			= UpColor;
            			return ret;
            		}
            
            		/// <summary>
            		/// </summary>
            		/// <returns></returns>
            		public override string DisplayName
            		{ 
            			get { return "Candle Stick"; }
            		}
            
            		/// <summary>
            		/// </summary>
            		public override void Dispose()
            		{
            			base.Dispose();
            
            			brush.Dispose();
            		}
            
            		/// <summary>
            		/// </summary>
            		/// <param name="barWidth"></param>
            		/// <returns></returns>
            		public override int GetBarPaintWidth(int barWidth)
            		{
            			// middle line + 2 * half of the body width + 2 * border line
            			return (int) (1 + 2 * (barWidth) + 2 * Pen.Width);
            		}
            
            		/// <summary>
            		/// </summary>
            		/// <param name="propertyDescriptor"></param>
            		/// <param name="chartStyle"></param>
            		/// <param name="attributes"></param>
            		/// <returns></returns>
            		public override PropertyDescriptorCollection GetProperties(PropertyDescriptor propertyDescriptor, ChartStyle chartStyle, Attribute[] attributes)
            		{
            			PropertyDescriptorCollection properties = base.GetProperties(propertyDescriptor, chartStyle, attributes);
            
            			// here is how you change the display name of the property on the properties grid
            			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "BarWidthUI",	"\r\r\rBar width");
            			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "DownColor",		"\r\r\rColor for down bars");
            			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "Pen",			"\r\r\rUp bars outline");
            			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "Pen2",			"\r\r\rDown bars outline");
            			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "UpColor",		"\r\r\rColor for up bars");
            
            			return properties;
            		}
            
            		/// <summary>
            		/// </summary>
            		public override bool IsTransparent
            		{
            			get { return UpColor == Color.Transparent && DownColor == Color.Transparent && Pen.Color == Color.Transparent &&  Pen2.Color == Color.Transparent; }
            		}
            
            		/// <summary>
            		/// </summary>
            		/// <param name="chartControl"></param>
            		/// <param name="graphics"></param>
            		/// <param name="bars"></param>
            		/// <param name="panelIdx"></param>
            		/// <param name="fromIdx"></param>
            		/// <param name="toIdx"></param>
            		/// <param name="bounds"></param>
            		/// <param name="max"></param>
            		/// <param name="min"></param>
            		public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min)
            		{
            			int	barWidthValue = bars.BarsData.ChartStyle.BarWidthUI;
            			int barWidth	  = GetBarPaintWidth(barWidthValue);
            
            			for (int idx = fromIdx; idx <= toIdx; idx++)
            			{
            				double closeValue	= bars.GetClose(idx);
            				int close			= chartControl.GetYByValue(bars, closeValue);
            				int high			= chartControl.GetYByValue(bars, bars.GetHigh(idx));
            				int low				= chartControl.GetYByValue(bars, bars.GetLow(idx));
            				double openValue	= bars.GetOpen(idx);
            				int open			= chartControl.GetYByValue(bars, openValue);
            				int x				= chartControl.GetXByBarIdx(bars, idx);
            
            				bool upBar = closeValue >= openValue;
            				
            				Pen pen = upBar ? Pen : Pen2;
            				Color orgPenColor = pen.Color;
            				Color barColor = chartControl.GetBarColor(bars, idx);
            				Color olColor  = chartControl.GetCandleOutlineColor(bars, idx);
            				if (olColor != Color.Empty) pen.Color = olColor;
            				else if (barColor != Color.Empty) pen.Color = barColor;
            
            				if (open == close)
            					graphics.DrawLine(pen, x - barWidth / 2, close, x + barWidth / 2, close);
            				else
            				{
            					brush.Color = barColor != Color.Empty ? barColor :
            							      upBar ? UpColor : DownColor;
            
            					graphics.FillRectangle(brush, x - barWidth / 2 + 1, Math.Min(close, open) + 1,
            						barWidth - 1, Math.Max(open, close) - Math.Min(close, open) - 1);
            
            					graphics.DrawRectangle(pen, x - (barWidth / 2) + (pen.Width / 2), Math.Min(close, open), barWidth - pen.Width, Math.Max(open, close) - Math.Min(close, open));
            				}
            
            				if (high < Math.Min(open, close))
            					graphics.DrawLine(pen, x, high, x, Math.Min(open, close));
            
            				if (low > Math.Max(open, close))
            					graphics.DrawLine(pen, x, low, x, Math.Max(open, close));
            
            				pen.Color = orgPenColor;
            			}
            		}
            	}
            I tried to maintain the Ninja coding style, but some of the tabs may be off slightly.

            Not sure hollow candles are a big deal, but having two outline pens does make for nicer candles on black background for sure.
            Last edited by aslane; 11-23-2009, 08:05 AM.

            Comment


              #7
              aslane,

              Thanks for sharing. Please feel free to use any custom chart style you may have made.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by aslane View Post
                Ok, the following is the same method applied to CandleStyle
                This looks awesome but I'm sadly not skilled enough to know how/where to install the code. I poked around in the @ChartStyles file in my NT folder but that didn't seem to do the trick.

                Where would one put this code to make it work?

                Thanks for the killer work!

                Comment


                  #9
                  Well I was hoping Ninja would take a run with this code, but perhaps after they get thru the Beta.

                  Anyway, to use this code now, you need to open the file "My Documents\NinjaTrader 7\bin\Custom\Type\@ChartStyles.cs", and replace the appropriate class (CandleStyle and/or OpenCloseStyle) in that file with the code provided here. You then need to open some indicator/strategy in NT and compile it in order to compile the changes into NT. Finally, you will need to restart NT to get it to load.

                  Before you start, I would suggest making a copy of the @ChartStyles.cs file first in case something goes wrong.

                  I have only done this on NT7B4, and the code likely does not work on NT6.5.

                  Another thing to note, is every time you install a new version of NT, you will have to patch the @ChartStyles.cs file again, as this file gets overwritten with a new install. Again, once it is working save a copy off somewhere.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by samish18, Yesterday, 08:57 AM
                  8 responses
                  25 views
                  0 likes
                  Last Post samish18  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  3 responses
                  10 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by RookieTrader, Today, 07:41 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post RookieTrader  
                  Started by maybeimnotrader, Yesterday, 05:46 PM
                  1 response
                  18 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Perr0Grande, Yesterday, 08:16 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X