//+------------------------------------------------------------------+
//| KDJ.mq4 |
//| Copyright 2006, raidsan. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 Yellow
#property indicator_color3 Magenta
//---- input parameters
extern int NPeriod=9;
extern int KPeriod=3;
extern int DPeriod=3;
double RSV;
double KBuffer;
double DBuffer;
double JBuffer;
double HighesBuffer;
double LowesBuffer;
int draw_begin_K = 0;
int draw_begin_D = 0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 2 additional buffers are used for counting.
IndicatorBuffers(6);
SetIndexBuffer(4, HighesBuffer);
SetIndexBuffer(5, LowesBuffer);
SetIndexBuffer(3, RSV);
//---- indicator lines
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0, KBuffer); //k
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1, DBuffer); //d
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2, JBuffer); //j
//---- name for DataWindow and indicator subwindow label
string shortname = "KDJ("+NPeriod+","+KPeriod+","+DPeriod+")";
IndicatorShortName(shortname);
SetIndexLabel(0,"K");
SetIndexLabel(1,"D");
SetIndexLabel(2,"J");
SetLevelValue(0,0);
SetLevelValue(1,20);
SetLevelValue(2,50);
SetLevelValue(3,80);
SetLevelValue(4,100);
//----
draw_begin_K = NPeriod+KPeriod;
draw_begin_D = draw_begin_K+DPeriod;
SetIndexDrawBegin(0,draw_begin_K);
SetIndexDrawBegin(1,draw_begin_D);
SetIndexDrawBegin(2,draw_begin_D);
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
SetIndexEmptyValue(2,0);
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int start()
{
int i,k;
int counted_bars=IndicatorCounted();
double price;
//----
if(Bars<=NPeriod)
return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=draw_begin_K;i++) KBuffer[Bars-i]=0;
for(i=1;i<=draw_begin_D;i++) DBuffer[Bars-i]=0;
for(i=1;i<=draw_begin_D;i++) JBuffer[Bars-i]=0;
}
//---- minimums counting
i=Bars-NPeriod;
if(counted_bars>NPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double min=1000000;
k=i+NPeriod-1;
while(k>=i)
{
price=Low[k];
if(min>price) min=price;
k--;
}
LowesBuffer=min;
i--;
}
//---- maximums counting
i=Bars-NPeriod;
if(counted_bars>NPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double max=-1000000;
k=i+NPeriod-1;
while(k>=i)
{
price=High[k];
if(max
2008-09-26 15:33