金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 2388|回复: 7

请帮忙改改代码,感谢。

[复制链接]

30

主题

147

帖子

147

积分

等级: 免费版

注册:
2023-5-20
曾用名:
发表于 2023-5-23 22:41 | 显示全部楼层 |阅读模式
//交易系统
开多:BUY(开多平空条件 ,1,MARKET);
平多:SELL(开空平多条件,holding(),MARKET);
开空:BUYSHORT(开空平多条件,1,MARKET);
平空:SELLSHORT(开多平空条件,holding(),MARKET);
请修改,加上每笔交易单笔亏损不超三千元,否则强平,同时,若连续亏损了N笔,暂停此方向开单。

回复

使用道具 举报

30

主题

147

帖子

147

积分

等级: 免费版

注册:
2023-5-20
曾用名:
 楼主| 发表于 2023-5-23 22:45 | 显示全部楼层
封起的日子:

//交易系统
int max_loss_per_trade = 3000; //单笔交易最大亏损
int max_consecutive_losses = 3; //最大连续亏损笔数
int consecutive_losses = 0; //已连续亏损笔数
int holding_position = 0; //当前持仓数量
int holding_direction = 0; //当前持仓方向,1表示多头,-1表示空头

//开多
if (开多平空条件 && holding_direction != -1 && consecutive_losses < max_consecutive_losses) {
    int max_buy_quantity = (account_balance - max_loss_per_trade * holding_position) / 价格;
    int buy_quantity = min(max_buy_quantity, 1);
    BUY(buy_quantity, MARKET);
    holding_position += buy_quantity;
    holding_direction = 1;
    consecutive_losses = 0;
}


//平多
if (开空平多条件 &&  holding_direction == 1 )
{
    int sell_quantity = holding_position;
    SELL(sell_quantity, MARKET);
    holding_position = 0;
    holding_direction = 0;
}

//开空
if (开空平多条件 && holding_direction != 1 && consecutive_losses < max_consecutive_losses) {
    int max_sell_short_quantity = (account_balance - max_loss_per_trade * holding_position) / 价格;
    int sell_short_quantity = min(max_sell_short_quantity, 1);
    BUYSHORT(sell_short_quantity, MARKET);
    holding_position -= sell_short_quantity;
    holding_direction = -1;
    consecutive_losses = 0;
}
//平空
if (开多平空条件 && holding_direction == -1) {
    int buy_to_cover_quantity = abs(holding_position);
    SELLSHORT(buy_to_cover_quantity, MARKET);
    holding_position = 0;
    holding_direction = 0;
}

//计算当前交易盈亏
int current_profit_loss = holding_position * (当前价格 - 成本价);

//判断是否需要强平
if (current_profit_loss < -max_loss_per_trade) {
    if (holding_direction == 1) {
        SELL(holding_position, MARKET);
    } else if (holding_direction == -1) {
        SELLSHORT(abs(holding_position), MARKET);
    }
    holding_position = 0;
    holding_direction = 0;
    consecutive_losses = 0;
} else if (current_profit_loss < 0) {
    consecutive_losses++;
} else {
    consecutive_losses = 0;
}
-------------------------------------

这是CHATGPT给改的,所有
if语句全部编译通不过,在此基础上改也行,或者用简单的语句在上贴直接改也行,谢谢
回复

使用道具 举报

37

主题

9972

帖子

6万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
wenarm
发表于 2023-5-24 09:32 | 显示全部楼层
本帖最后由 技术006 于 2023-5-24 09:34 编辑

这是C的代码。不是pel语言的语法。建议你自己根据自己的策略思想,按照PEL的语法进行编写。
详情见https://www.weistock.com/docs/PE ... 8E%A7%E5%88%B6.html

注:完整的策略编写,我们可以提供一对一的付费编写服务。具体可以联系销售。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-5-24 10:13 | 显示全部楼层
[PEL] 复制代码
INPUT:N(3,1,100,1);
VARIABLE:lk:=0;//负数非0时候是空头连亏,正常非0是多头连亏次数

//若连续亏损了N笔,暂停此方向开单。



开多条件:1;
开空条件:1;
平多条件:1;
平空条件:1;


if 平空条件 and holding<0 then 
begin 
SELLSHORT(1,HOLDING,MARKET);
if lk>0 or NUMPROFIT(1)>0 then lk:=0;
IF NUMPROFIT(1)<0 THEN lk:=lk-1;
end 

开多:BUY(开多条件 and lk<N ,1,MARKET);



if 平多条件 and holding>0 then 
begin 
SELL(1,HOLDING,MARKET);
if lk<0 or NUMPROFIT(1)>0 then lk:=0;
IF NUMPROFIT(1)<0 THEN lk:=lk+1;
end 

开空:BUYSHORT(开空条件  and lk>-N ,1,MARKET);

if holding<>0 and OPENPROFIT<-3000 then 
begin 
多强平:sell(1,holding,market);
空强平:sellshort(1,holding,market);
end 


连亏次数:lk;



开平条件你自己去补充定义即可。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

30

主题

147

帖子

147

积分

等级: 免费版

注册:
2023-5-20
曾用名:
 楼主| 发表于 2023-5-27 10:08 | 显示全部楼层
谢谢
回复

使用道具 举报

30

主题

147

帖子

147

积分

等级: 免费版

注册:
2023-5-20
曾用名:
 楼主| 发表于 2023-6-16 21:01 | 显示全部楼层
SELLSHORT(1,HOLDING,MARKET);
SELL(1,HOLDING,MARKET);
多强平:sell(1,holding,market);
空强平:sellshort(1,holding,market);

上面四行括号中的1指的什么???
感谢解答!!!

补充内容 (2023-6-16 21:05):

SELLSHORT(平空条件,HOLDING,MARKET);
SELL(平多条件,HOLDING,MARKET);
多强平:sell(平多条件,holding,market);
空强平:sellshort(平空条件,holding,market);

是不是这样?
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-6-19 08:54 | 显示全部楼层

1 是条件参数。1 表示条件满足执行下单。
通常第一个参数需要把控制下单的条件 语句放进去来控制下单。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

30

主题

147

帖子

147

积分

等级: 免费版

注册:
2023-5-20
曾用名:
 楼主| 发表于 2023-6-19 21:51 | 显示全部楼层
谢谢谢谢!!!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-7 04:21 , Processed in 0.163929 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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