以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://weistock.com/bbs/index.asp) -- 公式模型编写问题提交 (http://weistock.com/bbs/list.asp?boardid=4) ---- 请教老师公式问题 (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=97500) |
-- 作者:xwxlmb -- 发布时间:2016/5/17 9:19:38 -- 请教老师公式问题 请教老师,如何添加命令使程序在空仓状态下,系统发出开仓指令一次性执行定义的持仓量,并忽略平仓前的其它开仓信号。 input:inb(20,1,20,1),outb(10,1,20,1),risk(1,0,10,0.1); //海龟源码 variable:times=0,n=0; rn:=ema(ref(tr,1),20); n:=valuewhen(holding=0,rn); rh:=ref(h,1); rl:=ref(l,1); h1:hhv(rh,inb); h2:hhv(rh,outb); l1:llv(rl,inb); l2:llv(rl,outb); lotst:asset*risk*0.01/(n*multiplier); lots:=if(risk=0,1,lotst); //如果risk取0,表示固定开1手 tbc:=h<>l;//判断是否停板 if holding=0 and tbc then //不是停板才可以交易 begin if h>h1 then //开多 begin buyp:=max(o,h1); buy(1,lots,limitr,buyp); end;//开多结束 else if l<l1 then //开空 begin sellp:=min(o,l1 ); buyshort(1,lots,limitr,sellp); end;//开空结束 if holding>0 and tbc then //已有多仓 begin exitlongp:=max(enterprice,l2); if l<exitlongp and enterbars<>0 then //出场 begin exitp:=min(o,exitlongp); sell(1,0,limitr,exitp); end;//出场 if holding<0 and tbc then //已有空仓 begin exitlongp:=min(enterprice,h2); if h>exitlongp and enterbars<>0 then //出场 begin exitp:=max(o,exitlongp); sellshort(1,0,limitr,exitp); end;//出场 end; end; end; |
-- 作者:xwxlmb -- 发布时间:2016/5/17 9:22:23 -- 请教老师,如何添加命令使程序在空仓状态下,系统发出开仓指令一次性执行定义的持仓量,并忽略平仓前的其它开仓信号。 input:inb(20,1,20,1),outb(10,1,20,1),risk(1,0,10,0.1); //海龟源码 variable:times=0,n=0; rn:=ema(ref(tr,1),20); n:=valuewhen(holding=0,rn); rh:=ref(h,1); rl:=ref(l,1); h1:hhv(rh,inb); h2:hhv(rh,outb); l1:llv(rl,inb); l2:llv(rl,outb); lotst:asset*risk*0.01/(n*multiplier); lots:=if(risk=0,1,lotst); //如果risk取0,表示固定开1手 tbc:=h<>l;//判断是否停板 if holding=0 and tbc then //不是停板才可以交易 begin if h>h1 then //开多 begin buyp:=max(o,h1); buy(1,lots,limitr,buyp); end;//开多结束 else if l<l1 then //开空 begin sellp:=min(o,l1 ); buyshort(1,lots,limitr,sellp); end;//开空结束 if holding>0 and tbc then //已有多仓 begin exitlongp:=max(enterprice,l2); if l<exitlongp and enterbars<>0 then //出场 begin exitp:=min(o,exitlongp); sell(1,0,limitr,exitp); end;//出场 if holding<0 and tbc then //已有空仓 begin exitlongp:=min(enterprice,h2); if h>exitlongp and enterbars<>0 then //出场 begin exitp:=max(o,exitlongp); sellshort(1,0,limitr,exitp); end;//出场 end; end; end; |
-- 作者:jinzhe -- 发布时间:2016/5/17 9:24:37 -- 用IE发帖,然后格式发的准确一点 |
-- 作者:xwxlmb -- 发布时间:2016/5/17 9:29:58 -- input:inb(20,1,20,1),outb(10,1,20,1),risk(1,0,10,0.1); //海龟源码 variable:times=0,n=0; rn:=ema(ref(tr,1),20); n:=valuewhen(holding=0,rn); rh:=ref(h,1); rl:=ref(l,1); h1:hhv(rh,inb); h2:hhv(rh,outb); l1:llv(rl,inb); l2:llv(rl,outb); lotst:asset*risk*0.01/(n*multiplier); lots:=if(risk=0,1,lotst); //如果risk取0,表示固定开1手 tbc:=h<>l;//判断是否停板 if holding=0 and tbc then //不是停板才可以交易 begin if h>h1 then //开多 begin buyp:=max(o,h1); buy(1,lots,limitr,buyp); end;//开多结束 else if l<l1 then //开空 begin sellp:=min(o,l1 ); buyshort(1,lots,limitr,sellp); end;//开空结束 if holding>0 and tbc then //已有多仓 begin exitlongp:=max(enterprice,l2); if l<exitlongp and enterbars<>0 then //出场 begin exitp:=min(o,exitlongp); sell(1,0,limitr,exitp); end;//出场 if holding<0 and tbc then //已有空仓 begin exitlongp:=min(enterprice,h2); if h>exitlongp and enterbars<>0 then //出场 begin exitp:=max(o,exitlongp); sellshort(1,0,limitr,exitp); end;//出场 end; end; end; |
-- 作者:jinzhe -- 发布时间:2016/5/17 9:31:35 -- 系统发出开仓指令一次性执行定义的持仓量,并忽略平仓前的其它开仓信号 这句指的是什么情况? |
-- 作者:xwxlmb -- 发布时间:2016/5/17 9:37:12 -- 老师您试一下,开仓量被分成多次执行了,我想空仓状态第一次出信号开仓,如突破前20日高点开仓,反向2ATR止损、反向前10日低点止损或止盈,不加仓。 |
-- 作者:jinzhe -- 发布时间:2016/5/17 9:43:04 -- 海龟就是有多次加仓的,你想要不加仓,在开仓语句里面加上holding=0的判断 |
-- 作者:xwxlmb -- 发布时间:2016/5/17 9:57:03 -- 老师这样改对吗? input:inb(20,1,20,1),outb(10,1,20,1),risk(1,0,10,0.1); //海龟源码 variable:times=0,n=0; rn:=ema(ref(tr,1),20); n:=valuewhen(holding=0,rn); rh:=ref(h,1); rl:=ref(l,1); h1:hhv(rh,inb); h2:hhv(rh,outb); l1:llv(rl,inb); l2:llv(rl,outb); lotst:asset*risk*0.01/(n*multiplier); lots:=if(risk=0,1,lotst); //如果risk取0,表示固定开1手 tbc:=h<>l;//判断是否停板 if holding=0 and tbc then //不是停板才可以交易 begin if h>h1 then //开多 begin buyp:=max(o,h1); buy(1,lots,limitr,buyp); end;//开多结束 else if l<l1 then //开空 begin sellp:=min(o,l1 ); buyshort(1,lots,limitr,sellp); end;//开空结束 if holding=0 and tbc then //已有多仓 begin exitlongp:=max(enterprice,l2); if l<exitlongp and enterbars<>0 then //出场 begin exitp:=min(o,exitlongp); sell(1,0,limitr,exitp); end;//出场 if holding=0 and tbc then //已有空仓 begin exitlongp:=min(enterprice,h2); if h>exitlongp and enterbars<>0 then //出场 begin exitp:=max(o,exitlongp); sellshort(1,0,limitr,exitp); end;//出场 end; end; end; |
-- 作者:jinzhe -- 发布时间:2016/5/17 10:04:16 -- buy(1,lots,limitr,buyp);
buyshort(1,lots,limitr,sellp);
这两句改成
buy(holding=0,lots,limitr,buyp);
buyshort(holding=0,lots,limitr,sellp);
其他不要改 |
-- 作者:xwxlmb -- 发布时间:2016/5/17 10:06:11 -- 感谢老师的指导!下班试试。 |