金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
12
返回列表 发新帖
楼主: 若水97783

求助一个程序的编写

[复制链接]

44

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
发表于 2025-3-21 09:44 | 显示全部楼层
// 参数设置
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);
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 微信登录

本版积分规则

手机版|小黑屋|上海金之塔信息技术有限公司 ( 沪ICP备13035422号 )

GMT+8, 2025-9-13 09:04 , Processed in 0.098310 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表