金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 222|回复: 1

可以帮忙写一个平仓即锁仓,次日开仓如果有锁仓就平反向单子,无持仓就开新仓吗?

[复制链接]

54

主题

257

帖子

257

积分

Rank: 4

等级: 专业版

注册:
2021-10-19
曾用名:
发表于 2025-10-13 16:47 | 显示全部楼层 |阅读模式
可以帮忙写一个平仓即锁仓,次日开仓如果有锁仓就平反向单子,无持仓就开新仓吗?备注:用来做股指期货,避免日内高昂手续费


补充内容 (2025-10-13 16:49):
用于后台交易指令控制模块
回复

使用道具 举报

2

主题

5577

帖子

5577

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-24
曾用名:
发表于 2025-10-14 09:11 | 显示全部楼层
参考下面范例,这个范例本身不是针对你需求的,但是也满足你这里情况。你自行做一些调整 测试下:


[PEL] 复制代码
input:ss(6,1,100,1);

//这里暂忽略多空锁仓时候数量不一致的情况
//所有仓位读取 在下面这部分代码中提前读取好,如果在下单条件那里判断 下单后仓位变化会影响到后续逻辑。
多头持仓:tbuyholdingex('','',1);
空头持仓:tsellholdingex('','',1);

多头今仓:tbuyholdingex('','',0);//多头今仓
多头老仓:多头持仓-多头今仓;//多头老仓

空头今仓:tsellholdingex('','',0);//空头今仓
空头老仓:空头持仓-空头今仓;//空头老仓

开多:mod(TODAYBAR,5)=0;
开空:mod(TODAYBAR,5)=1;
平多:mod(TODAYBAR,5)=2;
平空:mod(TODAYBAR,5)=3;

//有昨日老仓时,只平仓;
//空仓后只开仓;
//持仓满足一多一空后,有开仓信号则平另一个方向的;
//只有多或空持仓时,出现平仓信号时则开另一个方向的;


if time>=185500 then  GOTO here;//收盘前跳过常规开平语句

if  平多 and 多头持仓<>0 then
begin 
if 多头老仓<>0 then tsell(1,多头老仓,mkt);//有当前方向老仓情况下,直接优先平老仓 不开反向仓
if 多头今仓<>0 and 空头持仓=0 and 多头老仓=0 then tbuyshort(1,ss,mkt);//单边持仓且无当前方向老仓的情况下,平多转开空
end

if  平空 and 空头持仓<>0 then
begin 
if 空头老仓<>0 then tsellshort(1,空头老仓,mkt);
if 空头今仓<>0 and 多头持仓=0 and 空头老仓=0 then tbuy(1,ss,mkt);
end


if  开多  then
begin 
if 空头老仓<>0 then tsellshort(1,空头老仓,mkt);//有昨日空头老仓,开多转平空
if  多头持仓=0 and 空头老仓=0 then tbuy(1,ss,mkt);//多头无持仓时候 且 没有空头老仓时候直接开多
if 	多头持仓<>0 and 空头持仓<>0 and (空头老仓=0) then tsellshort(1,空头持仓,mkt);//锁仓状态下,开仓转平反向仓
end

if  开空 then
begin 
if 多头老仓<>0 then tsell(1,多头老仓,mkt);
if  空头持仓=0 and 多头老仓=0 then tbuyshort(1,ss,mkt);
if 	多头持仓<>0 and 空头持仓<>0 and (多头老仓=0) then tsell(1,多头持仓,mkt);	
end


here@;
//收盘无持仓则对锁
if time>=185500 and 空头持仓=0 and 多头持仓=0 then 
begin 
tbuy(1,ss,lmt,c);
tbuyshort(1,ss,lmt,c);	
end 



回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-10-29 23:09 , Processed in 0.153805 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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