以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  逐K线如何实现即时止损  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=73771)

--  作者:zsg465341578
--  发布时间:2014/12/30 16:16:04
--  逐K线如何实现即时止损
老师好,请教:在期指1分钟周期里面,用逐K线模式作图表式自动交易,我想在亏损的当根K线未走完时及时进行止损平仓,以避免在极端行情下的秒上(下)带的重大损失,请问代码怎么实现?
--  作者:jinzhe
--  发布时间:2014/12/30 16:30:07
--  
使用固定时间间隔模式,时间间隔设置为1秒
图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看

--  作者:zsg465341578
--  发布时间:2014/12/30 16:34:45
--  
老师,这样的话,盘中会有信号闪烁导致的开仓或平仓单---我的只想在止损上实现实时止损,开仓平仓仍按K线走完模式
--  作者:zsg465341578
--  发布时间:2014/12/30 16:37:27
--  

是否可以继续执行逐K线模式,也不改变策略代码,只在下单设置里面在固定止损上打勾(设置好后)?



--  作者:pyd
--  发布时间:2014/12/30 16:37:44
--  

勾选固定时间间隔,止盈止损用本周的条件,开平仓条件用上周期条件,ref(开仓条件,1)

这样既可以及时止盈止损,也可以避免开平仓信号闪烁

[此贴子已经被作者于2014/12/30 16:38:42编辑过]

--  作者:zsg465341578
--  发布时间:2014/12/30 16:45:53
--  
麻烦老师举例说明一下,谢谢
--  作者:jinzhe
--  发布时间:2014/12/30 17:01:32
--  

把开仓条件改成ref(开仓条件,1),平仓不变


--  作者:zsg465341578
--  发布时间:2014/12/30 17:03:02
--  
老师,是否是这样调整策略代码:
原来的代码:
if kd then begin
   sellshort(1,0,market),orderqueue;
   buy(holding=0,1,market),orderqueue;
end
 
if kk then begin
   sell(1,0,market),orderqueue;
   buyshort(holding=0,1,market),orderqueue;
end

if pd or (enterprice-c)>=10 then sell(holding>0,0,market);
if pk or (c-enterprice)>=10 then sellshort(holding<0,0,market);

改后的代码:
if ref(kd,1) then begin
   sellshort(1,0,limitr,o),orderqueue;
   buy(holding=0,1,limitr,o),orderqueue;
end
 
if ref(kk,1) then begin
   sell(1,0,limitr,o),orderqueue;
   buyshort(holding=0,1,limitr,o),orderqueue;
end

if ref(pd,1)  or (enterprice-c)>=10 then sell(holding>0,0,market),orderqueue;
if ref(pk,1)  or (c-enterprice)>=10 then sellshort(holding<0,0,market),orderqueue;

--  作者:jinzhe
--  发布时间:2014/12/30 17:05:10
--  
要走完k线就ref,不需要走完k线希望立即下单的,不要加
--  作者:zsg465341578
--  发布时间:2014/12/30 17:13:01
--  
我的开仓需要走完K线,平仓和止损不要走完K线,上述表达对吗?