金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 564|回复: 5

代码怎样修改成固定手数一次平仓,不分批平仓?

[复制链接]

1

主题

3

帖子

3

积分

Rank: 1

等级: 新手上路

注册:
2024-11-27
曾用名:
发表于 2024-11-27 12:37 | 显示全部楼层 |阅读模式
variable:zs=c,hl=c;//声明全局变量zs、hl
ma7:=ma(c,7);
ma21:=ma(c,21);
atr:=ma(h-l,21);//市场平均波动幅度
buycond:=cross(ma7,ma21);//平空开多条件
sellcond:=cross(ma21,ma7);//平多开空条件

if holding>0 then begin
多止损:zs;
if l<zs then sell(1,1,limitr,min(o,zs)-mindiff);
else if sellcond then sell(1,1,limitr,c);
end

if holding<0 then begin
空止损:zs;
if h>zs then sellshort(1,1,limitr,max(o,zs)+mindiff);
else if buycond then sellshort(1,1,limitr,c);
end

if holding=0 and buycond then begin//多头开仓
buy(7,1,limitr,c);
zs:=c-2*atr;
hl:=c;//hl开仓后的最有利价位,刚买入时,最有利价位为开仓价
end

if holding=0 and sellcond then begin//空头开仓
buyshort(7,1,limitr,c);
zs:=c+2*atr;
hl:=c;
end

if holding>0 and enterbars>0 and h>hl then begin//最高价抬升,止损位相应地抬升
hl:=h;
zs:=hl-2*atr;
end

if holding<0 and enterbars>0 and l<hl then begin//最低价下降,止损位相应地下移
hl:=l;
zs:=l+2*atr;
end


设置了大于1手的手数会分批平仓。 怎样修改成设置用修改的固定手数进出场,不分批平仓?


如图:
如果两个都设置1,就是固定下1手,也是一次平仓
如果设置1,7  就是下7手,然后分7次平仓


我需要修改成,下单固定手数,然后出场一次平仓,不分批平仓




截图202411271236331393.png
截图202411271236213488.png
1.png
回复

使用道具 举报

0

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
gxx978
发表于 2024-11-27 13:25 | 显示全部楼层
参考如下,开仓和平仓语句的第2个参数是报单数量,不是第一个参数;开仓报7手,平仓用holding。
variable:zs=c,hl=c;//声明全局变量zs、hl
ma7:=ma(c,7);
ma21:=ma(c,21);
atr:=ma(h-l,21);//市场平均波动幅度
buycond:=cross(ma7,ma21);//平空开多条件
sellcond:=cross(ma21,ma7);//平多开空条件

if holding>0 then begin
多止损:zs;
if l<zs then sell(1,holding,limitr,min(o,zs)-mindiff);
else if sellcond then sell(1,holding,limitr,c);
end

if holding<0 then begin
空止损:zs;
if h>zs then sellshort(1,holding,limitr,max(o,zs)+mindiff);
else if buycond then sellshort(1,holding,limitr,c);
end

if holding=0 and buycond then begin//多头开仓
buy(1,7,limitr,c);
zs:=c-2*atr;
hl:=c;//hl开仓后的最有利价位,刚买入时,最有利价位为开仓价
end

if holding=0 and sellcond then begin//空头开仓
buyshort(1,7,limitr,c);
zs:=c+2*atr;
hl:=c;
end

if holding>0 and enterbars>0 and h>hl then begin//最高价抬升,止损位相应地抬升
hl:=h;
zs:=hl-2*atr;
end

if holding<0 and enterbars>0 and l<hl then begin//最低价下降,止损位相应地下移
hl:=l;
zs:=l+2*atr;
end
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

1

主题

3

帖子

3

积分

Rank: 1

等级: 新手上路

注册:
2024-11-27
曾用名:
发表于 2024-11-27 13:42 | 显示全部楼层
技术010 发表于 2024-11-27 13:25
参考如下,开仓和平仓语句的第2个参数是报单数量,不是第一个参数;开仓报7手,平仓用holding。
variable: ...

好的,我复制了你修改后的代码。

比如我要设置成固定手数用3手,一次平仓

是否如下这样设置的就可以?


if holding=0 and buycond then begin//多头开仓
buy(1,3,limitr,c);
zs:=c-2*atr;
hl:=c;//hl开仓后的最有利价位,刚买入时,最有利价位为开仓价
end

if holding=0 and sellcond then begin//空头开仓
buyshort(1,3,limitr,c);
zs:=c+2*atr;
hl:=c;
end



第二个数字设置成3,第一个数字代表什么呢?需要怎样设置?
回复

使用道具 举报

0

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
gxx978
发表于 2024-11-27 13:44 | 显示全部楼层
是的
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

1

主题

3

帖子

3

积分

Rank: 1

等级: 新手上路

注册:
2024-11-27
曾用名:
发表于 2024-11-28 21:42 | 显示全部楼层

您好,根据你的指导,现在已经可以是一次平仓。
这个策略的是两个均线的关系,但策略本身没有参数项可以输入,怎样写成有两个参数项,可以分别设置两个均线的值呢?
回复

使用道具 举报

0

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
gxx978
发表于 2024-11-29 08:58 | 显示全部楼层
那是因为你的代码中均线参数7和21在代码中写死了,可以用input来定义这个参数,例如:
input:n1(7,1,100,1),n2(21,1,100,1);
ma7:=ma(c,n1);
ma21:=ma(c,n2);
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-6 17:01 , Processed in 0.297270 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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