-- 作者:z7c9
-- 发布时间:2011/10/3 11:17:12
-- [交易系统]恒温器策略
runmode:0;
input:bollingerlengths(50); input:trendliqlength(50); input:numstddevs(2); input:swingprcnt1(0.5); input:swingprcnt2(0.75); input:atrlength(10); input:swingtrendswitch(20);
variable:swing=false;
cmival:=abs(close-ref(close,30))/(hhv(high,30),1)-llv(low,30);
buyeasierday:=0; selleasierday:=0;
trendlokbuy:=ma(low,3); trendloksell:=ma(high,3);
keyofday:=(high+low+close)/3;
if close>keyofday then selleasierday:=1; else buyeasierday:=1; atr:=ma(tr,atrlength);
if ref(buyeasierday,1)=1 then begin swingbuypt:=open+swingprcnt1*atr; swingsellpt:=open-swingprcnt2*atr; end
if ref(selleasierday,1)=1 then begin swingbuypt:=open+swingprcnt2*atr; swingsellpt:=open-swingprcnt1*atr; end
swingbuypt:=max(swingbuypt,trendlokbuy); swingsellpt:=min(swingsellpt,trendloksell);
ma1:=ma(close,trendliqlength);
mid:=ma(close,bollingerlengths); trendbuypt:=mid+numstddevs*std(close,bollingerlengths); trendsellpt:=mid-numstddevs*std(close,bollingerlengths);
if cmival<swingtrendswitch then begin if holding=0 then begin if high>=swingbuypt then begin buy(1,1,limitr,max(open,swingbuypt)); swing:=true; end end if holding=0 then begin if low<=swingsellpt then begin buyshort(1,1,limitr,min(open,swingsellpt)); swing:=true; end end if holding>0 then begin if low<=swingsellpt then begin sell(1,holding,limitr,min(open,swingsellpt)); buyshort(1,1,limitr,min(open,swingsellpt)); swing:=true; end end if holding<0 then begin if high>=swingbuypt then begin sellshort(1,holding,limitr,max(open,swingbuypt)); buy(1,1,limitr,max(open,swingbuypt)); swing:=true; end end end else begin swingprotstop:=3*atr; if holding=0 then begin if high>=trendbuypt then begin buy(1,1,limitr,max(open,trendbuypt)); swing:=false; end end if holding=0 then begin if low<=trendsellpt then begin buyshort(1,1,limitr,min(open,trendsellpt)); swing:=false; end end if holding>0 then begin if swing then begin if low<=enterprice-swingprotstop then sell(1,holding,limitr,min(open,enterprice-swingprotstop)); end else begin if low<=ma1 then sell(1,holding,limitr,min(open,ma1)); end end if holding<0 then begin if swing then begin if high>=enterprice+swingprotstop then sellshort(1,holding,limitr,max(open,enterprice+swingprotstop)); end else begin if high>=ma1 then sellshort(1,holding,limitr,max(open,ma1)); end end end
盈亏:asset-50000,noaxis,colorred,linethick2;
|