对沪深300全市场股票扫描
入场条件:1. macd绿柱变短的时候
2. 5日均线上扬
3. 指数上扬
出场条件:止损线设为入场时的最低点
回测曲线(由Auto-trader提供回测报告)
策略源码:
- function GPDX(n) % 日内高抛低吸.
- % 其中,len为在多少日内全部完成突破
- targetList = traderGetTargetList(); % 在RunBackTest中选择好的标的.
- %获取目标资产信息
- HandleList = traderGetHandleList(); %
- %获取账户信息
- %=================================================================
- % RunBackTest的参数设置
- % n=200;
- %=================================================================
- global s; % 定义cc为全局变量
- if isempty(s) % 判断cc是否为空值
- for i=1:length(targetList)
- s(i).BarNLong=0;
- s(i).time=0;
- s(i).stopprice=0;
- s(i).openmacd=0;
- end
- end
- for i = 1:length(targetList)
- [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(i).Market,targetList(i).Code);
- %获取当前仓位
-
- lags=n; % lags为策略需要往前获取多少天
- %策略中每次取数据的长度
-
- barnum=traderGetCurrentBar(targetList(i).Market,targetList(i).Code); % K线的序号,后面会增加,前面的值对应的日期固定.
- if(barnum<lags)
- continue;
- end
- % 数据长度限制,排除了前lags根k线
-
- %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- % 策略开始部分
- [time,open,high,low,close,volume,turnover,openinterest] = traderGetKData(targetList(i).Market,targetList(i).Code,'min',1, 0-lags, 0,false,'FWard');
-
- if length(close)<n
- continue;
- end
- %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- % MACD
- [ema12]=traderEMA(12,targetList(i).Market,targetList(i).Code,'min',1, 0-lags, 0,false,'FWard');
- [ema26]=traderEMA(26,targetList(i).Market,targetList(i).Code,'min',1, 0-lags, 0,false,'FWard');
- dif=ema12-ema26;
- dea=zeros(length(dif),1);
- for j=2:length(dif)
- dea(j,1)=8/10*dea(j-1,1)+2/10*dif(j,1);
- end
- macd=(dif-dea)*2;
- a=macd(end)<0 && macd(end-2)>macd(end-1) && macd(end)>macd(end-1); % 买入条件:macd绿柱变短.
- %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- % 5日均线上扬
- ma5=mean(close(end-4:end));
- ma5_1=mean(close(end-5:end-1));
- ma5_2=mean(close(end-6:end-2));
- b=ma5_1>ma5_2 && ma5>ma5_1;
- %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- [time0,open0,high0,low0,close0,volume0,turnover0,openinterest0] = traderGetKData('sse','000001','min',1,0-lags,0,false,'FWard'); % 上证指数
-
- if length(close0)<n
- continue;
- end
- sz_ma60=mean(close0(end-59:end));
- c=close0(end)>sz_ma60; % 上证指数要大于60日均线.
- %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- EntryLong1=a && b && c;
- % ===============================================================================================================
- ExitLong1=low(end)<s(i).stopprice; % 止损线设为进场bar的最低点.
-
- if marketposition > 0 && macd(end)>s(i).openmacd
- s(i).openmacd=macd(end);
- end
- ExitLong2=macd(end)<s(i).openmacd; % macd下降时出场.
- % ===============================================================================================================
- shareNum=floor(100000000/close(end)/100)*100;
- % && time(end)>=datenum('1-Jan-2016')
- if marketposition ==0 && EntryLong1;% 做多情况1
- orderID1=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum,0,'market','buy1'); % 开多单
- s(i).openmacd=macd(end);
- s(i).stopprice=low(end);
- s(i).time=time(end);
- end
-
- if marketposition > 0 && ExitLong1 && time(end)~=s(i).time; % 平仓情况1
- traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0,0,'market','sell1');
- end
-
- if marketposition > 0 && ExitLong2 && time(end)~=s(i).time; % 平仓情况2
- traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0,0,'market','sell1');
- end
- end
更多免费策略源码下载请登录DigQuant社区-策略资源下载~


雷达卡


京公网安备 11010802022788号







