以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://weistock.com/bbs/index.asp) -- 公式模型编写问题提交 (http://weistock.com/bbs/list.asp?boardid=4) ---- BUY(COND,V,Type,P);的格式问题。 (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=64885) |
-- 作者:qq代人发帖 -- 发布时间:2014/5/12 8:57:42 -- BUY(COND,V,Type,P);的格式问题。 请教:如果我用 if then begin 语句定义了一系列的开仓条件 以及开仓价格 ,那么在接下来的写开仓命令
还是要按照BUY(COND,V,Type,P);的格式写吗? 这是cond已经在前面定义一大堆了,后面如何处理?
|
-- 作者:jinzhe -- 发布时间:2014/5/12 9:00:50 -- 这个有什么疑问吗?cond写好后,后面就是下单数量,下单类型,下单价格 |
-- 作者:727181386w -- 发布时间:2014/5/12 9:31:21 -- 这是问题 我是初学者,在自己练习学写海龟模型,其中遇到了些问题,写出来的代码在K线图上没有交易显示,而且测试只有一次开仓,到最后测试日强制平仓。 还有这个问题,一直困扰我,估计很多初学者也会遇到:如果我用 if then begin 语句定义了一系列的开仓条件 以及开仓价格 ,那么在接下来的写开仓命令 还是要按照BUY(COND,V,Type,P);的格式写吗? 这是cond已经在前面定义一大堆了,后面如何处理 这是我的代码,大神给指导下呗,也有利于其他初学者学习。谢谢 //声明参数 input:D20(20,10,60,1);; input:D10(10,5,30,1); input:ATRL(13,5,30,1); input: risk(1,0.5,5,0.1) //声明变量 VARIABLE:H20:=close; VARIABLE:L20:=CLOSE; VARIABLE:H10:=Close; VARIABLE:L10:=CLOSE; //VARIABLE :_DEBUG: = 1 ;
//是否输出前台交易指令 (借鉴) VARIABLE:myenterprice:=0; //初始开仓价格; VARIABLE:myexitprice:=0;//初始平仓价格 VARIABLE:units:=0;//交易单位 VARIABLE:position:=0;//初始仓位 VARIABLE:sendorderthisbar:=0; Variable:units:=0; Variable:tunits:=0; VARIABLE:jdcond:=0; VARIABLE:pdcond:=0; VARIABLE:dzcond:=0; VARIABLE:jkcond:=0; VARIABLE:pkcond:=0; VARIABLE:kzcond:=0; H20:=ref(HHV(h,20),1); L20:=ref(LLV(l,20),1); H10:=ref(HHV(h,10),1); L10:=ref(LLV(l,10),1); KD:=c>H20; //开多条件 PD:=c<L10; //平多条件 KK:=c<L20; //开空条件 PK:=c>H10; //平空条件 N:=ma(TR,ATRL); units:=ASSET*risk*0.01/N; //建立仓位 if BARPOS=1 then begin end; //初始化; if position=0 and BARPOS>D20 and h>l then begin //建立多头仓位 if KD then BEGIN myentryprice:=if(open>H20+MINDIFF, open ,H20+MINdiff); buy(KD,units,LIMITR,myentryprice); position:=1; tuntis:=1; sendoederthisbar:=1; end; //建立空头仓位 if KK then begin myentryprice:=if(open<L20-MINDIFF ,open ,L20-MINDIFF); BUYSHORT( KK,units,LIMITR,myentryprice); position:=-1; tunits:=1; sendorderthisbar:=1; end end // jdcond:=( position=1 and BARPOS>D20 and H>l ) ; if jdcond then begin //多头加仓 WHILE (h>myentryprice+0.5*N) and tunits<4 do begin myentryprice:=if(open>myentryprice+0.5*N,open,myentryprice+0.5*N); myentryprice:=CEILING(myentryprice/MINDIFF)*Mindiff; buy( (h>myentryprice+0.5*N) and tunits<4 ,units,LIMITR,myentryprice); position:=1; tunits:=tunits+1; sendoederthisbar:=1; end //多头离场 pdcond:= pd and sendorderthisbar=0 ; if pdcond then begin myexitprice:=if(open<L10-MINDIFF,open,L10-MINDIFF); sell( pdcond, 0,limitr,myexitprice); position:=0; tunits:=0; end //多头止损 dzcond:=( low<myentryprice-2*N and position=1 and sendorderthisbar=0) if dzcond then begin myexitprice:=if(open<myentryprice-2*N,open,myentryprice-2*N); myexitprice:=floor(myexitprice/MINDIFF)*mindiff; sell( dzcond,0,limitr,myexitprice); position:=0; tunits:=0; ENd; end //加仓 jkcond:= (position=-1 and BARPOS>d20 and H>l) ; if jkcond then begin //空头加仓 WHILE (L<myentryprice-0.5*N) and tunits<4 do begin myentryprice:=if(open<myentryprice-0.5*N,open,myentryprice-0.5*N); myentryprice:=floor(myentryprice/MINDIFF)*Mindiff; buyshort( (L<myentryprice-0.5*N) and tunits<4,units,LIMITR,myentryprice); position:=-1; tunits:=tunits+1; sendoederthisbar:=1; end //空头离场 pkcond:= pk and sendorderthisbar=0 ; if pkcond then begin myexitrice:=if(open>H10+MINDIFF,open,h10+MINDIFF); sellshort( pkcond,0,limitr,myexitprice); position:=0; tunits:=0; end //空头止损 kzcond:=( h>myentryprice+2*N and position=-1 and sendorderthisbar=0) if kzcond then begin myexitprice:=if(open>myentryprice+2*N,open,myentryprice+2*N); myexitprice:=CEILING(myexitprice/MINDIFF)*mindiff; sellshort( kzcond,0,limitr,myexitprice); position:=0; tunits:=0; ENd; end //信号语句排列规则——先平后开 //“费率设置”按钮——用于合理设置模型“费率”,以便在图形上正确输出如下帐户信息: { 持仓:holding,linethick0; 资产:asset,noaxis; 可用现金:cash(0),linethick0; } |
-- 作者:jinzhe -- 发布时间:2014/5/12 9:55:09 -- 1循环是用来干什么的?这样写是为了实现什么目标? [此贴子已经被作者于2014/5/12 9:55:22编辑过]
|
-- 作者:727181386w -- 发布时间:2014/5/12 9:59:25 -- 这个是比照金字塔系统里面的海龟原程序写的,循环是加仓到4次为止。 我再试试 原系统里面设置了一个VARIABLE : _DEBUG = 1 ;后面就用_DEBUG代替所有定义的开仓条件了,不知道这个下划线的变量是什么意思,下划线有什么特殊功能吗? |
-- 作者:jinzhe -- 发布时间:2014/5/12 10:13:33 -- 这个没有特殊的意义,作者喜欢定义变量的时候给变量里面加个下划线 |
-- 作者:jinzhe -- 发布时间:2014/5/12 10:14:20 -- 图表里面的循环不要用啊,你那样写不符合图表思路 直接IF判断 |
-- 作者:727181386w -- 发布时间:2014/5/12 11:16:39 -- 改后还是不能正常 我把循环删了,没有加仓环节了,buy等交易指令后的cond也都改了 还是只有第一次开仓后面没有交易和平仓了 这是怎么回事呢 谢谢老师 //声明参数 input:D20(20,10,60,1);; input:D10(10,5,30,1); input:ATRL(13,5,30,1); input: risk(1,0.5,5,0.1) //声明变量 VARIABLE:H20:=close; VARIABLE:L20:=CLOSE; VARIABLE:H10:=Close; VARIABLE:L10:=CLOSE; VARIABLE:myenterprice:=0; //初始开仓价格; VARIABLE:myexitprice:=0;//初始平仓价格 VARIABLE:units:=0;//交易单位 VARIABLE:position:=0;//初始仓位 VARIABLE:sendorderthisbar:=0; H20:=ref(HHV(h,20),1); L20:=ref(LLV(l,20),1); H10:=ref(HHV(h,10),1); L10:=ref(LLV(l,10),1); KD:=c>H20; //开多条件 PD:=c<L10; //平多条件 KK:=c<L20; //开空条件 PK:=c>H10; //平空条件 N:=ma(TR,ATRL); units:=ASSET*risk*0.01/N; //建立仓位 if BARPOS=1 then begin end; //初始化; if position=0 and BARPOS>D20 and h>l then begin //建立多头仓位 if KD then BEGIN myentryprice:=if(open>H20+MINDIFF, open ,H20+MINdiff); buy(KD,units,LIMITR,myentryprice); position:=1; tuntis:=1; sendoederthisbar:=1; end; //建立空头仓位 if KK then begin myentryprice:=if(open<L20-MINDIFF ,open ,L20-MINDIFF); BUYSHORT( KK,units,LIMITR,myentryprice); position:=-1; tunits:=1; sendorderthisbar:=1; end end if position=1 and BARPOS>D20 and H>l then begin //多头离场 pdcond:= pd and sendorderthisbar=0 ; if pdcond then begin myexitprice:=if(open<L10-MINDIFF,open,L10-MINDIFF); sell( pdcond, holding,limitr,myexitprice); position:=0; end //多头止损 dzcond:= low<myentryprice-2*N and position=1 and sendorderthisbar=0 ; if dzcond then begin myexitprice:=if(open<myentryprice-2*N,open,myentryprice-2*N); myexitprice:=floor(myexitprice/MINDIFF)*mindiff; sell( dzcond,holding,limitr,myexitprice); position:=0; ENd; end if position=-1 and BARPOS>d20 and H>l then begin //空头离场 pkcond:= pk and sendorderthisbar=0 ; if pkcond then begin myexitrice:=if(open>H10+MINDIFF,open,h10+MINDIFF); sellshort( pkcond,HOLDING,limitr,myexitprice); position:=0; end //空头止损 kzcond:= h>myentryprice+2*N and position=-1 and sendorderthisbar=0; if kzcond then begin myexitprice:=if(open>myentryprice+2*N,open,myentryprice+2*N); myexitprice:=CEILING(myexitprice/MINDIFF)*mindiff; sellshort( kzcond,HOLDING,limitr,myexitprice); position:=0; ENd; end //信号语句排列规则——先平后开 //“费率设置”按钮——用于合理设置模型“费率”,以便在图形上正确输出如下帐户信息: 持仓:asset,linethick0; |
-- 作者:jinzhe -- 发布时间:2014/5/12 11:21:05 -- http://www.weistock.com/bbs/dispbbs.asp?boardid=4&id=1246&page=1&star=1 这个是金字塔调试的基本办法,你先试试自己调试下看看
你的说法是图表只有开仓没有平仓,那么就该调试输出一下平仓条件,看看有什么问题。 你把平仓条件逐一输出,看看是哪个你认为应该成立但是没有成立的平仓条件出了问题 [此贴子已经被作者于2014/5/12 11:21:47编辑过]
|