
KDCD指标的改进版
KDCD指标的改进版
下边的代码是本人直接用iStochastic函数做的KDCD指标,计算方法与前边的代码相同,但直接用了系统提供的iStochastic函数,这样代码就简洁多了。
代码如下:
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 White
#property indicator_color2 Yellow
#property indicator_color3 Green
#property indicator_color4 Red
extern int KPeriod=8;
extern int DPeriod=3;
extern int Slowing=5;
double MainBuffer[];
double SignalBuffer[];
double KDCDBuffer[];
double KDCDBuffer1[];
int draw_begin1=0;
int draw_begin2=0;
int draw_begin3=0;
int init()
{
string short_name;
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0, MainBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1, SignalBuffer);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2, KDCDBuffer);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3, KDCDBuffer1);
short_name="KDCD("+KPeriod+","+DPeriod+","+Slowing+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"Main");
SetIndexLabel(1,"Signal");
SetIndexLabel(2,"KDCD");
SetIndexLabel(3,"KDCD");
SetIndexDrawBegin(0,KPeriod+Slowing);
SetIndexDrawBegin(1,KPeriod+Slowing+DPeriod);
SetIndexDrawBegin(2,KPeriod+Slowing+DPeriod);
SetIndexDrawBegin(3,KPeriod+Slowing+DPeriod);
return(0);
}
int start()
{
int i,limit,counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars<0) counted_bars--;
limit=Bars-counted_bars;
for(i=0;i<limit;i++)
{
KDCDBuffer1=EMPTY_VALUE;
MainBuffer=2*iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_EMA,0,MODE_MAIN,i)-100;
SignalBuffer=2*iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_EMA,0,MODE_SIGNAL,i)-100;
KDCDBuffer=2*(MainBuffer-SignalBuffer);
if(KDCDBuffer>0) KDCDBuffer1=KDCDBuffer;
}
return(0);
}
效果图:
[localimg=1000,613]1[/localimg]
附件: 您所在的用户组无法下载或查看附件