//開始編寫屬于您自己的交易指標吧!GO!
//該模型為簡單示范模型,用戶需根據(jù)自己交易經(jīng)驗,修改完善后再實際應(yīng)用!!!
//author: fjasmine
input: t20(20,15,60,1);//參數(shù)名,缺省值,最小值,最大值,步長
input: t10(10,10,30,1);
input: atrlen(20,15,30,1);
input: posnum(1,1,20,1);
variable:daycount=1,positioncount=1,sellsign=0;//定義了三個常數(shù)變量,分別賦值
variable:entandexitsign=1,entpoint=0,exitpoint=0;//定義了三個常數(shù)變量,分別賦值
variable:n=0;//定義常數(shù)變量N,初始化值為0
ma1:ma(c,5);//輸出五日均價
ma2:ma(c,10);//輸出十日均價
m:=ma(tr,20);//輸出20日均價
buyhhv:=hhv(h,20);//20日最高價
sellllv:=llv(l,10);//20日最低價
ss:n,linethick0;
nt:=1;//調(diào)試信息帶有時間戳
buyorderthisbar:=0;//當前BAR有過交易
variable: _debug = 1; //是否輸出前臺的交易指令
variable: _tdebug = 1; //是否輸出后臺的交易指令
variable: _debugout = 0; //是否輸出后臺交易的調(diào)試信息
variable: myentryprice = 0;//開倉價格
variable: myxitprice = 0;//平倉價格
variable: turtleunits = 0;//交易單位
variable: position = 0;//倉位狀態(tài)
//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);
//開始執(zhí)行時,初始化數(shù)據(jù)
if barpos = 1 then begin
//position : = 0;
end//if
//如果是當時沒有持倉的狀態(tài)
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
//不要轉(zhuǎn)跳,讓程序檢查同一根K線是否可以加倉
//gotocontinueline;
end//if
//如果當前持有多頭倉位的狀態(tài)
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循環(huán)結(jié)束
//建立多頭離場條件
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//如果從上市到現(xiàn)在加以日等于21,那么
n:=m;//n=m
if daycount =6 or barpos = 21 then begin//五天調(diào)整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;//頭寸計數(shù)
sellsign:=true;//開始以stop賣出,如果達到指定的價格
end
if positioncount=1 then begin//第一頭寸
how:=cash(0)*0.01/n;//波動性百分比決定頭寸規(guī)模
open1:buy(h>=enterprice+0.5*n,how,market);//在20日新高stop指令買進
end
if positioncount = 2 then begin//第二頭寸
how:=cash(0)*0.01/n;//波動性百分比決定頭寸規(guī)模
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;//波動性百分比決定頭寸規(guī)模
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;//波動性百分比決定頭寸規(guī)模
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;{頭寸計算復(fù)原}
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;//顯示我的資產(chǎn)
available_cash:cash(0),linethick0;//可用現(xiàn)金
pos:holding,linethick0;
toaldaytrade1:totaldaytrade,linethick0;//總交易次數(shù)
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 currentposition:holding,colorgray,linethick0;//當前持倉
the currentcaptal:asset,noaxis,colorgray;//當前資產(chǎn)
改好了,但是你這個很多變量后面少了空格是什么情況?
[此貼子已經(jīng)被作者于2013/7/30 9:31:14編輯過]
//開始編寫屬于您自己的交易指標吧!GO!
//該模型為簡單示范模型,用戶需根據(jù)自己交易經(jīng)驗,修改完善后再實際應(yīng)用!!!
//author: fjasmine
input: t20(20,15,60,1);//參數(shù)名,缺省值,最小值,最大值,步長
input: t10(10,10,30,1);
input: atrlen(20,15,30,1);
input: posnum(1,1,20,1);
variable:daycount=1,positioncount=1,sellsign=0;//定義了三個常數(shù)變量,分別賦值
variable:entandexitsign=1,entpoint=0,exitpoint=0;//定義了三個常數(shù)變量,分別賦值
variable:n=0;//定義常數(shù)變量N,初始化值為0
ma1:ma(c,5);//輸出五日均價
ma2:ma(c,10);//輸出十日均價
m:=ma(tr,20);//輸出20日均價
buyhhv:=hhv(h,20);//20日最高價
sellllv:=llv(l,10);//20日最低價
ss:n,linethick0;
nt:=1;//調(diào)試信息帶有時間戳
buyorderthisbar:=0;//當前BAR有過交易
variable: _debug = 1; //是否輸出前臺的交易指令
variable: _tdebug = 1; //是否輸出后臺的交易指令
variable: _debugout = 0; //是否輸出后臺交易的調(diào)試信息
variable: myentryprice = 0;//開倉價格
variable: myxitprice = 0;//平倉價格
variable: turtleunits = 0;//交易單位
variable: position = 0;//倉位狀態(tài)
//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);
//開始執(zhí)行時,初始化數(shù)據(jù)
if barpos = 1 then begin
//position : = 0;
end//if
//如果是當時沒有持倉的狀態(tài)
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
//不要轉(zhuǎn)跳,讓程序檢查同一根K線是否可以加倉
//gotocontinueline;
end//if
//如果當前持有多頭倉位的狀態(tài)
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循環(huán)結(jié)束
//建立多頭離場條件
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//如果從上市到現(xiàn)在加以日等于21,那么
n:=m;//n=m
if daycount =6 or barpos = 21 then begin//五天調(diào)整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;//頭寸計數(shù)
sellsign:=true;//開始以stop賣出,如果達到指定的價格
end
if positioncount=1 then begin//第一頭寸
how:=cash(0)*0.01/n;//波動性百分比決定頭寸規(guī)模
open1:buy(h>=enterprice+0.5*n,how,market);//在20日新高stop指令買進
end
if positioncount = 2 then begin//第二頭寸
how:=cash(0)*0.01/n;//波動性百分比決定頭寸規(guī)模
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;//波動性百分比決定頭寸規(guī)模
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;//波動性百分比決定頭寸規(guī)模
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;{頭寸計算復(fù)原}
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;//顯示我的資產(chǎn)
available_cash:cash(0),linethick0;//可用現(xiàn)金
pos:holding,linethick0;
toaldaytrade1:totaldaytrade,linethick0;//總交易次數(shù)
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 currentposition:holding,colorgray,linethick0;//當前持倉
the currentcaptal:asset,noaxis,colorgray;//當前資產(chǎn)
此主題相關(guān)圖片如下:8$n0{ih0v12k2gdd557psg.jpg
改好了,但是你這個很多變量后面少了空格是什么情況?
剛剛用你改好的: