以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://www.weistock.com/bbs/index.asp) -- 策略编写求助区 (http://www.weistock.com/bbs/list.asp?boardid=11) ---- 麻烦老师帮忙编写一个模块 (http://www.weistock.com/bbs/dispbbs.asp?boardid=11&id=11276) |
-- 作者:txdys2008 -- 发布时间:2012/4/24 23:26:00 -- 麻烦老师帮忙编写一个模块 老师您好,我希望您帮我编写一个可以在15分钟K线上全自动交易的模块:
有两个变量,分别是当天的开盘价OO,还有一个固定的数值KL
如果盘中价(市价)大于等于当天的开盘价OO加上KL的值,按照最新价(而不是K线收盘价)执行平空翻多指令; 如果盘中价(市价)小于等于当天的开盘价OO减去KL的值,按照最新价(而不是K线收盘价)执行平多翻空指令;
谢谢您!
|
-- 作者:rushtaotao -- 发布时间:2012/4/25 8:46:09 -- 正在处理 请稍等 |
-- 作者:rushtaotao -- 发布时间:2012/4/25 8:53:25 -- //这里自己将KL赋一个值 sellshort(c>Open+KL,0,market); if date<>ref(date,1) then sell(c<Open-KL,0,market); |
-- 作者:txdys2008 -- 发布时间:2012/4/25 8:56:25 -- 老师,您在里头使用了close,请问是不是会变成K线收盘才发信号? 还有里头的OPEN,好像是每根K线的开盘价吧,与当天的开盘价似乎不一样。 |
-- 作者:jinzhe -- 发布时间:2012/4/25 9:22:55 -- 有两个变量,分别是当天的开盘价OO,还有一个固定的数值KL
如果盘中价(市价)大于等于当天的开盘价OO加上KL的值,按照最新价(而不是K线收盘价)执行平空翻多指令; 如果盘中价(市价)小于等于当天的开盘价OO减去KL的值,按照最新价(而不是K线收盘价)执行平多翻空指令;
input:kl(20,1,1000,2);
oo:callstock(\'zjif00\',vtopen,6,0);
if c>oo+kl then begin sellshort(holding<0,0,limitr,c); buy(holding=0,1,limitr,c); end
if c<oo-kl then begin sell(holding>0,0,limitr,c); buyshort(holding=0,1,limitr,c); end//close在盘中就是最新价,公式只能用固定时间间隔模式
|
-- 作者:阿火 -- 发布时间:2012/4/25 9:26:06 -- oo:=valuewhen(date<>ref(date,1),open); yl:=oo+kL; zc:=oo-KL; if h>yl then begin if holding<0 then sellshort(1,1,limitr,max(o,yl+mindiff)+3*mindiff); if holding=0 then buy(1,1,limitr,max(o,yl+mindiff)+3*mindiff); end if l<zc then begin if holding>0 then sell(1,1,limitr,min(o,zc-mindiff)-3*mindiff); if holding=0 then buyshort(1,1,limitr,min(o,zc-mindiff)-3*mindiff); end
但是有可能出现“最高价大于上界同时最低价低于下界”的情况。 所以,最好用1分钟K线,会比15分钟更加精确。 即使这样,一般也要再加个条件,比如:open>oo;
即:(用于1分钟K线图) oo:=valuewhen(date<>ref(date,1),open); yl:=oo+kL; zc:=oo-KL; if h>yl and open>oo then begin if holding<0 then sellshort(1,1,limitr,max(o,yl+mindiff)+3*mindiff); if holding=0 then buy(1,1,limitr,max(o,yl+mindiff)+3*mindiff); end if l<zc and open<oo then begin if holding>0 then sell(1,1,limitr,min(o,zc-mindiff)-3*mindiff); if holding=0 then buyshort(1,1,limitr,min(o,zc-mindiff)-3*mindiff); end [此贴子已经被作者于2012-4-25 9:27:17编辑过]
|
-- 作者:rushtaotao -- 发布时间:2012/4/25 9:27:29 -- 呵呵,写错了,实在不好意思,open是该周期的开盘价!! c就是最新价,用固定时间间隔就可以一直刷新出最新价 |
-- 作者:txdys2008 -- 发布时间:2012/4/25 14:52:41 -- 请问老师,您写的代码里头,如果实盘全自动交易的话,是不是只能按照里头写的1手数量进行交易? |
-- 作者:jinzhe -- 发布时间:2012/4/25 15:13:27 -- 是的,下单手数需要自行控制 |