您需要 登录 才可以下载或查看,没有帐号?注册
和上次的问题有些类似,就是我增加了一个划线指标,可是图中不显示,检查程序没有问题,可是无论如何运行都不行,就是关机后再重新也不行,其他电脑上也是。我只好把最后的赋值修改成具体的数据(倒数第五行的语句 if(MainBuffer[i] MainBuffer[i+1]) K_Buffer[i]=MainBuffer[i];),然后再恢复成早先的变量,居然成功。不知道是什么道理,烦请解释。谢谢!下面是代码
#property indicator_separate_window
#property indicator_minimum -5
#property indicator_maximum 105
#property indicator_buffers 6
#property indicator_color1 LightSeaGreen
#property indicator_color2 White
#property indicator_color3 Yellow
#property indicator_color4 Red
//---- input parameters
extern int KPeriod=9;
extern int DPeriod=3;
extern int Slowing=3;
//---- buffers
double MainBuffer[];
double SignalBuffer[];
double HighesBuffer[];
double LowesBuffer[];
double J_Buffer[];
double K_Buffer[];
//----
int draw_begin1=0;
int draw_begin2=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 2 additional buffers are used for counting.
IndicatorBuffers(6);
SetIndexBuffer(4, HighesBuffer);
SetIndexBuffer(5, LowesBuffer);
//---- indicator lines
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0, MainBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1, SignalBuffer);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2, J_Buffer);
SetIndexStyle(3,DRAW_LINE,0,2);
SetIndexBuffer(3, K_Buffer);
//---- name for DataWindow and indicator subwindow label
short_name= kdj( +KPeriod+ , +DPeriod+ , +Slowing+ )
IndicatorShortName(short_name);
SetIndexLabel(0, k
SetIndexLabel(1, d
SetIndexLabel(2, J
//----以下四句都可无?
draw_begin1=KPeriod+Slowing;//可无
draw_begin2=draw_begin1+DPeriod;//可无
SetIndexDrawBegin(0,draw_begin1);//可无
SetIndexDrawBegin(1,draw_begin2);//可无
//----
return(0);
}
//+------------------------------------------------------------------+
//| Stochastic oscillator |
//+------------------------------------------------------------------+
int start()
{
int i,k;
int counted_bars=IndicatorCounted();
double price;
//----
if(Barsprice) min=price;
k--;
}
LowesBuffer[i]=min;
i--;
}
//---- maximums counting---原程序风格
i=Bars-KPeriod;
if(counted_bars KPeriod) i=Bars-counted_bars-1;
while(i =0)
{
double max=-1000000;
k=i+KPeriod-1;
while(k =i)
{
price=High[k];
if(maxdraw_begin1) i=Bars-counted_bars-1;
while(i =0)
{
double sumlow=0.0;
double sumhigh=0.0;
for(k=(i+Slowing-1);k k--) // 只计算i前的Slowing次循环
{
sumlow+=Close[k]-LowesBuffer[k];
sumhigh+=HighesBuffer[k]-LowesBuffer[k];
}
if(sumhigh==0.0) MainBuffer[i]=100.0;
else MainBuffer[i]=sumlow/sumhigh*100; //简单平均
i--;
}
//---- last counted bar will be recounted
if(counted_bars 0) counted_bars--;
int limit=Bars-counted_bars;
//---- signal line(D) is simple movimg average
for(i=0; iMainBuffer[i+1]) K_Buffer[i]=MainBuffer[i];
}
return(0);
}
//+------------------------------------------------------------------+
外汇交易有很大的风险性,本站所有资源均来自网络,请选择使用,如若出现亏损,本站不承担任何责任!