|
Kagi Chart Code
This is the code for AmiBroker but I think it can be easily translated into MQL4:
__________________________________________________ __________
reverse = Param ("reverse %" ,0.1, 0.1, 1,0.1)/100;
// initialize first element
j = 0;
KC[j] = Close[0];
direction=0;
for( i = 1; i < BarCount-1; i++ )
{
// percent reversal requirement
if(direction[j]==0)
{
if( Close[i] <= KC[j]) //continue down
{
KC[j] = Close[i];
}
else
{
if( Close[i] >= KC[j]*(1 + Reverse)) //Change direction to up
{
j++;
direction[j] = 1;
KC[j] = Close[i];
}
}
}
else
{
if( Close[i] >= KC[j]) //Continue up
{
KC[j] = Close[i];
}
else
{
if( Close[i] <= KC[j]*(1 - Reverse)) //Change direction to down
{
j++;
direction[j]=0;
KC[j] = Close[i];
}
}
}
}
delta = BarCount - j-1; //shift the chart to the wright
kagi= Ref(kc,-delta);
direction = Ref(direction,-delta);
Color =39;// IIf(kagi>Ref(kagi,-1), colorGreen, colorRed);
Plot(kagi, "", Color, styleStaircase|1024 );
Last edited by apfx; 01-24-2007 at 11:14 PM.
|