源碼解析理論
輸出INPUT:INB(20,1,500,1),OUTB(10,1,500,1),RISK(2,0,10,0.1)
輸出//和風(fēng)版海龜源碼VARIABLE:TIMES=0,I=0,N=0
RN賦值:1日前的真實(shí)波幅的20日指數(shù)移動(dòng)平均
N賦值:如果HOLDING=0,返回RN,否則返回上個(gè)輸出值
RH賦值:1日前的最高價(jià)
RL賦值:1日前的最低價(jià)
輸出H1:INB日內(nèi)RH的最高值
輸出H2:OUTB日內(nèi)RH的最高值,LINEDOT
輸出L1:INB日內(nèi)RL的最低值
輸出L2:OUTB日內(nèi)RL的最低值,LINEDOT
輸出LOTST:ASSET*RISK*0.01/(N*2*期貨每手乘數(shù)),線寬為0
LOTS賦值:如果RISK=0,返回1,否則返回LOTST
示固定開1手TBC賦值:H<>L
//判斷是否停板PARTLINE(HOLDING>0,ENTERPRICE-2*N)
條件判斷 BARPOS<INB+1 THEN EXIT
開多BEGINBUYP賦值:開盤價(jià)和H1的較大值
開倉買入
TIMES賦值:1
DOBEGINBUYP賦值:開盤價(jià)和ENTERPRICE+N*0.5的較大值
開倉買入
TIMES賦值:TIMES+1
END
//連續(xù)開倉END
開空BEGINSELLP賦值:開盤價(jià)和L1的較小值
平倉買入
TIMES賦值:1
DOBEGINSELLP賦值:開盤價(jià)和ENTERPRICE-N*0.5的較小值
平倉買入
TIMES賦值:TIMES+1
END
//連續(xù)開倉END
END
ITLONGP賦值:ENTERPRICE-2*N和L2的較大值
出場BEGINEXITP賦值:開盤價(jià)和EXITLONGP的較小值
平倉賣出
TIMES賦值:0
END
開多BEGINBUYP賦值:開盤價(jià)和ENTERPRICE+N*0.5的較大值
開倉買入
TIMES賦值:TIMES+1
END
//連續(xù)開倉END
//ELSEEND
ITLONGP賦值:ENTERPRICE+2*N和H2的較小值
出場BEGINEXITP賦值:開盤價(jià)和EXITLONGP的較大值
開倉賣出
TIMES賦值:0
END
開多BEGINSELLP賦值:開盤價(jià)和ENTERPRICE-N*0.5的較小值
平倉買入
TIMES賦值:TIMES+1
END
//連續(xù)開倉END
//ELSEEND
//HOLDING<0
源碼:
input:inb(20,1,500,1),outb(10,1,500,1),risk(2,0,10,0.1);
//和風(fēng)版海龜源碼
variable:times=0,i=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),linedot;
l1:llv(rl,inb);
l2:llv(rl,outb),linedot;
lotst:asset*risk*0.01/(n*2*multiplier),linethick0;
lots:=if(risk=0,1,lotst); //如果risk取0,表示固定開1手
tbc:=h<>l;//判斷是否停板
partline(holding>0,enterprice-2*n);
if barpos<inb+1 then exit;
if holding=0 and tbc then //不是停板才可以交易
begin
if h>h1 then //開多
begin
buyp:=max(o,h1);
buy(1,lots,limitr,buyp);
times:=1;
while h>enterprice+n*0.5 and times<4 do
begin
buyp:=max(o,enterprice+n*0.5);
buy(1,lots,limitr,buyp);
times:=times+1;
end;//連續(xù)開倉
end;//開多結(jié)束
else if l<l1 then //開空
begin
sellp:=min(o,l1);
buyshort(1,lots,limitr,sellp);
times:=1;
while l<enterprice-n*0.5 and times<4 do
begin
sellp:=min(o,enterprice-n*0.5);
buyshort(1,lots,limitr,sellp);
times:=times+1;
end;//連續(xù)開倉
end;
end;//holding=0
if holding>0 and tbc then //已有多倉
begin // www.kzuj.com.cn
exitlongp:=max(enterprice-2*n,l2);
if l<exitlongp and enterbars<>0 then //出場
begin
exitp:=min(o,exitlongp);
sell(1,0,limitr,exitp);
times:=0;
end;//出場
else
begin
while h>enterprice+n*0.5 and times<4 do //開多
begin
buyp:=max(o,enterprice+n*0.5);
buy(1,lots,limitr,buyp);
times:=times+1;
end;//連續(xù)開倉
end;//else
end;//holding>0
if holding<0 and tbc then //已有空倉
begin
exitlongp:=min(enterprice+2*n,h2);
if h>exitlongp and enterbars<>0 then //出場
begin
exitp:=max(o,exitlongp);
sellshort(1,0,limitr,exitp);
times:=0;
end;//出場
else
begin
while l<enterprice-n*0.5 and times<4 do //開多
begin
sellp:=min(o,enterprice-n*0.5);
buyshort(1,lots,limitr,sellp);
times:=times+1;
end;//連續(xù)開倉
end;//else
end;//holding<0