K线包含关系的顺序原则:先用第1、2根K线的包含关系确认新的K线,然后用新的K线去和第3根比,如果有包含关系,继续用包含关系的法则结合成新的K线;如果没有,就按正常K线去处理。
程序代码:
runmode:1;//序列模式;
i:=BARPOS;
variable:up1=0;//定义一个数组用来存放向上包含的k线高点;
variable:up2=0;//定义一个数组用来存放向上包含的k线低点;
variable:dn1=0;//定义一个数组用来存放向下包含的k线高点;
variable:dn2=0;//定义一个数组用来存放向下包含的k线低点;
beforehigh:=high[2];
beforelow:=low[2];
thishigh:=high[3];
thislow:=low[3];
upordn:=BARPOS;
aa:=setlbound(high,2);//设置序列变量high的下界为2,起始有效变量从第2根k线开始;
bb:=setlbound(low,2);//设置序列变量low的下界为2,起始有效变量从第2根k线开始;
for i=3 to BARPOS do//循环开始
begin
upordn:=i;
if up1[i-1]>0 then
begin
beforehigh=up1[i-1];
beforelow=up2[i-1];
upordn=1;
end
if dn1[i-1]>0 then
begin
beforehigh=dn1[i-1];
beforelow=dn2[i-1];
upordn=-1;
end
else begin
beforehigh=high[i-1];
beforelow=low[i-1];
end //通过该循环对向上/向下数组循环赋值(将最近的up和dn数组值赋值给前一k线的高低点以便于和最新的k线高低点进行比较)
thishigh=high[i];
thislow=low[i];
if ((ThisHigh>=BeforeHigh) AND (ThisLow<=BeforeLow)) OR ((ThisHigh<=BeforeHigh) AND (ThisLow>=BeforeLow)) //循环开始,开始判断包含关系;
then begin
if upordn=1 then //向上包含
Up1[i] = MAX(ThisHigh, BeforeHigh);
Up2[i] = MAX(ThisLow, BeforeLow);
up1[i-1]=up1[i];
up2[i-1]=up2[i];
if upordn=-1 then //向下包含
dn1[i]=MIN(thishigh,beforehigh);
dn2[i]=MIN(thislow,beforelow);
dn1[i-1]=dn1[i];
dn2[i-1]=dn2[i];
end;
else //没有包含关系
if thishigh>beforehigh then begin//向上
up1[i]=thishigh;
up2[i]=thislow; end;
if thislow<beforelow then begin//向下
dn1[i]=thishigh;
dn2[i]=thislow; end;
cc:=stickline(up1[i]>up2[i],up1[i],up2[i],8,1,colorblue); //该语句参数需要调整确认
dd:=stickline(dn1[i]<dn2[i],dn1[i],dn2[i],8,1,colorred); //该语句参数需要调整确认
end;
系统在刚进入循环,if up1[i-1]>0 then 语句处,提醒说 数组越界操作; 盼请各位大拿开药方诊断~!!!