一个综合实例:
1、历史高点A——历史高点A之后的某波段次高点B 画线;红线
2、历史高点A——历史高点A之后的最低点C画线; 黄线
以下是我回复某论坛问题的公式代码,其中部分代码,可用本次介绍的排序函数来重写,有兴趣不妨动手试试:
复制内容到剪贴板
代码:
input:n(5,5,30);
fh:=high; fl:=low;
///以下找历史最高点,hh1表示最高价,phh1表示最高点位置///
hh1:=fh[1]; phh1:=1;
for i=1 to datacount do //从第1条K线开始,循环执行下面3条复合语句,直到K线结束
if hh1<fh[i] then begin //判断
hh1:=fh[i]; phh1:=i; //用hh1单值变量记录历史最高价,phh1记录位置
end;
///以下找phh1之后的最低点,ll表示最低价,pll最低点位置
if phh1<datacount then begin
ll:=fl[phh1+1];
for i=phh1 to datacount do
if ll>fl[i] then begin
ll:=fl[i]; pll:=i;
end;
end;
///以下用zig转折模拟波段,通过参数n来调整波的分布///
///找历史最高后的波峰最高点,hh2次高价,phh2位置///
tj:=peakbars(high,n,1)=0;
nstart:=max(lbound(tj),phh1+1);
if nstart<=datacount then begin
hh2:=0;
for i=nstart to datacount do
if tj[i] then begin
if hh2<fh[i] then begin
hh2:=fh[i];
phh2:=i;
end;
end;
end;
//////以下画线///////////
drawline(barpos=phh1,high,barpos=phh2,high,1),colormagenta;
drawline(barpos=phh1,high,barpos=pll,low,1),coloryellow;