
等级: 新手上路
- 注册:
- 2025-3-21
- 曾用名:
|
发表于 2025-3-21 09:40
来自手机
|
显示全部楼层
技术008 发表于 2025-3-21 08:55
这种都不行,都是描述性语句不足以直接写成策略的
// 参数设置
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:c(0); // 调整终点C
VARIABLE:bc_ratio(0); // BC段30%位置
VARIABLE:adj_start(0); // 调整起点价格
VARIABLE:adj_bars(0); // 调整持续K线数
// 计算AB段
if dir=0 then begin // 初始寻找方向
if close>ref(close,1)+x then begin
dir := 1;
a := ref(close,1);
b := close;
end else if close<ref(close,1)-x then begin
dir := -1;
a := ref(close,1);
b := close;
end;
end else if dir=1 then begin // 上涨趋势中
// 更新B点
if close > b then b := close;
// 记录回调
if close < ref(close,1) then begin
temp_adj := ref(close,1) - 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 barssince(close=b) >= max_bars*倍时 then begin
c := 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 > ref(close,1) then begin
temp_adj := close - ref(close,1);
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 barssince(close=b) >= max_bars*倍时 then begin
c := close;
bc_ratio := iff(dir=1, c + (b-c)*0.3, c - (c-b)*0.3);
dir := 0; // 重置进入新周期
end;
end;
end;
// 触发信号
if c>0 then begin
if (dir=1 and cross(close,bc_ratio)) or (dir=-1 and cross(bc_ratio,close)) 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); |
|