|
4楼
楼主 |
发表于 2011-12-9 00:52:59
|
只看该作者
本帖最后由 金字塔客服 于 2011-12-9 16:59 编辑
NFS
//////////////////////////////////////////////////////
runmode:0;
input:entryperiod(1,1,5,1);
input:initialstop(3,2,4,1);
input:breakevenstop(4,2,4,1);
input:trailingstop(5,4,8,1);
input:exitperiod(2,1,5,1);
input:intraday(1,0,1,1);
input:money(0,0,10,1);
input:offset(0,0,2,1);
input:debug(0,0,1,1);
variable:costprice=0;
variable:stopline=0;
variable:myasset=30000;
begin
if stricmp(marketlabel,'sq')=0 then
label:=strleft(stklabel,2);
if stricmp(marketlabel,'dq')=0 then
label:=strleft(stklabel,1);
if stricmp(marketlabel,'zq')=0 then
label:=strleft(stklabel,2);
if stricmp(marketlabel,'zj')=0 then
label:=strleft(stklabel,2);
if stricmp(label,'if')=0 then begin
marginratio:=15/100;
commission:=0.6/10000;
tradeable:=1;
entrytime:=time>=093100 and time<=151400;
exittime:=time>=151500;
stoplossunit:=25*mindiff;
length:=60;
end else begin
if stricmp(label,'cf')=0 then begin
marginratio:=17/100;
commission:=12;
tradeable:=1;
end
if stricmp(label,'sr')=0 then begin
marginratio:=18/100;
commission:=6;
tradeable:=1;
end
entrytime:=time>=091600 and time<=145900;
exittime:=time>=150000;
stoplossunit:=5*mindiff;
length:=225;
end
end
if tradeable=0 then exit;
if not(datatype=1) then exit;
begin
cond:=date>ref(date,1) or barpos=1;
dist:=barpos-valuewhen(cond,barpos)+1;
averageprice:=trimprice(sum(amount,dist)/sum(vol,dist)/multiplier);
settlementprice:=trimprice(sum(amount,length)/sum(vol,length)/multiplier);
entryupperband:=ref(hhv(high,60*entryperiod),1)+mindiff;
entrylowerband:=ref(llv(low,60*entryperiod),1)-mindiff;
exitupperband:=ref(hhv(high,30*exitperiod),2)+mindiff;
exitlowerband:=ref(llv(low,30*exitperiod),2)-mindiff;
initialstopnum:=stoplossunit*initialstop;
breakevenstopnum:=stoplossunit*breakevenstop;
trailingstopnum:=stoplossunit*trailingstop;
offsetnum:=mindiff*offset;
end
if holding=0 then begin
myentryprice:=0;
lots:=0;
if year>=2011 and entrytime and high>=entryupperband then
myentryprice:=max(open,entryupperband);
if myentryprice>0 then begin
mycash:=cash(0);
if money=0 then begin
lots:=1;
end else begin
lots1:=intpart(mycash/(myentryprice*multiplier*marginratio));
lots2:=intpart(mycash*(money/100)/(initialstopnum*multiplier));
lots:=min(lots1,lots2);
end
end
if lots>=1 then
buy(1,lots,limitr,myentryprice+offsetnum);
end
if holding=0 then begin
myentryprice:=0;
lots:=0;
if year>=2011 and entrytime and low<=entrylowerband then
myentryprice:=min(open,entrylowerband);
if myentryprice>0 then begin
mycash:=cash(0);
if money=0 then begin
lots:=1;
end else begin
lots1:=intpart(mycash/(myentryprice*multiplier*marginratio));
lots2:=intpart(mycash*(money/100)/(initialstopnum*multiplier));
lots:=min(lots1,lots2);
end
end
if lots>=1 then
buyshort(1,lots,limitr,myentryprice-offsetnum);
end
if holding>0 then begin
myexitprice:=0;
if exittime then begin
if intraday=0 then begin
myexitprice:=open;
end else begin
if not(costprice<averageprice and averageprice<stopline) then
myexitprice:=open;
end
end
if stopline>0 and low<=stopline then
myexitprice:=min(open,stopline);
if stopline=0 then begin
if commission>1 then
costprice:=enterprice+2*commission/multiplier;
else
costprice:=enterprice*(1+commission)/(1-commission);
costprice:=ceiling(costprice/mindiff)*mindiff;
stopline:=costprice-initialstopnum;
end
if stopline<costprice and high-breakevenstopnum>=costprice then
stopline:=costprice;
if stopline>=costprice and high-trailingstopnum>stopline then
stopline:=high-trailingstopnum;
if exitlowerband>stopline then
stopline:=exitlowerband;
if myexitprice>0 then begin
sell(1,holding,limitr,myexitprice-offsetnum);
costprice:=0;
stopline:=0;
myasset:=asset;
end
end
if holding<0 then begin
myexitprice:=0;
if exittime then begin
if intraday=0 then begin
myexitprice:=open;
end else begin
if not(costprice>averageprice and averageprice>stopline) then
myexitprice:=open;
end
end
if stopline>0 and high>=stopline then
myexitprice:=max(open,stopline);
if stopline=0 then begin
if commission>1 then
costprice:=enterprice-2*commission/multiplier;
else
costprice:=enterprice*(1-commission)/(1+commission);
costprice:=floor(costprice/mindiff)*mindiff;
stopline:=costprice+initialstopnum;
end
if stopline>costprice and low+breakevenstopnum<=costprice then
stopline:=costprice;
if stopline<=costprice and low+trailingstopnum<stopline then
stopline:=low+trailingstopnum;
if exitupperband<stopline then
stopline:=exitupperband;
if myexitprice>0 then begin
sellshort(1,holding,limitr,myexitprice+offsetnum);
costprice:=0;
stopline:=0;
myasset:=asset;
end
end
保证金:round(close*multiplier*marginratio),linethick0;
partline(1,averageprice,colorblue,2);
partline(entrytime and holding=0,entryupperband,colorred,2);
partline(entrytime and holding=0,entrylowerband,colorgreen,2);
if entrytime and holding=0 then begin
上轨:entryupperband,linethick0;
下轨:entrylowerband,linethick0;
end
if holding>0 then begin
多头成本:costprice,linethick0;
多头止损:stopline,linethick0;
多头盈亏:(stopline-costprice)*multiplier,linethick0;
drawicon(stopline<costprice,stopline,11);
drawicon(stopline=costprice,stopline,12);
drawicon(stopline>costprice,stopline,10);
end
if holding<0 then begin
空头成本:costprice,linethick0;
空头止损:stopline,linethick0;
空头盈亏:(costprice-stopline)*multiplier,linethick0;
drawicon(stopline>costprice,stopline,11);
drawicon(stopline=costprice,stopline,12);
drawicon(stopline<costprice,stopline,10);
end
if debug=1 then begin
资产:myasset,noaxis,linethick2,colormagenta;
收益:(myasset-30000)/30000,linethick0;
次数:totaltrade,linethick0;
胜率:percentwin,linethick0;
连亏:maxseqloss,linethick0;
连赢:maxseqwin,linethick0;
end
///////////////////////////////////////////////////////////////////////////
网格交易法
input:grid(3,1,60,1);
variable:level=0;
dist:=barslast(date<>ref(date,1));
oo:=ref(open,dist);
if holding=0 then begin
dnprice:=oo-grid*mindiff;
if low<=dnprice then begin
buy(1,1,limitr,dnprice);
level:=-1;
end
end
if holding=0 then begin
upprice:=oo+grid*mindiff;
if high>=upprice then begin
buyshort(1,1,limitr,upprice);
level:=1;
end
end
if holding>0 then begin
upprice:=oo+(level+1)*grid*mindiff;
dnprice:=oo+(level-1)*grid*mindiff;
if high>=upprice then begin
sell(1,1,limitr,upprice);
level:=level+1;
end
if low<=dnprice then begin
buy(1,1,limitr,dnprice);
level:=level-1;
end
if time=closetime(0) then
sell(1,holding,limitr,close);
end
if holding<0 then begin
upprice:=oo+(level+1)*grid*mindiff;
dnprice:=oo+(level-1)*grid*mindiff;
if low<=dnprice then begin
sellshort(1,1,limitr,dnprice);
level:=level-1;
end
if high>=upprice then begin
buyshort(1,1,limitr,upprice);
level:=level+1;
end
if time=closetime(0) then
sellshort(1,holding,limitr,close);
end
盈亏:asset,noaxis,colormagenta;
收益:(asset-50000)/50000,linethick0;
次数:totaltrade,linethick0;
胜率:percentwin,linethick0;
连亏:maxseqloss,linethick0;
连赢:maxseqwin,linethick0;
///////////////////////////////////////////////////////////////////////////
时空交易
input:n(11,1,20,1);
input:m(35,5,120,5);
longcond:=ref(close,1)-ref(close,n)>=m*mindiff;
longprice:=open;
shortcond:=ref(close,n)-ref(close,1)>=m*mindiff;
shortprice:=open;
if holding=0 then begin
if longcond then
buy(1,1,limitr,longprice);
end
if holding=0 then begin
if shortcond then
buyshort(1,1,limitr,shortprice);
end
if holding>0 then begin
if time=closetime(0) then
sell(1,holding,limitr,close);
end
if holding<0 then begin
if time=closetime(0) then
sellshort(1,holding,limitr,close);
end
收益:asset,noaxis,colormagenta;
次数:totaltrade,linethick0;
胜率:percentwin,linethick0;
连亏:maxseqloss,linethick0;
连赢:maxseqwin,linethick0;
//////////////////////////////////////////////////////////////////////////
|
|