RENKO CHART--Need symbol specific brick setting in afl

#1
Hi friends

I have a small problem with renko chart.
Often renko chart comes blank in Amibroker.
-----------------------------------------------------------------
ERROR 10
Array subscript out of range.
you must not access array elements outside 0 .. (Barcount-1) range.

------------------------------------------------------------------
Fed up with this problem,new traders stop using RENKO chart.
The idea here is find a small fix and get rid of the problem using addition of a small code line.

It may look a cilly thing but it saves big hassels and makes life easier so that one can go on testing renko chart if it suits or not.

I dont mind finding right brick size by trial and error when I am not trading.
Once I find right bricksize,then I like to put the code line that makes the afl to create renko chart with specified brick size setting the moment i select that symbol.
The code line for single symbol is as follows.
IIf( "ticker"== ParamStr(" ticker","NIFTY14JAN6200CE"),brick =2,0);
IIf( "ticker" == ParamStr(" ticker","SILVERM14FEBFUT"),brick =20,0);
IIf( "Ticker"== ParamStr( " ticker", "LT"),brick =2.4,0); //uses 2.4 as brick size
===========================

I can use only one code line at a time. it works for that sym,bol or any symbol having sama range of brick size setting.
When symbol changes from a stock having brick=2 to a commodity having brick=20,I like the code line to make a smooth transition to deliver new chart.
without manual intereference during trading hours.
suppose i have 10 favourite symbols and their specific brick size values, how can I write these individual code lines together in one line?

Something like

=======================================================
chart afl here
HTML:
//Brick = LastValue( Max(0.02*C, 0.05) );//WORKS GOOD
//Brick = Param( "Brick Size", 0.1, 0.01, 100.00, 0.01 );
reverse = 2;
IIf( "ticker" == ParamStr(" ticker","SILVERM14FEBFUT"),brick =20,0);
//IIf( "Ticker"== "NIFTY14JANFUT",Brick ==10,0),
IIf( "ticker"== ParamStr(" ticker","NIFTY14JAN6200CE"),Brick ==2,0);
//IIf( "ticker"==ParamStr( " ticker","NIFTY14JAN6400PE"),Brick ==2,0) ,
//IIf( "Ticker"== ParamStr( " ticker", "LT",Brick==2.4,0);





// 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;
========================
Hope somebody can help link the code lines for single symbols together to get a trouble free renko chart as we change symbol. we need to use comma or OR etc for linking the code lines of 10 symbols into one code line.
------------------------
why Renko chart? becoz it minimises noise and points out trend clearly.

thanks
ford7k
 
Last edited:

mastermind007

Well-Known Member
#2
Code:
boxsize=IIf(C>=0.01 AND C<10, 0.05,
IIf(C>=10 AND C<20, 0.10,
IIf(C>=20 AND C<30, 0.15,
IIf(C>=30 AND C<40, 0.20,
IIf(C>=40 AND C<50, 0.25,
IIf(C>=50 AND C<60, 0.30,
IIf(C>=60 AND C<70, 0.35,
IIf(C>=70 AND C<80, 0.40,
IIf(C>=80 AND C<90, 0.45,
IIf(C>=90 AND C<100, 0.50,
IIf(C>=100 AND C<150, 0.75,
IIf(C>=150 AND C<200, 1.00,
IIf(C>=200 AND C<250, 1.25,
IIf(C>=250 AND C<300, 1.50,
IIf(C>=300 AND C<350, 1.75,
IIf(C>=350 AND C<400, 2.00,
IIf(C>=400 AND C<450, 2.25,
IIf(C>=450 AND C<500, 2.50,
IIf(C>=500 AND C<550, 2.75,
IIf(C>=550 AND C<600, 3.00,
IIf(C>=600 AND C<650, 3.25,
IIf(C>=650 AND C<700, 3.50,
IIf(C>=700 AND C<750, 3.75,
IIf(C>=750 AND C<800, 4.00,
IIf(C>=800 AND C<850, 4.25,
IIf(C>=850 AND C<900, 4.50,
IIf(C>=900 AND C<950, 4.75,
IIf(C>=950 AND C<1000, 5.00,
IIf(C>=1000 AND C<1100, 5.50,
IIf(C>=1100 AND C<1200, 6.00,
IIf(C>=1200 AND C<1300, 6.50,
IIf(C>=1300 AND C<1400, 7.00,
IIf(C>=1400 AND C<1500, 7.50,
IIf(C>=1500 AND C<1600, 8.00,
IIf(C>=1600 AND C<1700, 8.50,
IIf(C>=1700 AND C<1800, 9.00,
IIf(C>=1800 AND C<1900, 9.50,
IIf(C>=1900 AND C<2000, 10.00,
IIf(C>=2000 AND C<2100, 10.50,
IIf(C>=2100 AND C<2200, 11.00,
IIf(C>=2200 AND C<2300, 11.50,
IIf(C>=2300 AND C<2400, 12.00,
IIf(C>=2400 AND C<2500, 12.50,
IIf(C>=2500 AND C<2600, 13.00,
IIf(C>=2600 AND C<2700, 13.50,
IIf(C>=2700 AND C<2800, 14.00,
IIf(C>=2800 AND C<2900, 14.50,
IIf(C>=2900 AND C<3000, 15.00,
IIf(C>=3000 AND C<3100, 15.50,
IIf(C>=3100 AND C<3200, 16.00,
IIf(C>=3200 AND C<3300, 16.50,
IIf(C>=3300 AND C<3400, 17.00,
IIf(C>=3400 AND C<3500, 17.50,
IIf(C>=3500 AND C<3600, 18.00,
IIf(C>=3600 AND C<3700, 18.50,
IIf(C>=3700 AND C<3800, 19.00,
IIf(C>=3800 AND C<3900, 19.50,
IIf(C>=3900 AND C<4000, 20.00,
IIf(C>=4000 AND C<4100, 20.50,
IIf(C>=4100 AND C<4200, 21.00,
IIf(C>=4200 AND C<4300, 21.50,
IIf(C>=4300 AND C<4400, 22.00,
IIf(C>=4400 AND C<4500, 22.50,
IIf(C>=4500 AND C<4600, 23.00,
IIf(C>=4600 AND C<4700, 23.50,
IIf(C>=4700 AND C<4800, 24.00,
IIf(C>=4800 AND C<4900, 24.50,
IIf(C>=4900 AND C<5000, 25.00,
IIf(C>=5000 AND C<6000, 30,
IIf(C>=6000 AND C<7000, 35,
IIf(C>=7000 AND C<8000, 40,
IIf(C>=8000 AND C<9000, 45,
IIf(C>=9000 AND C<10000, 50,
IIf(C>=10000 AND C<11000, 55,
IIf(C>=11000 AND C<12000, 60,
IIf(C>=12000 AND C<13000, 65,
IIf(C>=13000 AND C<14000, 70,
IIf(C>=14000 AND C<15000, 75,
IIf(C>=15000 AND C<16000, 80,
IIf(C>=16000 AND C<17000, 85,
IIf(C>=17000 AND C<18000, 90,
IIf(C>=18000 AND C<19000, 95,
IIf(C>=19000 AND C<20000, 100,
IIf(C>=20000 AND C<21000, 105,
IIf(C>=21000 AND C<22000, 110,
IIf(C>=22000 AND C<23000, 115,
IIf(C>=23000 AND C<24000, 120,
IIf(C>=24000 AND C<25000, 125,
IIf(C>=25000 AND C<26000, 130,
IIf(C>=26000 AND C<27000, 135,
IIf(C>=27000 AND C<28000, 140,
IIf(C>=28000 AND C<29000, 145,
IIf(C>=29000 AND C<30000, 150,
IIf(C>=30000 AND C<31000, 155,
IIf(C>=31000 AND C<32000, 160,
IIf(C>=32000 AND C<33000, 165,
IIf(C>=33000 AND C<34000, 170,
IIf(C>=34000 AND C<35000, 175,
200
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))));
Brick = LastValue(boxsize);
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++;
			j = i;
			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++;
			j = i;
			up[j] = 1;
			down[j] = 0;
			RKC[j] = RKC[j-1] + 2;
			RKO[j] = RKC[j] - 1;			
			for( x=2; x<=num; x++ )
			{
				//j++;
				j = i;
				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++;
					j = i;
					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++;
					j = i;
					Up[j] = 0;
				 	Down[j] = 1;
				 	RKC[j] = RKC[j-1] - 2;
				 	RKO[j] = RKC[j] + 1;
				 	for( x=2; x<=num; x++ )
				 	{
						//j++;
						j = i;
					 	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;
 
Last edited:
#3
Mastermind007
Thank you for the solution.
it works in most times.

I still want the afl code line for 10 symbols with specific sEtting(which I find once & use it always).
THIS I USED EARLIER BUT LOST THE CODE during pc format work.

=========================
I dont mind finding right brick size by trial and error when I am not trading.
Once I find right bricksize,then I like to put the code line that makes the afl to create renko chart with specified brick size setting the moment I select that symbol.
The code line for single symbol is as follows.
IIf( "ticker"== ParamStr(" ticker","NIFTY14JAN6200CE"),brick =2,0);
IIf( "ticker" == ParamStr(" ticker","SILVERM14FEBFUT"),brick =20,0);
IIf( "Ticker"== ParamStr( " ticker", "LT"),brick =2.4,0); //uses 2.4 as brick size

LINK 10 such things with OR or AND TO GET

IIf( "ticker"== ParamStr(" ticker","NIFTY14JAN6200CE"),brick =2,0),
IIf( "ticker" == ParamStr(" ticker","SILVERM14FEBFUT"),brick =20,0),
IIf( "Ticker"== ParamStr( " ticker", "LT"),brick =2.4,0);

It runs into error as the lines are linked-that i the only problem I need to solve this
---------------------
thanks & regards
ford7k
 
#4
_SECTION_BEGIN("renko");
// Modified Renko Chart with custom date axis
// and high/low winks
// Loosely based on Renko chart formula by G. Kavanagh
// from AmiBroker on-line formula library (id=521)
// Modifications & fixes TJ 2014

function FillRun( dir, num, changedir )
{
global i, j, modified, dt, RKC, RKO, RKD, RKH, RKL;

for ( x = 1; x <= num AND j < BarCount - 1; x++ )
{
j++;

extra = ( changedir AND x == 1 ) * dir;

RKC[ j ] = RKC[ j - 1 ] + dir + extra;
RKO[ j ] = RKC[ j - 1 ] + IIf( modified, 0, extra );
RKD[ j ] = dt[ i ];
RKH[ j ] = High[ i - 1 ];
RKL[ j ] = Low[ i - 1 ];
}
}

SetBarsRequired( sbrAll, sbrAll );
Brick = Param( "Brick Size", 0.001, 0.0001, 1.00, 0.001 );
reverse = 2;
intra = ParamToggle( "Intraday", "No|Yes", 0 );
modified = ParamToggle( "Modified", "No|Yes", 0 );

// 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;
RKD = 0;
RKH = 0;
RKL = 0;
dt = IIf( intra, floor( TimeNum() / 100 ), DateNum() );

dir = -1; // 1 is up, -1 is down

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

for ( i = 1; i < BarCount - 1; i++ )
{
if ( j >= BarCount )
break; // no more room -> finish

if ( CF <= RKC[j] - 1 AND dir < 0 ) // Continue down
{
num = RKC[j] - CF;

FillRun( dir, num, False );
}
else
if ( CR >= RKC[j] + Reverse AND dir < 0 ) // Change down to up
{
num = CR - RKC[j];
dir = 1;

FillRun( dir, num, True );
}
else
if ( CR >= RKC[j] + 1 AND dir > 0 ) // Continue Up
{
num = CR - RKC[j];
FillRun( dir, num, False );
}
else
if ( CF <= RKC[j] - Reverse AND dir > 0 ) // Change up to down
{
num = RKC[j] - CF;
dir = -1;

FillRun( dir, num, True );
}
}

// 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 );
RKD = Ref( RKD, -delta );
RKH = Ref( RKH, -delta );
RKL = Ref( RKL, -delta );

C = RKC * Brick;
O = RKO * Brick;
H = IIf( modified, RKH, Max( C, O ) );
L = IIf( modified, RKL, Min( C, O ) );

Plot( C, "", IIf( C > O, colorGreen, colorRed ), styleCandle );

m1 = MA( (C+H+L)/3, 8 );
m2 = MA( C, 8 );

Plot( m1, "SMA Typ", colorBlue );
Plot( m2, "SMA Renko", colorOrange );

Cover = Cross( m2, m1 );
Sell = Cross( m1, m2 );

Short = Sell AND C < O;
Buy = Cover AND C > O;

PlotShapes( shapeUpArrow * Buy, colorGreen, 0, m1);
PlotShapes( shapeDownArrow * Sell, colorRed, 0, m1 );
PlotShapes( shapeHollowUpArrow * Cover, colorGreen, 0, m1, -25);
PlotShapes( shapeHollowDownArrow * Short, colorRed, 0, m1, -25 );

color = IIf( Flip( Buy, Sell ), ColorRGB( 220, 255, 220 ),
IIf( Flip( Short, Cover ), ColorRGB( 255, 220, 220 ), colorWhite ) );

Plot( 1, "", color, styleArea | styleOwnScale, 0, 1, 0, -1 );

xnum = floor( RKD / 1000 );
XChange = IIf( xnum != Ref( xnum, -1 ), 1, Null );

Plot( XChange, "", colorGrey50, styleHistogram | styleOwnScale, 0, 1 );

// Draw renko-date axis
MonthNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
fvb = FirstVisibleValue( BarIndex() );
lvb = LastVisibleValue( BarIndex() );

for ( i = fvb; i < lvb; i++ )
{
if ( XChange[ i ] )
{
if ( intra )
datetext = StrFormat( "%02gh", floor ( RKD[ i ] / 100 ) );
else
if ( ( xnum[ i ] % 100 ) == 1 )
datetext = StrFormat( "%04.0f", 1900 + ( xnum[ i ] / 100 ) );
else
datetext = StrExtract( MonthNames, ( xnum[ i ] % 100 ) - 1 );

PlotText( datetext , i, LowestVisibleValue( Low ), colorGrey50, colorWhite );
}
}

Title = Name() + StrFormat( " - 20%06.0f", RKD % 1000000 ) + " - Renko Chart : Last Value = " + RKC * Brick + " H: " + RKH + " L: " + RKL + ", Brick Size = " + Brick;

GraphXSpace = 5;
_SECTION_END();
 
#5
i tried this afl .

even the last closing price doesnt matches.

i also have a couple of afl on renko but they also dont plot afl properly ......
 
Last edited:
#6
There is so much lack of work on renko.Does anybody actually use it?I have couple of afls which do not serve the purpose to plot mcx gold,mcx silver and Nifty.Anybody with similar issue?
 
#7
Code:
boxsize=IIf(C>=0.01 AND C<10, 0.05,
IIf(C>=10 AND C<20, 0.10,
IIf(C>=20 AND C<30, 0.15,
IIf(C>=30 AND C<40, 0.20,
IIf(C>=40 AND C<50, 0.25,
IIf(C>=50 AND C<60, 0.30,
IIf(C>=60 AND C<70, 0.35,
IIf(C>=70 AND C<80, 0.40,
IIf(C>=80 AND C<90, 0.45,
IIf(C>=90 AND C<100, 0.50,
IIf(C>=100 AND C<150, 0.75,
IIf(C>=150 AND C<200, 1.00,
IIf(C>=200 AND C<250, 1.25,
IIf(C>=250 AND C<300, 1.50,
IIf(C>=300 AND C<350, 1.75,
IIf(C>=350 AND C<400, 2.00,
IIf(C>=400 AND C<450, 2.25,
IIf(C>=450 AND C<500, 2.50,
IIf(C>=500 AND C<550, 2.75,
IIf(C>=550 AND C<600, 3.00,
IIf(C>=600 AND C<650, 3.25,
IIf(C>=650 AND C<700, 3.50,
IIf(C>=700 AND C<750, 3.75,
IIf(C>=750 AND C<800, 4.00,
IIf(C>=800 AND C<850, 4.25,
IIf(C>=850 AND C<900, 4.50,
IIf(C>=900 AND C<950, 4.75,
IIf(C>=950 AND C<1000, 5.00,
IIf(C>=1000 AND C<1100, 5.50,
IIf(C>=1100 AND C<1200, 6.00,
IIf(C>=1200 AND C<1300, 6.50,
IIf(C>=1300 AND C<1400, 7.00,
IIf(C>=1400 AND C<1500, 7.50,
IIf(C>=1500 AND C<1600, 8.00,
IIf(C>=1600 AND C<1700, 8.50,
IIf(C>=1700 AND C<1800, 9.00,
IIf(C>=1800 AND C<1900, 9.50,
IIf(C>=1900 AND C<2000, 10.00,
IIf(C>=2000 AND C<2100, 10.50,
IIf(C>=2100 AND C<2200, 11.00,
IIf(C>=2200 AND C<2300, 11.50,
IIf(C>=2300 AND C<2400, 12.00,
IIf(C>=2400 AND C<2500, 12.50,
IIf(C>=2500 AND C<2600, 13.00,
IIf(C>=2600 AND C<2700, 13.50,
IIf(C>=2700 AND C<2800, 14.00,
IIf(C>=2800 AND C<2900, 14.50,
IIf(C>=2900 AND C<3000, 15.00,
IIf(C>=3000 AND C<3100, 15.50,
IIf(C>=3100 AND C<3200, 16.00,
IIf(C>=3200 AND C<3300, 16.50,
IIf(C>=3300 AND C<3400, 17.00,
IIf(C>=3400 AND C<3500, 17.50,
IIf(C>=3500 AND C<3600, 18.00,
IIf(C>=3600 AND C<3700, 18.50,
IIf(C>=3700 AND C<3800, 19.00,
IIf(C>=3800 AND C<3900, 19.50,
IIf(C>=3900 AND C<4000, 20.00,
IIf(C>=4000 AND C<4100, 20.50,
IIf(C>=4100 AND C<4200, 21.00,
IIf(C>=4200 AND C<4300, 21.50,
IIf(C>=4300 AND C<4400, 22.00,
IIf(C>=4400 AND C<4500, 22.50,
IIf(C>=4500 AND C<4600, 23.00,
IIf(C>=4600 AND C<4700, 23.50,
IIf(C>=4700 AND C<4800, 24.00,
IIf(C>=4800 AND C<4900, 24.50,
IIf(C>=4900 AND C<5000, 25.00,
IIf(C>=5000 AND C<6000, 30,
IIf(C>=6000 AND C<7000, 35,
IIf(C>=7000 AND C<8000, 40,
IIf(C>=8000 AND C<9000, 45,
IIf(C>=9000 AND C<10000, 50,
IIf(C>=10000 AND C<11000, 55,
IIf(C>=11000 AND C<12000, 60,
IIf(C>=12000 AND C<13000, 65,
IIf(C>=13000 AND C<14000, 70,
IIf(C>=14000 AND C<15000, 75,
IIf(C>=15000 AND C<16000, 80,
IIf(C>=16000 AND C<17000, 85,
IIf(C>=17000 AND C<18000, 90,
IIf(C>=18000 AND C<19000, 95,
IIf(C>=19000 AND C<20000, 100,
IIf(C>=20000 AND C<21000, 105,
IIf(C>=21000 AND C<22000, 110,
IIf(C>=22000 AND C<23000, 115,
IIf(C>=23000 AND C<24000, 120,
IIf(C>=24000 AND C<25000, 125,
IIf(C>=25000 AND C<26000, 130,
IIf(C>=26000 AND C<27000, 135,
IIf(C>=27000 AND C<28000, 140,
IIf(C>=28000 AND C<29000, 145,
IIf(C>=29000 AND C<30000, 150,
IIf(C>=30000 AND C<31000, 155,
IIf(C>=31000 AND C<32000, 160,
IIf(C>=32000 AND C<33000, 165,
IIf(C>=33000 AND C<34000, 170,
IIf(C>=34000 AND C<35000, 175,
200
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))));
Brick = LastValue(boxsize);
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++;
            j = i;
            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++;
            j = i;
            up[j] = 1;
            down[j] = 0;
            RKC[j] = RKC[j-1] + 2;
            RKO[j] = RKC[j] - 1;           
            for( x=2; x<=num; x++ )
            {
                //j++;
                j = i;
                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++;
                    j = i;
                    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++;
                    j = i;
                    Up[j] = 0;
                     Down[j] = 1;
                     RKC[j] = RKC[j-1] - 2;
                     RKO[j] = RKC[j] + 1;
                     for( x=2; x<=num; x++ )
                     {
                        //j++;
                        j = i;
                         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;


Dear @mastermind007 ,
your above renko code not work in 6.35

can you modify it ?

Thanks in advance
 

Similar threads