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:
Kagi Chart
Author/Uploader:
Graham Kavanagh - gkavanag [at] bigpond.net.au
Date/Time added:
2002-11-29 05:12:31
Origin:
Keywords:
Kagi
Level:
medium
Flags:
system,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:
Kagi swing chart with change based on share price. Swing ranges from 3 to 5%.
Place in indicator builder.
Formula:
//KAGI Chart (or Swing) for Amibroker Indicator window.
//Reverse swing is 3%.
//Graham Kavanagh 16 Nov 2002
SetBarsRequired(100000,100000);
Close = IIf( C<10, round(C*10)/10, IIf( C>=10 AND C<50, int(C) +
round(round(frac(C)*10)/5)*5/10, int(C)));
Reverse = LastValue(IIf(C<50,0.05,IIf(C>=50 AND C<100,0.04,0.03)));
EnableScript("jscript");
<%
Close = VBArray( AFL( "Close" ) ).toArray();
KC = new Array();
// initialize first element
j = 0;
KC[j] = Close[0];
down = 1; // By default the first bar is a down bar.
up = 0;
swap = 0;
// perform the loop that produces Kagi Chart
for( i = 1; i < Close.length; i++ )
{
Reverse =AFL("Reverse"); // percent reversal
requirement
if( Close[i] <= KC[j] && down) //continue down
{
KC[j] = Close[i];
}
else
{
if( Close[i] >= KC[j]*(1 + Reverse) && down) //Change direction to up
{
j++;
swap = 1;
KC[j] = Close[i];
}
}
if( Close[i] >= KC[j] && up) //Continue up
{
KC[j] = Close[i];
}
else
{
if( Close[i] <= KC[j]*(1 - Reverse) && up) //Change direction to down
{
j++;
KC[j] = Close[i];
swap = 1;
}
}
if( swap )
{
swap = 0;
if( up )
{
up = 0;
down = 1;
}
else
{
up = 1;
down = 0;
}
}
}
delta = Close.length - j-1; //to get all of chart
AFL.Var("KC") = KC;
AFL.Var("delta") = delta;
AFL.Var("Reverse") = Reverse;
%>
KC = Ref( KC, -delta );
C = KC;
L = LLV(C,2);
H = HHV(C,2);
MyColor =
IIf(C>Ref(H,-2),colorBlue,
IIf(C<Ref(L,-2),colorRed,
colorBlack));
Graph0BarColor = MyColor;
Graph0Style = 512+4096;
GraphXSpace = 5;
Graph0 = C;
Graph0Name = "Kagi Chart";
Graph1BarColor = 1;
Graph1Style = 16+2048+4096;
Graph1 = Reverse*100;
Graph1Name = "Reverse %";
Comments:
Fred Bender fbender [at] corb.net 2002-12-27 23:33:59
Graham,
I'm a complete newbie to AB, thus can't understand your coding, but have used Kagi charts in MetaStock for years. I've found that, for the stuff I trade (US-based mutual funds; closing price data only), Kagi works best on weekly data (compressed from daily). So please excuse the newbie-questions:
1. How can I modify your script to have it display weekly data, while the main price charts (and other indicator charts) display daily?
2. How can I adjust the parameter range (to 1 - 6 percent) and the default parameter (to 4.7 percent)?
Many thanks.
Fred
Graham Kavanagh kavemanperth [at] telstra.com 2002-12-28 19:07:04
Fred
1.Weekly chart can be viewed simply by viewing the weekly chart. The "W" button.
2. The parameter can be set with the "reverse" variable near the beginning of the code. I had just varied the %swing by the last closing price. Higher price, less swing. My closing price had to be rounded because I found a lot of my past data had been previously saved as odd decimals. I have since corrected the data and the initial statement can be removed for defining the close price.
maybe use
Reverse = 0.047;
or if you have the range of % based on some criteria just us an IIF statement
Reverse = IIf(condition==x,0.01,IIF(condition==y,0.06,0.047));
or similar
Graham
Flame doesnt matter 2003-06-02 20:34:13
I think there is a mistake there, the J shouldnt be incrised inside the else.
Im new to afl and know nothing about Java scripts so i might be mistaken.
Flame
2003-06-02 20:41:23
Forget my previous comment i was wrong.
Robert transition [at] hotkey.net.au 2003-07-28 22:10:25
Hi Graham, Thanks for your Kagi AFL. If you could shed some light on the following, I would appreciate it greatly.
1. How would you control the colour of a bar so it changes colour halfway up ?
2. How could you control the width(x axis) of the steps, so you could overlay it with the price chart, and not lose the time/date information.
If you are in Melbourne, please call me.
03 86289057
Graham gkavanagh [at] e-wire.net.au 2003-09-13 07:02:37
Robert
the only way I can think of to change the colour and/or line thickness as per the normal kagi chart would be to have 2 (or more) charts overlayed. They would need to each be configured for the colour and line thickness, then only be visible where required. ie be Null if condition not met.
Sorry, I am in Perth WA