 
等级: 超级版主
- 注册:
- 2021-5-18
- 曾用名:
|
// 参数设置
INPUT:x(50,1,1000,1); // 设置AB段触发点数
INPUT:倍数(3,1,10,1); // 调整幅度倍数
INPUT:倍时(2,1,10,1); // 调整时间倍数
// 变量声明
VARIABLE:dir=0; // 方向 1涨 -1跌
VARIABLE:a=0,b=0; // AB段起点终点
VARIABLE:max_adj=0; // AB段最大调整幅度
VARIABLE:max_bars=0; // AB段最长调整时间
variable:c1=0 ; // 调整终点C
VARIABLE:bc_ratio=0; // BC段30%位置
VARIABLE:adj_start=0; // 调整起点价格
VARIABLE:adj_bars=0; // 调整持续K线数
// 计算AB段
temp:=ref(close,1);
temp1:=barssince(close=b);
if dir=0 then begin // 初始寻找方向
if close>temp+x then begin
dir := 1;
a := temp;
b := close;
end else if close<temp-x then begin
dir := -1;
a := temp;
b := close;
end;
end else if dir=1 then begin // 上涨趋势中
// 更新B点
if close > b then b := close;
// 记录回调
if close < temp then begin
temp_adj := temp - close;
if temp_adj > max_adj then max_adj := temp_adj;
adj_bars := adj_bars + 1;
end else begin
if adj_bars > max_bars then max_bars := adj_bars;
adj_bars := 0;
end;
// 检测顶部调整
if close < b then begin
current_adj := b - close;
if current_adj >= max_adj*倍数 and temp1 >= max_bars*倍时 then begin
c1 := close;
bc_ratio := iff(dir=1, c + (b-c)*0.3, c - (c-b)*0.3);
dir := 0; // 重置进入新周期
end;
end;
end else if dir=-1 then begin // 下跌趋势中
// 更新B点
if close < b then b := close;
// 记录反弹
if close > temp then begin
temp_adj := close - temp;
if temp_adj > max_adj then max_adj := temp_adj;
adj_bars := adj_bars + 1;
end else begin
if adj_bars > max_bars then max_bars := adj_bars;
adj_bars := 0;
end;
// 检测底部调整
if close > b then begin
current_adj := close - b;
if current_adj >= max_adj*倍数 and temp1 >= max_bars*倍时 then begin
c1 := close;
bc_ratio := iff(dir=1, c + (b-c)*0.3, c - (c-b)*0.3);
dir := 0; // 重置进入新周期
end;
end;
end;
// 触发信号
temp3:=(dir=1 and cross(close,bc_ratio)) or (dir=-1 and cross(bc_ratio,close));
if c>0 then begin
if temp3 then begin
BUY(dir=1,1,market);
SELLSHORT(dir=-1,1,market);
DRAWICON(1,close,4); // 显示信号图标
end;
end;
// 画图辅助
DRAWTEXT(dir=1,a,'A',COLORRED);
DRAWTEXT(dir=1,b,'B',COLORRED);
DRAWTEXT(c>0,c,'C',COLORGREEN);
DRAWNUMBER(1,bc_ratio,bc_ratio,2,COLORCYAN); |
|