金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 4026|回复: 17

3655

[复制链接]

28

主题

153

帖子

163

积分

Rank: 2

等级: 标准版

注册:
2022-6-27
曾用名:
发表于 2023-7-25 17:15 | 显示全部楼层 |阅读模式
老师:
    你好!
策略加载:连续亏损3次,当日禁止开仓,,这个逻辑如何写?
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-7-25 17:23 | 显示全部楼层
本帖最后由 技术009 于 2023-7-25 17:25 编辑

[PEL] 复制代码
variable:num=0;                            // 全局变量
cs:=3;                                              //限定一天最多亏损3次
ma5:=ma(close, 5);
ma20:=ma(close, 20);
cond1:=cross(ma5,ma20);
cond2:=cross(ma20,ma5);
 
if cond2 and holding>0 then 
begin 
sell(1,1,market);
if NUMPROFIT(1)<0 then num:=num+1;     //平仓
if NUMPROFIT(1)>0 then num:=0;
end 
if cond1 and holding=0 and num<cs then             //开仓
begin
    buy(1,1,market);
end
if time=closetime(0) then num:=0;             // closetime(0)是取商品期货最后一节的交易时间,收盘的同时,num赋值为0。


参考这个范例试下
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

28

主题

153

帖子

163

积分

Rank: 2

等级: 标准版

注册:
2022-6-27
曾用名:
 楼主| 发表于 2023-7-25 18:13 | 显示全部楼层
//多
if PD and holding>0 then
begin
sell(1,SS,limitr,close);
if NUMPROFIT(1)<0 then num:=num+1;  //平多仓
if NUMPROFIT(1)>0 then num:=0;
end
if KD and holding=0 and num<cs then  //开多仓
begin
    buy(1,SS,limitr,close);
end
if time=closetime(0) then num:=0;

//空
if PK and holding>0 then
begin
SELLSHORT(1,SS,limitr,close);
if NUMPROFIT(1)<0 then num:=num+1;  //平空仓
if NUMPROFIT(1)>0 then num:=0;
end
if KK and holding=0 and num<cs then             //开空仓
begin
   BUYSHORT(1,SS,limitr,close);
end
if time=closetime(0) then num:=0;


老师,你看这样是否正确
回复

使用道具 举报

28

主题

153

帖子

163

积分

Rank: 2

等级: 标准版

注册:
2022-6-27
曾用名:
 楼主| 发表于 2023-7-25 19:18 | 显示全部楼层

TCD:=(time>=010000 and time<185700);
variable:num=0;  // 全局变量
cs:=3;  //限定一天最多亏损3次
MA1:=MA(C,20);
KD:=CLOSE>MA1;          //开多条件
PD:=CLOSE<MA1;          //平多条件
KK:=CLOSE<MA1;          //开空条件
PK:=CLOSE>MA1;          //平空条件

SS:=1;//手数

//多
if PD and holding>0 then
begin
sell(1,SS,limitr,close);
if NUMPROFIT(1)<0 then num:=num+1;  //平多仓
if NUMPROFIT(1)>0 then num:=0;
end
if KD and TCD and holding=0 and num<cs then  //开多仓
begin
    buy(1,SS,limitr,close);
end
if time=closetime(0) then num:=0;

//空
if PK and holding>0 then
begin
SELLSHORT(1,SS,limitr,close);
if NUMPROFIT(1)<0 then num:=num+1;  //平空仓
if NUMPROFIT(1)>0 then num:=0;
end
if KK and TCD and holding=0 and num<cs then             //开空仓
begin
   BUYSHORT(1,SS,limitr,close);
end
if time=closetime(0) then num:=0;

IF num>cs THEN BEGIN
        SETTRADESIGN(0);
END

//指定时间平仓
if time=185700 then begin
收盘A:sell(1,SS,LIMITR,CLOSE)COLORYELLOW;//平多
收盘:sellshort(1,SS,LIMITR,CLOSE)COLORGREEN;//平空
END

我这样写为什么不行呢?我加了一个禁止开仓就不行了,注释禁止开仓后,连亏3次后,还会开仓,哪里出现了问题?


补充内容 (2023-7-25 19:22):
我想要的效果,此策略当天亏损3次后,此策略禁止开仓
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-7-26 08:47 | 显示全部楼层
你前面一楼说的是连亏,上面代码处理的也是连亏的情况,如果只是亏损三次不会限制交易。

f PK and holding>0 then
begin
SELLSHORT(1,SS,limitr,close);
if NUMPROFIT(1)<0 then num:=num+1;  //平空仓
//if NUMPROFIT(1)>0 then num:=0;
end
平仓这里的语句去掉就是当日亏损三次就停止交易的意思了。


金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

28

主题

153

帖子

163

积分

Rank: 2

等级: 标准版

注册:
2022-6-27
曾用名:
 楼主| 发表于 2023-7-26 08:56 | 显示全部楼层
注释了平仓,效果还是不行,亏损3次后当天还在交易

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号? 微信登录

x
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-7-26 08:59 | 显示全部楼层
你只处理了平空,平多没改。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

28

主题

153

帖子

163

积分

Rank: 2

等级: 标准版

注册:
2022-6-27
曾用名:
 楼主| 发表于 2023-7-26 09:15 | 显示全部楼层
注释了平多空仓,效果还是不行,

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号? 微信登录

x
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-7-26 09:29 | 显示全部楼层
是要注释掉:
//if NUMPROFIT(1)>0 then num:=0;


但是平仓的地方:
if NUMPROFIT(1)<0 then num:=num+1;  //平空仓

这一句是需要的。

这样说明白了吗? 所有平仓地方都要这一句代码。不是让你把那部分整个的注释掉。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-7-26 09:42 | 显示全部楼层
[PEL] 复制代码
tcd:(time>=010000 and time<185700);
variable:num:=0;  // 全局变量
cs:=3;  //限定一天最多亏损3次
ma1:=ma(c,20);
kd:close>ma1;          //开多条件
pd:=close<ma1;          //平多条件
kk:=close<ma1;          //开空条件
pk:=close>ma1;          //平空条件

ss:=1;//手数

//多
if pd and holding>0 then
begin
sell(1,ss,limitr,close);
if numprofit(1)<0 then num:=num+1;  //平多仓
end

if kd and tcd and holding=0 and num<cs then  //开多仓
begin
buy(1,ss,limitr,close);
end


//空
if pk and holding<0 then
begin
sellshort(1,ss,limitr,close);
if numprofit(1)<0 then num:=num+1;  //平空仓
end

if kk and tcd and holding=0 and num<cs then             //开空仓
begin
   buyshort(1,ss,limitr,close);
end


if time=closetime(0) then num:=0;

亏损次数:num;
//指定时间平仓
if time=185700 then begin
收盘a:sell(1,ss,limitr,close)coloryellow;//平多
收盘:sellshort(1,ss,limitr,close)colorgreen;//平空
end

hd:holding;
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-28 23:03 , Processed in 0.131131 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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