帖子
作者
回复/查看
最后发表
2008-06-06 19:10
2007-10-21 09:33
2006-07-01 11:38
//+------------------------------------------------------------------+
//| 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 **uffer;
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, **uffer); //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++) **uffer[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(max0)
counted_bars--;
//K
if(counted_bars>=draw_begin_K)
i=Bars-counted_bars-1;
else
i=Bars-draw_begin_K-1;
while(i>=0)
{
KBuffer = (RSV + (KPeriod-1)*KBuffer[i+1] ) / KPeriod; //k
i --;
}
//J
if(counted_bars>=draw_begin_D)
i=Bars-counted_bars-1;
else
i=Bars-draw_begin_D-1;
while(i>=0)
{
DBuffer = (1* KBuffer + (DPeriod-1)*DBuffer[i+1] ) / DPeriod; //D
**uffer=3*KBuffer-2*DBuffer;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
[ 本帖最后由 raidsan 于 2006-7-1 19:33 编辑 ]
2006-07-01 11:32