利用收盘价,构造变形的5阶矩
多头入场条件为:当前高阶矩值大于由高阶矩构造的布林带上轨;
空头入场条件为:当前高阶矩的值低于高阶矩布林带下轨。反手出场。
回测曲线(由Auto-Trader软件提供回测报告):
策略代码:
function gflossadd(Freq,k,n)global record;targetList = traderGetTargetList();HandleList = traderGetHandleList();for i=1:length(targetList) marketposition=traderGetAccountPosition(HandleList(1),targetList(i).Market,targetList(i).Code); lags=200;%270 barnum=traderGetCurrentBar(targetList(i).Market,targetList(i).Code); if(barnum<=lags) continue; end dlags=40; [time,open,high,low,close,volume,turnover,openinterest] = traderGetKData(targetList(i).Market,targetList(i).Code,'min',Freq, 0-lags, 0,false,'FWard'); [Dtime,Dopen,Dhigh,Dlow,Dclose,Dvolume,~,~] = traderGetKData(targetList(i).Market,targetList(i).Code,'day',1, 0-dlags, 0,false,'FWard'); if length(close)<lags|| length(Dclose)<dlags continue; end; hmv=hma(close,k,n); len=100; gmean=mean(hmv(end-len:end)); gstd=std(hmv(end-len:end)); con1=hmv(end)<=gmean-3*gstd; con2=hmv(end)>=gmean+3*gstd; %% %止损线 ATR=ATR(Dhigh,Dlow,Dclose,20); %% %满仓上移 %-------------------------------满仓上移--------------% if record{i}.m>=3 if close(end)>record{i}.entryp+2*ATR(end)&&(marketposition>0) record{i}.entryp= record{i}.entryp+2*ATR(end); elseif close(end)<record{i}.entryp-2*ATR(end)&&(marketposition<0) record{i}.entryp= record{i}.entryp-2*ATR(end); end end %% %-------------------------平仓止损--------------------% %做多平仓 if marketposition>0&&record{i}.m~=0 if close(end)<record{i}.entryp-0.5*ATR(end) order= traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0,0,'market','sell'); if order~=0 record{i}.m=0; record{i}.entryp=close(end); end end end if marketposition<0&&record{i}.m~=0 if close(end)>record{i}.entryp+0.5*ATR(end) order= traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0,0,'market','sell'); if order~=0 record{i}.m=0; record{i}.entryp=close(end); end end end %% %入场 sharenum=5; %---------------入场-------------% if con1&&(record{i}.m==0)&&(marketposition==0) order=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum,0,'market','buy'); %%%%做多 if order~=0 record{i}.m= record{i}.m+1; record{i}.entryp=close(end); end end if con2&&(record{i}.m==0)&&(marketposition==0) order=traderSellShort(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum,0,'market','buy'); %%%%做多 if order~=0 record{i}.m= record{i}.m+1; record{i}.entryp=close(end); end end %% %-----------------加仓----------------% if close(end)>record{i}.entryp+2*ATR(end)&&(record{i}.m<3)&&(marketposition>0) order=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum,0,'market','buy'); %%%%做多 if order~=0 record{i}.m= record{i}.m+1; record{i}.entryp=close(end); end end if close(end)<record{i}.entryp-2*ATR(end)&&(record{i}.m<3)&&(marketposition<0) order=traderSellShort(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum,0,'market','buy'); %%%%做多 if order~=0 record{i}.m= record{i}.m+1; record{i}.entryp=close(end); end end endendfunction ATRValue=ATR(High,Low,Close,Length)ATRValue=zeros(length(High),1);TRValue=zeros(length(High),1);TRValue(2:end)=max([High(2:end)-Low(2:end) abs(High(2:end)-Close(1:end-1)) abs(Low(2:end)-Close(1:end-1))],[],2);ATRValue=MA(TRValue,Length);endfunction MAValue=MA(Price,Length)MAValue=zeros(length(Price),1);for i=Length:length(Price) MAValue(i)=sum(Price(i-Length+1:i))/Length;endMAValue(1:Length-1)=Price(1:Length-1);endfunction hmv=hma(price,k,n)hmv=zeros(length(price),1);hmv(1:n)=price(1:n);for i=n+1:length(price) hmv(i)=0.5*(mean(diff(price(i-n+1:i)).^k));endend
更多免费策略代码下载请登录DigQuant社区-策略资源下载~