以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://weistock.com/bbs/index.asp) -- 公式模型编写问题提交 (http://weistock.com/bbs/list.asp?boardid=4) ---- 帮我看下我编写的东西好吗为什么出现句末木有分号 (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=54420) |
||||
-- 作者:武田晴信 -- 发布时间:2013/7/30 9:03:28 -- 帮我看下我编写的东西好吗为什么出现句末木有分号 刚刚用金字塔格式的传上去不能正常显示,这个是TXT文档的类型
|
||||
-- 作者:武田晴信 -- 发布时间:2013/7/30 9:23:07 -- 以前说程序不能直接复制到回复区,现在就放在TXT文档中 |
||||
-- 作者:武田晴信 -- 发布时间:2013/7/30 9:26:18 -- 已经出现了好几次这种情况了。有点郁闷 |
||||
-- 作者:jinzhe -- 发布时间:2013/7/30 9:30:41 --
//该模型为简单示范模型,用户需根据自己交易经验,修改完善后再实际应用!!! //author: fjasmine
input: atrlen(20,15,30,1); input: posnum(1,1,20,1); variable:daycount=1,positioncount=1,sellsign=0;//定义了三个常数变量,分别赋值 variable:entandexitsign=1,entpoint=0,exitpoint=0;//定义了三个常数变量,分别赋值 variable:n=0;//定义常数变量N,初始化值为0 ma2:ma(c,10);//输出十日均价 m:=ma(tr,20);//输出20日均价 buyhhv:=hhv(h,20);//20日最高价 sellllv:=llv(l,10);//20日最低价
ss:n,linethick0;
buyorderthisbar:=0;//当前BAR有过交易 variable: _tdebug = 1; //是否输出后台的交易指令 variable: _debugout = 0; //是否输出后台交易的调试信息
variable: myentryprice = 0;//开仓价格 variable: myxitprice = 0;//平仓价格
variable: turtleunits = 0;//交易单位 variable: position = 0;//仓位状态
//0表示没有仓位,1表示持有多头,-1表示持有空头
variable: t20hi=close; variable: t20lo=close;
variable: t10hi=close; variable: t10lo=close;
//需要准备计算的变量 t20hi=:ref(hhv(h,t20),1);// t20lp=:ref(llv(h,t20),1);//
t10hi=:ref(hhv(h,t10),1); t10lo=:ref(llv(h,t10),1);
avgtr:=ref(ma(tr,atrlen),1);
//开始执行时,初始化数据
if barpos = 1 then begin //position : = 0;
end//if
//如果是当时没有持仓的状态 if position=0 and barpos > t20 andh>l then begin
//建立多头进场条件
long:=h>t20hi;
//多头进场 iflong then begin myentryprice:=if(open>t20hi+mindiff,open,t20hi+mindiff); buy(_debug,posnum,limitr,myentryprice); position:=1; turtleunits:=1; n:=avgtr; buyorderthisbar:=1;
end//IF
//建立空头进场条件 short:=l<t20lo;
//空头进场 ifshort and position=0 then begin myentryprice:=if(open<t20lo-mindiff,open,t20lo-mindiff); buyshort(_debug,posnum,limitr,myentryprice); position:=-1; turtleunits:=1; n:=avgtr; buyorderthisbar:=1; end //不要转跳,让程序检查同一根K线是否可以加仓 //gotocontinueline;
end//if
//如果当前持有多头仓位的状态 ifposition=1 and barpos>t20 and h>l then begin //多头加仓条件 while(high>myentryprice+0.5*n) and turtleunits < 4 do begin myentryprice:=if(open>myentryprice+0.5*n,open,myentryprice+0.5*n); myentryprice:=ceiling(myentryprice/mindiff)*mindiff; buy(_debug,posnum,limitr,myentryprice); turtleunits:=turtleunits+1; buyorderthisbar:=1;
end//while循环结束
//建立多头离场条件 longx1:=(low<t10lo);
iflongx1 and buyorderthisbar=0 then begin myexitprice:=if(open<t10lo-mindiff,open,t10lo-mindiff); sell(_debug,0,limitr,myexitprice); position:=0; turtleunits:=0; end
//建立多头止损条件 longx2:= (low<myentryprice-2*n);
iflongx2 and position = 1 and buyorderthisbar=0 then begin myexitprice:=if(open<myentryprice-2*n,open,myentryprice-2*n); myexitprice:=floor(myexitprice/mindiff)*mindiff; sell(_debug,0,limitr,myexitprice); position:=0; turtleunits:=0; end
goto continueline;
end //if if barpos >= 21 or barpos=21 then begin//如果从上市到交易日大于21天那么 if barpos =21 then//如果从上市到现在加以日等于21,那么 n:=m;//n=m if daycount =6 or barpos = 21 then begin//五天调整N值 n:=(19*n+tr)/20;//计算N的值 daycount:=2; end daycount:=daycount+1; entpoint:=enterbars+1; if entpoint=entandexitsign then begin//说明stop指令买进头寸成功 positioncount:=positioncount+1;//头寸计数 sellsign:=true;//开始以stop卖出,如果达到指定的价格 end if positioncount=1 then begin//第一头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open1:buy(h>=enterprice+0.5*n,how,market);//在20日新高stop指令买进 end if positioncount = 2 then begin//第二头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open2:buy(h>enterprice+0.5*n,how,market);//在上头寸(即第一头寸)+0.5个N新高stop指令买进 end if positioncount=3 then begin//第三头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open3:buy(h>=enterprice+0.5*n,how,market);//在上头寸(即第二头寸)+0.5个N新高stop指令买进 end if positioncount = 4 then begin //第四头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open4:buy(h>=enterprice+0.5*n,how,market); //在上头寸(即第三头寸)+0.5个N新高stop指令买进 end
if sellsign = true then begin exitpoint:=exitbars+1; ifexitpoint = entandexitsign then begin //说明卖出成功 positioncount:=1;{头寸计算复原} sellsign:=false; end ifenterprice-2*n then sell(l<sellllv,100%,market);{退出亏损头寸} else sell(l<enterprice-2*n,100%,market); end end
continueline@ mycount:asset,linethick0;//显示我的资产 available_cash:cash(0),linethick0;//可用现金 pos:holding,linethick0; toaldaytrade1:totaldaytrade,linethick0;//总交易次数
if _debugout>0 then begin debugfile2(\'c:debugfile.txt\',\'barpos=%.of\',barpos,nt); debugfile2(\'c:debugfile.txt\',\'t20hi=%.2f\',t20hi,nt); debugfile2(\'c:debugfile.txt\',\'n=%.2f\',n,nt); debugfile2(\'c:debugfile.txt\',\'close=%.2f\',c,nt); debugfile2(\'c:debugfile.txt\',\'position=%.2f\',position,nt); debugfile2(\'c:debugfile.txt\',\'turtleunits=%.of\',turtleunits,nt); debugfile2(\'c:debugfile.txt\',\'myentryprice=%.of\',myentryprice,nt); debugfile2(\'c:debugfile.txt\',\'myexitprice=%.of\',myexitprice,nt); end
the currentcaptal:asset,noaxis,colorgray;//当前资产
改好了,但是你这个很多变量后面少了空格是什么情况? [此贴子已经被作者于2013/7/30 9:31:14编辑过]
|
||||
-- 作者:武田晴信 -- 发布时间:2013/7/30 9:46:22 -- 以下是引用jinzhe在2013/7/30 9:30:41的发言:
//该模型为简单示范模型,用户需根据自己交易经验,修改完善后再实际应用!!! //author: fjasmine
input: atrlen(20,15,30,1); input: posnum(1,1,20,1); variable:daycount=1,positioncount=1,sellsign=0;//定义了三个常数变量,分别赋值 variable:entandexitsign=1,entpoint=0,exitpoint=0;//定义了三个常数变量,分别赋值 variable:n=0;//定义常数变量N,初始化值为0 ma2:ma(c,10);//输出十日均价 m:=ma(tr,20);//输出20日均价 buyhhv:=hhv(h,20);//20日最高价 sellllv:=llv(l,10);//20日最低价
ss:n,linethick0;
buyorderthisbar:=0;//当前BAR有过交易 variable: _tdebug = 1; //是否输出后台的交易指令 variable: _debugout = 0; //是否输出后台交易的调试信息
variable: myentryprice = 0;//开仓价格 variable: myxitprice = 0;//平仓价格
variable: turtleunits = 0;//交易单位 variable: position = 0;//仓位状态
//0表示没有仓位,1表示持有多头,-1表示持有空头
variable: t20hi=close; variable: t20lo=close;
variable: t10hi=close; variable: t10lo=close;
//需要准备计算的变量 t20hi=:ref(hhv(h,t20),1);// t20lp=:ref(llv(h,t20),1);//
t10hi=:ref(hhv(h,t10),1); t10lo=:ref(llv(h,t10),1);
avgtr:=ref(ma(tr,atrlen),1);
//开始执行时,初始化数据
if barpos = 1 then begin //position : = 0;
end//if
//如果是当时没有持仓的状态 if position=0 and barpos > t20 andh>l then begin
//建立多头进场条件
long:=h>t20hi;
//多头进场 iflong then begin myentryprice:=if(open>t20hi+mindiff,open,t20hi+mindiff); buy(_debug,posnum,limitr,myentryprice); position:=1; turtleunits:=1; n:=avgtr; buyorderthisbar:=1;
end//IF
//建立空头进场条件 short:=l<t20lo;
//空头进场 ifshort and position=0 then begin myentryprice:=if(open<t20lo-mindiff,open,t20lo-mindiff); buyshort(_debug,posnum,limitr,myentryprice); position:=-1; turtleunits:=1; n:=avgtr; buyorderthisbar:=1; end //不要转跳,让程序检查同一根K线是否可以加仓 //gotocontinueline;
end//if
//如果当前持有多头仓位的状态 ifposition=1 and barpos>t20 and h>l then begin //多头加仓条件 while(high>myentryprice+0.5*n) and turtleunits < 4 do begin myentryprice:=if(open>myentryprice+0.5*n,open,myentryprice+0.5*n); myentryprice:=ceiling(myentryprice/mindiff)*mindiff; buy(_debug,posnum,limitr,myentryprice); turtleunits:=turtleunits+1; buyorderthisbar:=1;
end//while循环结束
//建立多头离场条件 longx1:=(low<t10lo);
iflongx1 and buyorderthisbar=0 then begin myexitprice:=if(open<t10lo-mindiff,open,t10lo-mindiff); sell(_debug,0,limitr,myexitprice); position:=0; turtleunits:=0; end
//建立多头止损条件 longx2:= (low<myentryprice-2*n);
iflongx2 and position = 1 and buyorderthisbar=0 then begin myexitprice:=if(open<myentryprice-2*n,open,myentryprice-2*n); myexitprice:=floor(myexitprice/mindiff)*mindiff; sell(_debug,0,limitr,myexitprice); position:=0; turtleunits:=0; end
goto continueline;
end //if if barpos >= 21 or barpos=21 then begin//如果从上市到交易日大于21天那么 if barpos =21 then//如果从上市到现在加以日等于21,那么 n:=m;//n=m if daycount =6 or barpos = 21 then begin//五天调整N值 n:=(19*n+tr)/20;//计算N的值 daycount:=2; end daycount:=daycount+1; entpoint:=enterbars+1; if entpoint=entandexitsign then begin//说明stop指令买进头寸成功 positioncount:=positioncount+1;//头寸计数 sellsign:=true;//开始以stop卖出,如果达到指定的价格 end if positioncount=1 then begin//第一头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open1:buy(h>=enterprice+0.5*n,how,market);//在20日新高stop指令买进 end if positioncount = 2 then begin//第二头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open2:buy(h>enterprice+0.5*n,how,market);//在上头寸(即第一头寸)+0.5个N新高stop指令买进 end if positioncount=3 then begin//第三头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open3:buy(h>=enterprice+0.5*n,how,market);//在上头寸(即第二头寸)+0.5个N新高stop指令买进 end if positioncount = 4 then begin //第四头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open4:buy(h>=enterprice+0.5*n,how,market); //在上头寸(即第三头寸)+0.5个N新高stop指令买进 end
if sellsign = true then begin exitpoint:=exitbars+1; ifexitpoint = entandexitsign then begin //说明卖出成功 positioncount:=1;{头寸计算复原} sellsign:=false; end ifenterprice-2*n then sell(l<sellllv,100%,market);{退出亏损头寸} else sell(l<enterprice-2*n,100%,market); end end
continueline@ mycount:asset,linethick0;//显示我的资产 available_cash:cash(0),linethick0;//可用现金 pos:holding,linethick0; toaldaytrade1:totaldaytrade,linethick0;//总交易次数
if _debugout>0 then begin debugfile2(\'c:debugfile.txt\',\'barpos=%.of\',barpos,nt); debugfile2(\'c:debugfile.txt\',\'t20hi=%.2f\',t20hi,nt); debugfile2(\'c:debugfile.txt\',\'n=%.2f\',n,nt); debugfile2(\'c:debugfile.txt\',\'close=%.2f\',c,nt); debugfile2(\'c:debugfile.txt\',\'position=%.2f\',position,nt); debugfile2(\'c:debugfile.txt\',\'turtleunits=%.of\',turtleunits,nt); debugfile2(\'c:debugfile.txt\',\'myentryprice=%.of\',myentryprice,nt); debugfile2(\'c:debugfile.txt\',\'myexitprice=%.of\',myexitprice,nt); end
the currentcaptal:asset,noaxis,colorgray;//当前资产
改好了,但是你这个很多变量后面少了空格是什么情况? 刚刚用你改好的: [此贴子已经被作者于2013/7/30 9:31:14编辑过]
|
||||
-- 作者:武田晴信 -- 发布时间:2013/7/30 9:47:09 -- 还是出现的是这个问题我确定我用的全部都是你帮我改好的代码因为我看不出来语法什么的错在哪儿了 |
||||
-- 作者:武田晴信 -- 发布时间:2013/7/30 9:54:27 -- 能不能 @JINZE 试试 |
||||
-- 作者:jinzhe -- 发布时间:2013/7/30 9:55:59 -- input: t20(20,15,60,1);//参数名,缺省值,最小值,最大值,步长 input: atrlen(20,15,30,1); input: posnum(1,1,20,1); variable:daycount=1,positioncount=1,sellsign=0;//定义了三个常数变量,分别赋值 variable:entandexitsign=1,entpoint=0,exitpoint=0;//定义了三个常数变量,分别赋值 variable:n=0;//定义常数变量N,初始化值为0 ma2:ma(c,10);//输出十日均价 m:=ma(tr,20);//输出20日均价 buyhhv:=hhv(h,20);//20日最高价 sellllv:=llv(l,10);//20日最低价
ss:n,linethick0;
buyorderthisbar:=0;//当前BAR有过交易 variable: _tdebug = 1; //是否输出后台的交易指令 variable: _debugout = 0; //是否输出后台交易的调试信息
variable: myentryprice = 0;//开仓价格 variable: myxitprice = 0;//平仓价格
variable: turtleunits = 0;//交易单位 variable: position = 0;//仓位状态
//0表示没有仓位,1表示持有多头,-1表示持有空头
variable: t20hi=close; variable: t20lo=close;
variable: t10hi=close; variable: t10lo=close;
//需要准备计算的变量 t20hi=:ref(hhv(h,t20),1);// t20lp=:ref(llv(h,t20),1);//
t10hi=:ref(hhv(h,t10),1); t10lo=:ref(llv(h,t10),1);
avgtr:=ref(ma(tr,atrlen),1);
//开始执行时,初始化数据
if barpos = 1 then begin //position : = 0;
end//if
//如果是当时没有持仓的状态 if position=0 and barpos > t20 and h>l then begin
//建立多头进场条件
long:=h>t20hi;
//多头进场 if long then begin myentryprice:=if(open>t20hi+mindiff,open,t20hi+mindiff); buy(_debug,posnum,limitr,myentryprice); position:=1; turtleunits:=1; n:=avgtr; buyorderthisbar:=1;
end//IF
//建立空头进场条件 short:=l<t20lo;
//空头进场 if short and position=0 then begin myentryprice:=if(open<t20lo-mindiff,open,t20lo-mindiff); buyshort(_debug,posnum,limitr,myentryprice); position:=-1; turtleunits:=1; n:=avgtr; buyorderthisbar:=1; end //不要转跳,让程序检查同一根K线是否可以加仓 //gotocontinueline;
end//if
//如果当前持有多头仓位的状态 if position=1 and barpos>t20 and h>l then begin //多头加仓条件 while high>myentryprice+0.5*n and turtleunits < 4 do begin myentryprice:=if(open>myentryprice+0.5*n,open,myentryprice+0.5*n); myentryprice:=ceiling(myentryprice/mindiff)*mindiff; buy(_debug,posnum,limitr,myentryprice); turtleunits:=turtleunits+1; buyorderthisbar:=1;
end//while循环结束
//建立多头离场条件 longx1:=(low<t10lo);
if longx1 and buyorderthisbar=0 then begin myexitprice:=if(open<t10lo-mindiff,open,t10lo-mindiff); sell(_debug,0,limitr,myexitprice); position:=0; turtleunits:=0; end
//建立多头止损条件 longx2:= (low<myentryprice-2*n);
if longx2 and position = 1 and buyorderthisbar=0 then begin myexitprice:=if(open<myentryprice-2*n,open,myentryprice-2*n); myexitprice:=floor(myexitprice/mindiff)*mindiff; sell(_debug,0,limitr,myexitprice); position:=0; turtleunits:=0; end
goto continueline;
end //if if barpos >= 21 or barpos=21 then begin//如果从上市到交易日大于21天那么 if barpos =21 then//如果从上市到现在加以日等于21,那么 n:=m;//n=m if daycount =6 or barpos = 21 then begin//五天调整N值 n:=(19*n+tr)/20;//计算N的值 daycount:=2; end daycount:=daycount+1; entpoint:=enterbars+1; if entpoint=entandexitsign then begin//说明stop指令买进头寸成功 positioncount:=positioncount+1;//头寸计数 sellsign:=true;//开始以stop卖出,如果达到指定的价格 end if positioncount=1 then begin//第一头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open1:buy(h>=enterprice+0.5*n,how,market);//在20日新高stop指令买进 end if positioncount = 2 then begin//第二头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open2:buy(h>enterprice+0.5*n,how,market);//在上头寸(即第一头寸)+0.5个N新高stop指令买进 end if positioncount=3 then begin//第三头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open3:buy(h>=enterprice+0.5*n,how,market);//在上头寸(即第二头寸)+0.5个N新高stop指令买进 end if positioncount = 4 then begin //第四头寸 how:=cash(0)*0.01/n;//波动性百分比决定头寸规模 open4:buy(h>=enterprice+0.5*n,how,market); //在上头寸(即第三头寸)+0.5个N新高stop指令买进 end
if sellsign = true then begin exitpoint:=exitbars+1; if exitpoint = entandexitsign then begin //说明卖出成功 positioncount:=1;{头寸计算复原} sellsign:=false; end if enterprice-2*n then sell(l<sellllv,100%,market);{退出亏损头寸} else sell(l<enterprice-2*n,100%,market); end end
continueline@ mycount:asset,linethick0;//显示我的资产 available_cash:cash(0),linethick0;//可用现金 pos:holding,linethick0; toaldaytrade1:totaldaytrade,linethick0;//总交易次数
if _debugout>0 then begin debugfile2(\'c:debugfile.txt\',\'barpos=%.of\',barpos,nt); debugfile2(\'c:debugfile.txt\',\'t20hi=%.2f\',t20hi,nt); debugfile2(\'c:debugfile.txt\',\'n=%.2f\',n,nt); debugfile2(\'c:debugfile.txt\',\'close=%.2f\',c,nt); debugfile2(\'c:debugfile.txt\',\'position=%.2f\',position,nt); debugfile2(\'c:debugfile.txt\',\'turtleunits=%.of\',turtleunits,nt); debugfile2(\'c:debugfile.txt\',\'myentryprice=%.of\',myentryprice,nt); debugfile2(\'c:debugfile.txt\',\'myexitprice=%.of\',myexitprice,nt); end
the currentcaptal:asset,noaxis,colorgray;//当前资产
{
} 持仓:holding,linethick0; 您可以在查看菜单->交易系统模板 中设置自己需要的模板 [此贴子已经被作者于2013/7/30 9:57:41编辑过]
|
||||
-- 作者:武田晴信 -- 发布时间:2013/7/30 9:57:57 -- 以下是引用jinzhe在2013/7/30 9:55:59的发言:
我直接是复制你的代码进编译器的
我改过后编译,没问题了, |