# Amibroker AFL for Renko

##### Member
Hi,

I tried to check the attached AFL on Renko. This is ffrom another forum and seems to be working properly.
But when I am putting this in Amin=boker 6.0, it is throwing up multiple error messages. It seesm that version porting is needed. If anyone can help in getting this code corrected, that will be of great help.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//------------------------------------------------------------------------------
//
// 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
//
//------------------------------------------------------------------------------

// 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 <= 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, "", 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;

#### boarders

##### Well-Known Member
Brick = Param( "Brick Size", 0.1, 0.01, 1.00, 0.01 );

correct above to suit the scrip tick size / multiples

#### RajaShukla

##### New Member
It is still not working..

Can anybody help?

#### niceman

##### Member
Hi Boarders,

Kindly suggest values for NF and BNF.

Regards.

#### Velocity

##### Member
I am trying to get a buy/sell signals on the chart on below conditions:
st = supertrend(10,3)
sellsig=c<st
Sell = Cross(Ref(L,SellSig),L)
however, sometimes I am getting correct and sometimes incorrect signals.
Below is the entire code:
_SECTION_BEGIN(“Price”);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, “Close”, ParamColor(“Color”, colorDefault ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN(“Try”);
function SuperTrend(lenATR, width)
{
nATR = ATR(lenATR);
pAvg = (H+L) / 2;
upperBand = pAvg + width * nATR;
lowerBand = pAvg - width * nATR;
isUpTrend = True;
dn = DateNum();

for (i=lenATR; i<BarCount; ++i)
{
if (C > upperBand[i-1])
isUpTrend = True;
else if (C < lowerBand[i-1])
isUpTrend = False;
else
isUpTrend = isUpTrend[i-1];

if (isUpTrend)
lowerBand = Max(lowerBand, lowerBand[i-1]);
else
upperBand = Min(upperBand, upperBand[i-1]);
}

super = IIf(isUpTrend, lowerBand, upperBand);
return super;

}
st = SuperTrend(10,3);
Plot(st, “STOP”, IIf(C>st,colorBrightGreen,colorRed),styleLine|styleStaircase|styleThick);
BuySig = C > st;
SellSig = C < st;
Sell = Cross(Ref(L,SellSig),L);
Sell = ExRem(Sell, Buy);
Short = Sell;
Cover = ExRem(Buy, Sell);
Short = ExRem(Sell, Buy);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorBlueGrey, 0,L, offset=-80);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone), colorRed, 0,H, offset=-90);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone), colorGreen, 0,L, offset=-60);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone), colorOrange, 0,H, offset=-70);
_SECTION_END();
pls help
Thanks!