SMA-ADX
策略原理:
多头入场:价格大于65日均线,最高价大于均线,ADX均值大于20,最高价大于最近20日最高价上0.5倍ATR
空头入场:价格小于65日均线,最低价小于均线,ADX均值大于20,最低价小于最近20日最低价下0.5倍ATR
多头平仓:价格跌破均线
空头平仓:价格突破均线
回测曲线(由Auto-trader提供回测报告)
策略源码:
function Strategy1(default_unit,default_exitway,freq)%targetList = traderGetTargetList(); %获取目标资产信息HandleList = traderGetHandleList();%获取账户句柄for k=1:length(targetList); %--------------------仓位、K线、当前bar的提取-----------------------------% %获取当前仓位 [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(k).Market,targetList(k).Code); %策略中每次取数据的长度 lags=80; barnum=traderGetCurrentBar(targetList(k).Market,targetList(k).Code); %数据长度限制 if(barnum<lags) continue; end %获取K线数据 [time,open,high,low,close,volume,turnover,openinterest] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq, 0-lags, 0,false,'FWard'); if length(close)<lags continue; end; %-------------------------交易逻辑-------------------------------% %----------入场信号--------------------% [PDIma,NDIma,ADX]=DMI(close,high,low,14,14); TRvalue=TR(close,high,low); ATR=ma(TRvalue,20); ADXma=ma(ADX,18); ma1=ma(close,65); highest=est(high,1); lowest=est(low,-1); buycon=close(end)>ma1(end) && highest(end-1)>ma1(end) && ADXma(end)>20 && high(end)>max(high(end-20:end-2))+0.5*ATR(end); sellshortcon=close(end)<ma1(end) && lowest(end-1)<ma1(end) && ADXma(end)>20 && low(end)<min(low(end-20:end-2))-0.5*ATR(end); sellcon=close(end)<ma1(end); buytocovercon=close(end)>ma1(end); %---------------------------入场操作--------------------------------% if sellcon && marketposition>0 orderID1=traderPositionTo(HandleList(1),targetList(k).Market,targetList(k).Code,0,0,'market','sell'); if orderID1==0 continue; end; end; if buytocovercon && marketposition<0 orderID2=traderPositionTo(HandleList(1),targetList(k).Market,targetList(k).Code,0,0,'market','sell'); if orderID2==0 continue; end; end; if buycon && marketposition==0 buyunit=default_unit; orderID3=traderBuy(HandleList(1),targetList(k).Market,targetList(k).Code,buyunit,0,'market','buy'); if orderID3==0 continue; end; end; if sellshortcon && marketposition==0 sellshortunit=default_unit; orderID4=traderSellShort(HandleList(1),targetList(k).Market,targetList(k).Code,sellshortunit,0,'market','sell'); if orderID4==0 continue; end; end; endend
更多免费策略源码下载请登录DigQuant社区-策略资源下载~