NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > Application Technical Support > Miscellaneous Support > Historical Version 7 Beta Threads > Version 7 Beta General Questions & Bug Reports

Version 7 Beta General Questions & Bug Reports Ask questions here and post bug reports.

 
 
Thread Tools Display Modes
Old 11-17-2009, 08:19 AM   #1
aslane
Senior Member
 
Join Date: May 2006
Location: Madison
Posts: 234
Thanks: 1
Thanked 2 times in 2 posts
Default 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?
aslane is offline  
Old 11-17-2009, 09:30 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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.
NinjaTrader_Josh is offline  
Old 11-17-2009, 09:41 AM   #3
aslane
Senior Member
 
Join Date: May 2006
Location: Madison
Posts: 234
Thanks: 1
Thanked 2 times in 2 posts
Default

One color was not what I had in mind, but I'll check it out.
aslane is offline  
Old 11-17-2009, 10:08 AM   #4
aslane
Senior Member
 
Join Date: May 2006
Location: Madison
Posts: 234
Thanks: 1
Thanked 2 times in 2 posts
Default

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 Images
File Type: png hollow bars.png (6.6 KB, 25 views)
aslane is offline  
Old 11-22-2009, 10:06 PM   #5
aslane
Senior Member
 
Join Date: May 2006
Location: Madison
Posts: 234
Thanks: 1
Thanked 2 times in 2 posts
Default 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 Images
File Type: png hollow new.png (6.9 KB, 35 views)
aslane is offline  
Old 11-23-2009, 07:00 AM   #6
aslane
Senior Member
 
Join Date: May 2006
Location: Madison
Posts: 234
Thanks: 1
Thanked 2 times in 2 posts
Default 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 at 07:05 AM.
aslane is offline  
Old 11-23-2009, 08:54 AM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

aslane,

Thanks for sharing. Please feel free to use any custom chart style you may have made.
NinjaTrader_Josh is offline  
Old 11-25-2009, 06:33 PM   #8
noevictorian
Member
 
Join Date: Aug 2009
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
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!
noevictorian is offline  
Old 11-26-2009, 06:56 AM   #9
aslane
Senior Member
 
Join Date: May 2006
Location: Madison
Posts: 234
Thanks: 1
Thanked 2 times in 2 posts
Default

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.
aslane is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Renko Bars roonius General Programming 112 01-23-2012 03:52 AM
Backtesting Renko Bars jeremymgp Automated Trading 3 10-05-2009 09:16 AM
Eds Renko ? T2020 Miscellaneous Support 3 09-18-2009 09:02 AM
Renko Help kermut Strategy Analyzer 5 08-15-2009 04:17 PM
Renko Charts? Brunoben Charting 67 07-04-2009 04:06 PM


All times are GMT -6. The time now is 12:27 PM.