6[i过]系统自带Stochastic 汉译KD

//[i]Stochastic 汉译KD

property indicator_separate_window

property indicator_minimum 0

property indicator_maximum 100

property indicator_buffers 2

property indicator_color1 LightSeaGreen

property indicator_color2 Red

property indicator_level1 20.0

property indicator_level2 80.0

property indicator_levelcolor clrSilver

property indicator_levelstyle STYLE_DOT

input int K周期 = 5; // (实为RSV周期)
input int D周期 = 3; // (实为K周期)
input int 慢周期 =3; // (实为D周期)

double 主线组[];
double 信线组[];
double 区顶序组[];
double 区底序组[];

//---
int 始绘处1 = 0;
int 始绘处2 = 0;

//-----------初始化---------------+

int OnInit(void)
{
//--用在计算中的两组缓存
IndicatorBuffers(4);
SetIndexBuffer(2, 区顶序组);
SetIndexBuffer(3, 区底序组);

//--指标线
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0, 主线组);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1, 信线组);

//--名称
string 名称="Sto("+IntegerToString(K周期)+","+IntegerToString(D周期)+","+IntegerToString(慢周期)+")";
IndicatorShortName(名称);
SetIndexLabel(0,名称);
SetIndexLabel(1,"Signal");

//--
始绘处1= K周期+慢周期;
始绘处2= 始绘处1+D周期;
SetIndexDrawBegin(0,始绘处1);
SetIndexDrawBegin(1,始绘处2);

//--初始化结束

return(INIT_SUCCEEDED);
}

//----------主函数---------------+

int OnCalculate(const int 总需棒数,
const int 已计,
const datetime &K时组[],
const double &K开组[],
const double &K高组[],
const double &K低组[],
const double &K收组[],
const long &tick_volume[],
const long &volume[],
const int &spread[]){

int i,
k,
pos;

//--检查
if(总需棒数<=K周期+D周期+慢周期)
return(0);

//--设置为序列数组
ArraySetAsSeries(主线组,false);
ArraySetAsSeries(信线组,false);
ArraySetAsSeries(区顶序组,false);
ArraySetAsSeries(区底序组,false);

ArraySetAsSeries(K低组,false);
ArraySetAsSeries(K高组,false);
ArraySetAsSeries(K收组,false);

//--
pos= K周期-1;
if(pos+1<已计)
pos= 已计-2;
else{
for(i=0; i<pos; i++){
区底序组[i]= 0.0;
区顶序组[i]= 0.0;
}
}

//--找到最小值与最大值 并赋于数组
for(i=pos; i<总需棒数 && !IsStopped(); i++){
double 最小值= 1000000.0;
double 最大值= -1000000.0;
for(k=i-K周期+1; k<=i; k++){
if(最小值>K低组[k])
最小值= K低组[k];
if(最大值<K高组[k])
最大值= K高组[k];
}
区底序组[i]= 最小值;
区顶序组[i]= 最大值;
}

//--
pos= K周期-1 +慢周期-1;
if(pos+1<已计)
pos= 已计-2;
else{
for(i=0; i<pos; i++)
主线组[i]= 0.0;
}

//--主线(%RSV)
for(i=pos; i<总需棒数 && !IsStopped(); i++){
double 收低差和= 0.0;
double 高低差和= 0.0;
for(k=(i-慢周期+1); k<=i; k++){
收低差和 += (K收组[k]-区底序组[k]);
高低差和 += (区顶序组[k]-区底序组[k]);
}
if(高低差和==0.0)
主线组[i]= 100.0;
else
主线组[i]= 收低差和/高低差和*100.0;
}
//--信号线(%K)
pos= D周期-1;
if(pos+1<已计)
pos= 已计-2;
else{
for(i=0; i<pos; i++)
信线组[i]=0.0;
}
for(i=pos; i<总需棒数 && !IsStopped(); i++){
double sum= 0.0;
for(k=0; k<D周期; k++)
sum += 主线组[i-k];
信线组[i]= sum/D周期;
}

//--主循环结束,返回新的己计
return(总需棒数);
}

//----------谢谢点赞-----------+

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容