用AMIBROKER自制RENKO指標

為什麼要使用Renko圖?

因為Renko圖可以過濾股票/期貨走勢中的雜訊,讓投資者更能清楚地分析到股票/期貨的走勢。

如何在AmiBroker自制Renko指標?

1) Analysis -> Formula Editor

amibroker_make_ppo_2

 

2) 在AmiBroker輸入下面的languages (sources from Amibroker.com)

// 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”, 5, 5, 20, 1);
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;

 

3)  File -> Save As -> 輸入檔案名稱(例如renko_indicator)-> 存檔 -> 關閉Formula Editor 視窗

amibroker_renko_1

 

4)  打開Chart 視窗-> Custom Indicator -> 右點擊renko_indicator(剛剛儲存的檔案名稱)-> Insert-> OK

amibroker_make_ppo_5a

amibroker_renko_2

 

5) Renko 圖便出功出現在圖表上。

amibroker_renko_3

如果想知道更多關於使用Rendo的原理及要注意的地方,請報讀我們最新的Quants Training課程。