以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://222.73.7.161/bbs/index.asp) -- 公式模型编写问题提交 (http://222.73.7.161/bbs/list.asp?boardid=4) ---- [求助]怎样控制日内多品种交易总次数 (http://222.73.7.161/bbs/dispbbs.asp?boardid=4&id=167218) |
|
-- 作者:雪松fj303 -- 发布时间:2018/12/19 11:44:51 -- [求助]怎样控制日内多品种交易总次数 老师: 交易程序日内多品种怎样控制交易总次数?比如3次以内
|
|
-- 作者:FireScript -- 发布时间:2018/12/19 13:11:45 -- 这个帖子下面 2.2条。有代码范例的。
|
|
-- 作者:雪松fj303 -- 发布时间:2019/1/2 14:03:49 -- 老师:您好! 前些天请教限制当天开仓次数,我查了
|
|
-- 作者:FireScript -- 发布时间:2019/1/2 14:16:18 -- 我简单加载了下代码 看图表信号的话,这个应该是满足当日只开平一次的需求的啊。你说的测试是回测还是说实际模拟交易的情况呢? “买入平仓后再开仓,代码怎么写?”这个什么意思?是指空仓情况下才允许开仓吗?这个图表上应该也是已经控制过了得啊。
|
|
-- 作者:雪松fj303 -- 发布时间:2019/1/2 15:13:51 -- 老师:那是根据2.2贴模仿的。 我这样写对吗? variable:num=0;// 全局变量,来控制当天交易次数 cs:=1;//限定一天最多交易1次 ma5:=ma(close,5); ma20:=ma(close,20); cond1:=cross(ma5,ma20); cond2:=cross(ma20,ma5); if cond1 and holding<0 then begin sellshort(1,1,market); num:=0; end if cond1 and holding=0 and num<cs then begin buy(1,1,market); num:=num+1; end if cond2 and holding>0 then begin sell(1,1,market); num:=0; end if cond2 and holding=0 and num<cs then begin buyshort(1,1,market); num:=num+1; end abb:=(time0-timetot0(dynainfo(207))<=60) or not(islastbar);//提前60s下单 if abb and time=150000 then BEGIN 收盘平多:sell(1,1,LIMITR,C-mindiff); 收盘平空:sellshort(1,1,LIMITR,C+mindiff); NUM:=0; end //if time=closetime(0) then num:=0; 还是回测有2-3次的,是不是又是错的? |
|
-- 作者:FireScript -- 发布时间:2019/1/2 15:19:54 -- 那你看下 这里是不是勾了。
|
|
-- 作者:雪松fj303 -- 发布时间:2019/1/2 15:23:48 -- 这里打勾后同一天不同时间还是有多于一次的开仓 |
|
-- 作者:FireScript -- 发布时间:2019/1/2 15:31:16 -- 你这个交易一次是开多平多算一次,开空平空也算一次是吗? variable:num=0;// 全局变量,来控制当天交易次数 cs:=1;//限定一天最多交易1次 ma5:=ma(close,5); ma20:=ma(close,20); cond1:=cross(ma5,ma20); cond2:=cross(ma20,ma5); if cond1 and holding<0 then begin sellshort(1,1,market); num:=0; end if cond1 and holding=0 and num<cs then begin buy(1,1,market); num:=num+1; end if cond2 and holding>0 then begin sell(1,1,market); num:=0; end if cond2 and holding=0 and num<cs then begin buyshort(1,1,market); num:=num+1; end abb:=(time0-timetot0(dynainfo(207))<=60) or not(islastbar);//提前60s下单 if abb and time=150000 then BEGIN 收盘平多:sell(1,1,LIMITR,C-mindiff); 收盘平空:sellshort(1,1,LIMITR,C+mindiff); NUM:=0; end 上面代码我调整了下把num重置只放在最后一个K。你看下是否满足需求。还有6楼那个我意思是不要打钩。 |
|
-- 作者:雪松fj303 -- 发布时间:2019/1/2 15:41:02 -- 我把NUM重置只放在平多、或只放在收盘平仓两种都回测,还是不能一天开仓一次(含开多或开空) |
|
-- 作者:FireScript -- 发布时间:2019/1/2 15:47:34 -- 我知道怎么回事了。 variable:num=0;// 全局变量,来控制当天交易次数
if TODAYBAR=1 or BARPOS=1 then num:=0; cs:=1;//限定一天最多交易1次 ma5:=ma(close,5); ma20:=ma(close,20); cond1:=cross(ma5,ma20); cond2:=cross(ma20,ma5); if cond1 and holding<0 then begin sellshort(1,1,market); end if cond1 and holding=0 and num<cs then begin buy(1,1,market); num:=num+1; end if cond2 and holding>0 then begin sell(1,1,market); end if cond2 and holding=0 and num<cs then begin buyshort(1,1,market); num:=num+1; end abb:(time0-timetot0(dynainfo(207))<=60) or not(islastbar);//提前60s下单 if abb and time=150000 then BEGIN 收盘平多:sell(1,1,LIMITR,C-mindiff); 收盘平空:sellshort(1,1,LIMITR,C+mindiff); end num的重置放在当天第一个K最合理。 [此贴子已经被作者于2019/1/2 15:50:58编辑过]
|