Renko Charts

mrm

New Member
#1
I'm getting several errors in this chart
Line 148,col8 error 10 array subscript out of range .You must not acces elements outside0(bar count-1)range you attemted to access 200th element array
Please somebody correct this afl
Thank you
SetBarsRequired(100000,100000);
//------------------------------------------------------------------+
// Block 1 |
//------------------------------------------------------------------+
VR=ParamToggle("View Renko","Bricks|Lines/Bars",0);
FV=Param("Initial size volatility",0.1,0.001,50,0.001);
MV=Param("Method calculation volatility",0,0,2,1);
PeriodVol=Param("Period calculation volatility",14,2,100,1);
Multiplier=Param("Multiplier volatility",1,0.1,10,0.1);
MR=ParamToggle("Method Renko","floating|fixed",1);
SG=ParamToggle("Show gap","No|Yes",1);
CG=ParamColor("Colour show gap",11);
MaxBS=Param("Maximum size brick",0,0,10,0.1);
MinBS=Param("Minimum size brick",0,0,10,0.1);
RenkoUp=ParamColor("Colour Renko upwards",colorBlack);
RenkoDown=ParamColor("Colour Renko downwards",colorBlack);
SB=ParamStyle("View bars",defaultval=styleCandle,mask=maskPrice);
color3=ParamColor("Colour bars",colorBlack);
History=Param("History size",5000,2,BarCount-1,1);
//------------------------------------------------------------------+
// Block 2 |
//------------------------------------------------------------------+
i=Max(BarCount-1-History,PeriodVol+1);
r=j=0;
direction=0;
iGapUp=iGapDown=0;
rOpen[0]=rHigh[0]=rLow[0]=rClose[0]=jUp=jDown=Open;
//-------------------------------------------------------------------
switch(MV)
{
case 0: Volatility=FV; break;
case 1: Volatility=ATR(PeriodVol)*Multiplier; break;
case 2: Volatility=StDev(Open,PeriodVol)*Multiplier; break;
}
BrickSize=Volatility[i-1];
//-------------------------------------------------------------------+
// Block 3 |
//-------------------------------------------------------------------+
while(i<=BarCount-1)
{
if(SG==1)
{
if(High[i-1]<Low)
{
iGapUp=1;
}
else
{
if(Low[i-1]>High)
{
iGapDown=1;
}
}
}
//-------------------------------------------------------------------
if(MR==0)
{
BrickSize=Volatility[i-1];
if(MaxBS>0) {BrickSize=Min(MaxBS,BrickSize);}
if(MinBS>0) {BrickSize=Max(MinBS,BrickSize);}
}
//------------------------------------------------------------------+
// Block 4 |
//------------------------------------------------------------------+
if(direction==0)
{
if(Open-rClose[r]>BrickSize)
{
rClose[r]=rOpen[r]+BrickSize;
rHigh[r]=rClose[r];
direction=1;
//-------------------------------------------------------------------
BrickSize=Volatility;
if(MaxBS>0) {BrickSize=Min(MaxBS,BrickSize);}
if(MinBS>0) {BrickSize=Max(MinBS,BrickSize);}
//-------------------------------------------------------------------
if(iGapUp==1|iGapDown==1)
{
color[r]=CG;
}
else
{
color[r]=RenkoUp;
}
continue;
}
//-------------------------------------------------------------------
else
{
if(rClose[r]-Open>BrickSize)
{
rClose[r]=rOpen[r]-BrickSize;
rLow[r]=rClose[r];
direction=2;
//-------------------------------------------------------------------
BrickSize=Volatility;
if(MaxBS>0) {BrickSize=Min(MaxBS,BrickSize);}
if(MinBS>0) {BrickSize=Max(MinBS,BrickSize);}
//-------------------------------------------------------------------
if(iGapUp==1|iGapDown==1)
{
color[r]=CG;
}
else
{
color[r]=RenkoDown;
}
continue;
}
}
}
//------------------------------------------------------------------+
// Block 5 |
//------------------------------------------------------------------+
else
{
if(direction==1)
{
if(rOpen[r]-Open>BrickSize)
{
r++;
rOpen[r]=rOpen[r-1];
rHigh[r]=rOpen[r];
rClose[r]=rOpen[r]-BrickSize;
rLow[r]=rClose[r];
direction=2;
//-------------------------------------------------------------------
BrickSize=Volatility;
if(MaxBS>0) {BrickSize=Min(MaxBS,BrickSize);}
if(MinBS>0) {BrickSize=Max(MinBS,BrickSize);}
//-------------------------------------------------------------------
if(iGapUp==1|iGapDown==1)
{
color[r]=CG;
}
else
{
color[r]=RenkoDown;
}
continue;
}
//-------------------------------------------------------------------
else
{
while(Open-rClose[r]>BrickSize)
{
r++;
rOpen[r]=rClose[r-1];
rLow[r]=rOpen[r];
rClose[r]=rOpen[r]+BrickSize;
rHigh[r]=rClose[r];
//-------------------------------------------------------------------
BrickSize=Volatility;
if(MaxBS>0) {BrickSize=Min(MaxBS,BrickSize);}
if(MinBS>0) {BrickSize=Max(MinBS,BrickSize);}
//-------------------------------------------------------------------
if(iGapUp==1|iGapDown==1)
{
color[r]=CG;
}
else
{
color[r]=RenkoUp;
}
}
}
}
//------------------------------------------------------------------+
// Block 6 |
//------------------------------------------------------------------+
else
{
if(direction==2)
{
if(Open-rOpen[r]>BrickSize)
{
r++;
rOpen[r]=rOpen[r-1];
rLow[r]=rOpen[r];
rClose[r]=rOpen[r]+BrickSize;
rHigh[r]=rClose[r];
direction=1;
//-------------------------------------------------------------------
BrickSize=Volatility;
if(MaxBS>0) {BrickSize=Min(MaxBS,BrickSize);}
if(MinBS>0) {BrickSize=Max(MinBS,BrickSize);}
//-------------------------------------------------------------------
if(iGapUp==1|iGapDown==1)
{
color[r]=CG;
}
else
{
color[r]=RenkoUp;
}
continue;
}
//-------------------------------------------------------------------
else
{
while(rClose[r]-Open>BrickSize)
{
r++;
rOpen[r]=rClose[r-1];// ERROR ON THIS LINE AND LINE 149,150,151,163
rHigh[r]=rOpen[r];
rClose[r]=rOpen[r]-BrickSize;
rLow[r]=rClose[r];
//-------------------------------------------------------------------
BrickSize=Volatility;
if(MaxBS>0) {BrickSize=Min(MaxBS,BrickSize);}
if(MinBS>0) {BrickSize=Max(MinBS,BrickSize);}
//-------------------------------------------------------------------
if(iGapUp==1|iGapDown==1)
{
color[r]=CG;
}
else
{
color[r]=RenkoDown;
}
}
}
}
}
}
//------------------------------------------------------------------+
// Block 7 |
//------------------------------------------------------------------+
if(VR==1)
{
jOpen[j]=Open;
jHigh[j]=High;
jLow[j]=Low;
jClose[j]=Close;
//-------------------------------------------------------------------
if(direction==1)
{
jUp[j]=rClose[r];
jDown[j]=rOpen[r];
color2[j]=color[r];
}
else
{
if(direction==2)
{
jUp[j]=rOpen[r];
jDown[j]=rClose[r];
color2[j]=color[r];
}
}
j++;
}
i++;
}
//------------------------------------------------------------------+
// Block 8 |
//------------------------------------------------------------------+
if(VR==1)
{
delta=BarCount-j;
jOpen=Ref(jOpen,-delta);
jHigh=Ref(jHigh,-delta);
jLow=Ref(jLow,-delta);
jClose=Ref(jClose,-delta);
jUp=Ref(jUp,-delta);
jDown=Ref(jDown,-delta);
color2=Ref(color2,-delta);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
PlotOHLC(jOpen,jHigh,jLow,jClose,"SRI",color3,SB);
Plot(jUp,"Up",color2,styleThick);
Plot(jDown,"Down",color2,styleThick);
}
//-------------------------------------------------------------------
else
{
delta=BarCount-1-r;
rOpen=Ref(rOpen,-delta);
rHigh=Ref(rHigh,-delta);
rLow=Ref(rLow,-delta);
rClose=Ref(rClose,-delta);
color=Ref(color,-delta);
PlotOHLC(rOpen,rHigh,rLow,rClose,"SRI",color,styleCandle);
}
 

mrm

New Member
#2
Problem is in size of bricks Can somebody sugest what size to use?

VR=ParamToggle("View Renko","Bricks|Lines/Bars",0);
FV=Param("Initial size volatility",1,1,500,1);
MV=Param("Method calculation volatility",0,0,2,1);
PeriodVol=Param("Period calculation volatility",14,2,100,1);
Multiplier=Param("Multiplier volatility",1,0.1,10,0.1);
MR=ParamToggle("Method Renko","floating|fixed",1);
SG=ParamToggle("Show gap","No|Yes",1);
CG=ParamColor("Colour show gap",11);
MaxBS=Param("Maximum size brick",.1,.01,1,0.1);
MinBS=Param("Minimum size brick",.1,0,1,0.1);
RenkoUp=ParamColor("Colour Renko upwards",colorBlack);
RenkoDown=ParamColor("Colour Renko downwards",colorBlack);
SB=ParamStyle("View bars",defaultval=styleCandle,mask=maskPrice);
color3=ParamColor("Colour bars",colorBlack);
History=Param("History size",5000,2,BarCount-1,1);
Is anybody using renko charts?
If you do what is yours setups. I want to use for stocks on daily charts
Thanks for help
 

rvlv

Active Member
#4
hi
not having enough data ?

Just change brick size to 0.001.
EACH INSTRUMENT OR SYMBOL HAS ITS OWN BEST SETTING-WHICH YOU NEED TO FIND OUT BY TRIAL N ERROR.

increase or decrease brick size.

that is it
Note DOWN- what setting works for each symbol- use it
 

mastermind007

Well-Known Member
#5
help me guys somebody I'm sure using Renko charts
Error is very hard to remove. There are far too many uncontrolled/unchecked increments. Logic has to be fully understood and debugged and it can take hours.
 

mrm

New Member
#6
Thanks
Did try several settings but nothing happen I give up on this one I have older version from 2004 that version work ok
 

extremist

Well-Known Member
#8
// Renko Chart
// Graham Kavanagh 13 Aug 2004 ver C - MODIFIED BY M.J.JEEVAN LAL
// 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) );
SetChartOptions(0,chartShowArrows|chartShowDates);
Brick = Param( "Brick Size", 5, 0.01, 10, 0.01 );
reverse =Param( "Reverse ", 1, 0, 10, 1 );

// Convert the closing price to rising and falling rounded bricks
CF = ceil(H/Brick);
CR = floor(L/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 <= RKC[j] - 1 && down[j] ) // Continue down
{
num = RKC[j] - CF;
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 >= RKC[j] + Reverse && down[j] ) // Change down to up
{
num = CR - 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 >= RKC[j] + 1 && up[j] ) // Continue Up
{
num = CR - 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 <= RKC[j] - Reverse && up[j] ) // Change up to down
{
num = RKC[j] - CF;
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, "", ParamColor( "Renko Color", colorBlack ),ParamStyle("Renko Style",styleCandle,maskAll));


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \n Op=> %g, \n Cl=> %g \n", O, C ) );

// plot chart
//PlotOHLC( rO, rH, rL, rC, "Renko Price " , colorBlack, styleCandle);
/*
Buy=Up;
PlotShapes(shapeUpArrow*Buy,colorGreen, 0, L );
Sell=Down;
PlotShapes(shapeDownArrow*Sell,colorRed, 0, H );

*/

i hope this will serve ur pourpose.
credit goes to Author.
i'm using this code so for any further help u can ask.
 
Last edited:
#9
hi
even this code faces same problem as other codes.

Amibroker becomes weak when it comes to barcount and array values less than zero etc.
This is like a curse on Amibroker.
read
//Brick size is dependant on what you want, if too small will not produce a
//chart due to insufficient x-axis bars




ERROR 10-FIXING NEEDS MODIFYING CODE LINES-NOT EASY ON NEW USERS OF AMIBROKER
===========================================
Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range
Occurs when you attempt to access array elements with subscripts below 0 (zero) or above BarCount-1.

// incorrect
for( bar = 0; bar < BarCount; bar++ )
{
a[ bar ] = C[ bar - 1]; // when i == 0 we are accessing C[-1] which is wrong
}


// correct
for( bar = 0; bar < BarCount; bar++ )
{
if( bar > 0 )
a[ bar ] = C[ bar - 1 ]; // only access C[ i - 1 ] when i is greater than zero
else
a[ bar ] = C[ 0 ];
}


===================

So if you can modify your code, it works.
second thing
brick size can be defined and be made for symbol specific.
like
if symbol is NIFTY, BRICKSIZE =10
IF SYMBOL IS L&T, bricksize = 4
------------------
if( Name() == "NIFTY" ) ,BRICKSIZE =10 // CORRECT - equality operator used properly
{

}


-----------------------
This type of code is needed. once you insert this code, the afl automatically changes to right brick size and you get chart ready.
EXACT CODE LINES TO BE WRITTEN AND INSERTED.

--------------
FIX ERROR10
BRICKSIZE PREDEFINE AND INSERT IT

these can solve the problem.
 
Last edited:

pratapvb

Well-Known Member
#10
you will be using renko in 1min chart or tick if you have it....but if you can get ATR of a higher TF, say 3min and set bricksize to that it will become symbol independent
 

Similar threads