K線包含關(guān)系的順序原則:先用第1、2根K線的包含關(guān)系確認(rèn)新的K線,然后用新的K線去和第3根比,如果有包含關(guān)系,繼續(xù)用包含關(guān)系的法則結(jié)合成新的K線;如果沒有,就按正常K線去處理。
程序代碼:
runmode:1;//序列模式;
i:=BARPOS;
variable:up1=0;//定義一個數(shù)組用來存放向上包含的k線高點;
variable:up2=0;//定義一個數(shù)組用來存放向上包含的k線低點;
variable:dn1=0;//定義一個數(shù)組用來存放向下包含的k線高點;
variable:dn2=0;//定義一個數(shù)組用來存放向下包含的k線低點;
beforehigh:=high[2];
beforelow:=low[2];
thishigh:=high[3];
thislow:=low[3];
upordn:=BARPOS;
aa:=setlbound(high,2);//設(shè)置序列變量high的下界為2,起始有效變量從第2根k線開始;
bb:=setlbound(low,2);//設(shè)置序列變量low的下界為2,起始有效變量從第2根k線開始;
for i=3 to BARPOS do//循環(huán)開始
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 //通過該循環(huán)對向上/向下數(shù)組循環(huán)賦值(將最近的up和dn數(shù)組值賦值給前一k線的高低點以便于和最新的k線高低點進行比較)
thishigh=high[i];
thislow=low[i];
if ((ThisHigh>=BeforeHigh) AND (ThisLow<=BeforeLow)) OR ((ThisHigh<=BeforeHigh) AND (ThisLow>=BeforeLow)) //循環(huán)開始,開始判斷包含關(guān)系;
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 //沒有包含關(guān)系
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); //該語句參數(shù)需要調(diào)整確認(rèn)
dd:=stickline(dn1[i]<dn2[i],dn1[i],dn2[i],8,1,colorred); //該語句參數(shù)需要調(diào)整確認(rèn)
end;
系統(tǒng)在剛進入循環(huán),if up1[i-1]>0 then 語句處,提醒說 數(shù)組越界操作; 盼請各位大拿開藥方診斷~!!!