Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: Renko Chart
Author/Uploader: Graham Kavanagh - gkavanagh [at] e-wire.net.au
Date/Time added: 2005-07-21 02:18:53
Origin:
Keywords: renko
Level: advanced
Flags: indicator

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

Plot renko chart. Error in plotting will occur if the box and/or reversal values are too small causing the number of renko bars exceeding the underlying stock normal price bars

Formula:

// Renko  Chart
// Graham Kavanagh  13 Aug 2004 ver C
// Custom Indicator, date axis does not apply


 SetBarsRequired(10000,10000);

// Brick size is dependant on what you want, if too small will not produce a
chart due to insufficient x-axis bars
//Brick = LastValue( ATR(100) );
//Brick = LastValue( Max(0.02*C, 0.05) );
Brick = Param( "Brick Size", 0.1, 0.01, 1.00, 0.01 );
reverse = 2;

// Convert the closing price to rising and falling rounded bricks
CF = ceil(C/Brick);
CR = floor(C/Brick);

// initialize first element
j = 0;
RKC[j] = CF[0];
RKO[j] = CF[0] + 1;

down[j] = 1;  // By default the first bar is a down bar.
up[j] = 0;

// Loop to produce the Renko values in number of bricks

for( i=1; i<BarCount-1; i++ )
{
if( CF[i] <= RKC[j] - 1 && down[j] ) // Continue down
	{
		num = RKC[j] - CF[i];
		for( x=1; x<=num; x++ )
		{
			j++;
			up[j] = 0;
			down[j] = 1;
			RKC[j] = RKC[j-1] - 1;
			RKO[j] = RKC[j] + 1;
		}
	}
	else
	{
		if( CR[i] >= RKC[j] + Reverse && down[j] )  // Change down to up
		{
			num = CR[i] - RKC[j];
			j++;
			up[j] = 1;
			down[j] = 0;
			RKC[j] = RKC[j-1] + 2;
			RKO[j] = RKC[j] - 1;			
			for( x=2; x<=num; x++ )
			{
				j++;
				up[j] = 1;
				down[j] = 0;
				RKC[j] = RKC[j-1] + 1;
				RKO[j] = RKC[j] - 1;
			}
		}
		else
		{
			if( CR[i] >= RKC[j] + 1 && up[j] ) // Continue Up
			{
				num = CR[i] - RKC[j];
				for( x=1; x<=num; x++ )
				{
					j++;
					Up[j] = 1;
					Down[j] = 0;
					RKC[j] = RKC[j-1] + 1;
					RKO[j] = RKC[j] - 1;
				}
		 	}
		 	else
		 	{
			 	if( CF[i] <= RKC[j] - Reverse && up[j] )  // Change up to down
			 	{
				 	num = RKC[j] - CF[i];
				 	j++;
					Up[j] = 0;
				 	Down[j] = 1;
				 	RKC[j] = RKC[j-1] - 2;
				 	RKO[j] = RKC[j] + 1;
				 	for( x=2; x<=num; x++ )
				 	{
					 	j++;
					 	up[j] = 0;
				 		down[j] = 1;
				 	 	RKC[j] = RKC[j-1] - 1;
				 	 	RKO[j] = RKC[j] + 1;
					}
				}
			}
		}
	}
}


// move the chart to right end of chart space, ie last brick on last bar
position
delta =  BarCount-1 - j;

RKC = Ref( RKC, -delta );
RKO = Ref( RKO, -delta );

Up = Ref( Up, -delta );
Down = Ref( Down, -delta );

/*
rC = RKC * Brick;// + (Up-down)*Brick/2;
rO = RC - (Up-down)*Brick;
rH = Max(rC,rO);
rL = Min(rC,rO);
*/


C = RKC * Brick;// + (Up-down)*Brick/2;
O = C - (Up-down)*Brick;
H = Max(C,O);
L = Min(C,O);

Plot( C, "", colorGrey50,styleCandle); 
// plot chart
//plotOHLC( rO, rH, rL, rC, "Renko Price " , colorBlack, styleCandle);
GraphXSpace=5;

Title = Name() + " - {{INTERVAL}} {{DATE}} - Renko Chart : Last Value = " + RKC
* Brick + ", Brick Size = " + Brick;

Comments:

Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-07-21 02:33:19
forgot to mention that brick size selection is in the Parameters window. You can change the limits of the param function in the Param line near the top of the AFL
Paul

2005-07-21 05:21:59
Big thx. But I have AB 4.7.05 and this indicator doesn´t work:(
mmike
mmike8090 [at] yahoo.com
2005-07-21 12:33:17
@Graham: Thanks a lot, works fine

@Paul: you have to copy the data from the "Download formula file" site and adjust the brick size
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-07-21 19:02:30
It was written last year so should work on more recent AB versions. I only added the param line for brick size selection before posting.
Check that the errors are not from copy/paste and try pasting to a text editor first before into AB. Sometimes any characters that are formatted (eg html) can paste incorrectly
Paul

2005-07-22 04:19:46
To Graham and Mmmike: Now is everything O.K.. Big thx.
B Singh
bsingh60 [at] hotmail.com
2005-07-22 17:27:36
I get error 10 on line 36, col 8, at up[j]=0; when clicking verify AFL code on AB 4.71.1. ....!!!

madman
investment [at] fahrzeugkabel.de
2005-07-22 17:51:26
@B Singh
I´ve the same problem...
Kook

2005-07-23 00:19:59
I have got this error message on AB 4.6.

Line 108, Column 1:
}

}

}

}
^

Error 7.
Subscript out of range

Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-07-23 18:28:45
the majority of errors will occur if you have the brick size or reverse number too small causing the plot to use more than the available bars. Remember any plot is limited by the number of bars (quotes) in the base stock.
as stated at the top of the code
"// Brick size is dependant on what you want, if too small will not produce a
chart due to insufficient x-axis bars"

Try increasing the brick size

I wrote this back in Aug 04, V4.60 was released on 7th Aug 04, so I guess it should work. I did not include the version within the code as I originally was not posting to the afl library. I do not recall modifying it, but may have between Aug04 and Jul05
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-07-23 18:33:02
as an addition you can make the reverse changeable with prarameter window as well by changing the line
reverse =2;
to
reverse = Param( "Reverse", 2, 1, 5, 1 );

with this both brick size and rversal amount can be changed "live" to see when a chart begins to show
Kook

2005-07-24 16:29:11
These are errors massage from Amibroker 4.70.5

Ln: 88, Col: 6 : Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range
Ln: 89, Col: 8 : Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range
Ln: 90, Col: 8 : Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range
Ln: 91, Col: 17 : Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range


Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-07-24 18:51:33
Increase the brick size
or
Increase the reversal size

Kook

2005-07-25 03:49:39
Thank you,Graham

It work well with AB 4.60 after I adjust the brick size as your suggestion.

:-)
Steve

2005-08-03 08:05:03
Very nice. I don't suppose that you have 3 line break charts as well?

regards
Steve
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-08-03 18:38:07
if you go top the 3rd party area of website there is a plugin for 3 line break aceTLB
Joseph Biran
jbiran [at] pacbell.net
2005-08-15 01:58:25
i am still getting error 10 on line 56
for( x=2; x<=num; x++ )
{
j++;
up[j] = 1; // << error 10. subscript out of range. You must not access array elements outside 0..(barcount-1) range !! why??
down[j] = 0;
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-08-15 05:39:05
at a rough guess the brick size is too small creating an array of bricks longer than the underlying symbol price chart
Martin Cooney
martin [at] cooney.com.au
2005-08-15 08:42:06
Hi Graham,

I was interested in using Amibroker in relation to currency - a few people are looking at the package as an interface to Metatrader.

I was wondering whether this renko indicator can be configured to show bricks in a size of 3 pips (0.0003) in a time increment of 5 mins or 10 mins ?

Given currency is typically shown in a pricing structure of 1.8125, say for GBPUSD.

Is this possible to do with your current indicator. Excuse my lack of understanding of the indicator as well as AFL (been a while since I've used my AmiBroker).

Any help would be appreciated.
Martin
Martin Cooney
martin [at] cooney.com.au
2005-08-15 09:36:02
Hi Graham,

I was interested in using Amibroker in relation to currency - a few people are looking at the package as an interface to Metatrader.

I was wondering whether this renko indicator can be configured to show bricks in a size of 3 pips (0.0003) in a time increment of 5 mins or 10 mins ?

Given currency is typically shown in a pricing structure of 1.8125, say for GBPUSD.

Is this possible to do with your current indicator. Excuse my lack of understanding of the indicator as well as AFL (been a while since I've used my AmiBroker).

Any help would be appreciated.
Martin
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-08-15 18:25:58
The brick size is whatever you define it as, but remember that the number of columns cannot exceed the bas symbol number of bars
See the line Brick = na ebter what ever you like after the =

If the brick size neds to be smaller you may be able to reduce the number of base symbol bars used in the construction of the renko chart
eg start the loop at i=round(barcount/2) instead of i=1
Martin Cooney
martin [at] cooney.com.au
2005-08-16 06:52:37
Thanks Graham,

I'm struggling to understand it, to be honest.

I've set the line to:-
Brick = LastValue( Max(0.0003*C, 0.0003) );

I've absolutely no idea if this is correct. I know what I want the renko displayed as - simply don't know how these values i.e. 5 min / 3 pip (0.0003) are inserted. (Since it's time based, I'd like to see if it's possible to have a different time base than the main price chart window)

Second question is whether the regular MA indicators will correctly display when placed on top of a renko indicator ?

Any further help would be good too :0
Martin
Martin Cooney
martin [at] cooney.com.au
2005-08-16 07:32:09
OK forget the first bit :) I just put in
Brick = 0.0003; and the pip size looks pretty good. MAs also look to be a pretty good approximation when viewed with other Renko charting packages.

Remaining question is whether I can hardwire the time value of the brick which will give me a 5 min / 3 pip brick even if looking at a 15 min chart ?
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-08-16 19:10:57
Renko is only price based, like P&F charts. There is absolutely no time value for them. The X axis is only to provide somewhere to separate the bricks.
As I say in the title of the AFL
// Custom Indicator, date axis does not apply

If you want to create a time based renko chart you would need to re-write the code and the basis of constructing the renko completely

Timeframes are used to show a longer timeframe within shorter time chart (eg show 15 minute charts when background tperiod is 5 minute
It is not straightforward to do the reverse and you would encounter more X axis space than you would nornmally as therre are more changes in lower time period charts, and the X axis reduces as you make the time peiod greater
eg 1 minute may have 15,000 bars, but 15 minute only 1,000 bars to plot the renko

You would have to consider this when selecting brick sizes and the number of bricks to show.
I can suggest that you could create the renko price data into a composite symbol for the 5 minute and display this in the longer timeframe window.
Martin Cooney
martin [at] cooney.com.au
2005-08-17 01:45:58
Graham,

Renko is actually based on a brick based on a price movement as well as the length of time for a brick. As the indicator is at the moment, the duration of a brick is based on the timeframe of the chart.

I'd simply like to set one of the parameters of the Renko indicator to be a timeframe unit i.e. 5 min periods is when the check for a new brick is done. If close price hasn't moved the 3 units, no new brick.

Would this be done using some simple addition such as TimeFrameSet ? (excuse my current lack of AFL at this point)

Cheers
Martin

P.S Would it be preferrable to email you or post this thread in the Yahoo forum ?
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2005-08-17 18:04:03
Martin, I do not recall reading about time at price in my refs to renko charts, so beyond my knowledge of them. Probabaly best to check with the mailing list group
Mohan Yellayi
mohany1 [at] comcast.net
2005-08-24 21:35:00
By changing the line
Brick = Param( "Brick Size", 0.1, 0.01, 1.00, 0.01 );

To the following 2 lines, it works for me in AB 4.70.5


Brick1 = Param( "Brick Size", 0.2, 0.01, 1.00, 0.01 );
Brick = LastValue( Max(Brick1*C, 0.01) );
Ron Mack
EliteMack [at] aol.com
2005-09-10 20:12:52
Where can i get some good Renko charts for a good price or even free!!!
Rick Lee
buyfast1000 [at] yahoo.com
2005-10-30 01:27:48
Martin is correct.

Renko charts although they change direction when the box size is twice the size of the last box, they are built from the underlying time data.

For example a Renko chart based on 60 minutes of data will have a different structure than a Renko chart built on 120 minutes of data or a daily chart. Even though both Renko's will change together for the first 60 min after that the 60 min Renko will be "set in stone". while the 120 min Renko could possible reverse a number of times before 120 minutes expires. If the price moves far enough it could erase the 60 min portion of the 120 min Renko. (if trending )

In other words the input to the Renko is the close of the 60 minute bars (in this example). The 60 min bars filter the ticks and then become the input for the Renko which filters the 60 min bars.

So if Graham reads this please adjust your Renko to get it's input from the underlying bars (5min, 15min etc)

Take a look at Xtick (Xtick.com) and download their free trial (They are mostly currencies) and build some renko' based on different timframes. You will see the difference.

Graham
kavemanperth [at] gmail.com
2005-11-01 20:30:39
It is already just based on whatever bar period you are using in the chart.
I cannot see what the problem is?
Please if anyone can fix this please do so. I do not use renko nor do I understand it I just followed what information I found on the net to create it. You will find that different sources can all have different interpretations on how to construct any chart. If your source is different you are freee to change this code to suit your needs.
Rick Lee
buyfast1000 [at] yahoo.com
2005-11-03 03:40:50
Given that the Renko chart is already based on a 5 min, 60 min bar etc then Graham is correct.

Renko itself is not time based as a bar or candlestick chart is. It adds bricks only when the close (in this example)of the current brick exceeds the previous brick.

otb
bin_jazy [at] yahoo.com
2006-01-26 10:13:21
Line 113, Column 1:
}

}

}

}
^

Error 7.
Subscript out of range
Graham
gkavanagh [at] e-wire.net.au
2006-01-26 17:21:27
OTB see the other comments above about brick size being too small creating too many bars for the base chart array size
cesare
stenab [at] hotmail.com
2006-01-31 08:15:33
Is possible with this price model insert a buy-sell option, so to make a back-test and see how the best value in box-size?
Thanks!
cesare
stenab [at] hotmail.com
2006-01-31 09:29:44
Is possible with this price model insert a buy-sell option, so to make a back-test and see how the best value in box-size?
Thanks!
cesare
stenab [at] hotmail.com
2006-01-31 10:34:10
Is possible with this price model insert a buy-sell option, so to make a back-test and see how the best value in box-size?
Thanks!
Graham
gkavanagh [at] e-wire.net.au
2006-01-31 19:40:45
You could do. You would need to remove the changing to renko bars and make the normal price chart use when the renko is rising/falling etc.
You could display the renko like a staircase plot overlaying the price chart. I ahve done similar to this with P&F chart to develop a trading system in actual chart time rather than in modified chart time as the P&f (and renko) do.
You could then use it with a normal chart incorporating your trade signals based on the condition of the renko values. This could then be optimised
cesare
stenab [at] hotmail.com
2006-02-01 05:44:49
Is possible with this price model insert a buy-sell option, so to make a back-test and see how the best value in box-size?
Thanks!
sona baja
sona_baja [at] yahoo.co.in
2006-09-24 09:32:34
These are errors massage from Amibroker 4.70.5

Ln: 36, Col: 8 : Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range
Ln: 37, Col: 10 : Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range
Ln: 38, Col: 9 : Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range
Ln: 39, Col: 18 & 9 : Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range
pl help and give detail what to change step by step
after eeading comments from too many users i am very much appreciate with you creatoion . awating tour reply
Graham
gkavanagh [at] e-wire.net.au
2006-09-24 18:27:29
Description:

Plot renko chart. Error in plotting will occur if the box and/or reversal values are too small causing the number of renko bars exceeding the underlying stock normal price bars
AP
voyager3k [ a t ] h ot mai l.co m
2007-03-17 11:56:14
If anyone interested, I incorporated all the suggestions in this thread into these changes and the Renko chart worked. I've commented out the original line of code and shown the suggested changes.

Make sure, also, that comments that wrap onto another line are cleaned up, i.e. made into one line instead of 2. They caused several errors due to copy & paste, made 2 lines out of 1 comment line.

Good Luck
AP
------- CODE CHANGES SHOWN HERE -----

...
//Brick = LastValue( ATR(100) );
//Brick = LastValue( Max(0.02*C, 0.05) );
//Brick = Param( "Brick Size", 0.1, 0.01, 1.00, 0.01 );

// took Mohan's suggestion
Brick1 = Param( "Brick Size", 0.2, 0.01, 1.00, 0.01 );
Brick = LastValue( Max(Brick1*C, 0.01) );

...
//reverse = 2;
// Took Graham's Suggestion
reverse = Param( "Reverse", 2, 1, 5, 1 );

...


// for( i=1; i<BarCount-1; i++ )
// Took Graham's Suggestion
for(i = round(BarCount/2); i<BarCount-1; i++ )
{
...
Mauricio Frang
aciofrang [at] 1dn.com [at] 1dn.com
2007-04-15 06:07:46
Tebe vosled rukoj i kami vniz
gumisio
gumisio [at] tenbit.pl
2007-08-12 07:39:18
Hello ;)

I have problems with finding proper parameters for the renko. I saw renko in Metastock and there is default 6.08 brick size, but here with intraday charts like 5 min I still get too much whipsaw effects and wrong entrance signals. Any suggestions?
gumisio
gumisio [at] tenbit.pl
2007-08-12 07:39:42
Hello ;)

I have problems with finding proper parameters for the renko. I saw renko in Metastock and there is default 6.08 brick size, but here with intraday charts like 5 min I still get too much whipsaw effects and wrong entrance signals. Any suggestions?
Scott

2009-04-11 17:29:28
//Use adaptive brick size

period = Param( \\\"Period\\\", 10, 2, 30, 1 );

stdVol = StDev(V, period );
Brick = LastValue( ATR(period )*stdVol/V );


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM