寻找上涨趋势中的杯子形态,寻找此处作为入场点
同时满足close > average (close,N)均线过滤的有条件下,做多
寻找下跌趋势中的杯子形态,寻找此处作为入场点
同时满足close < average (close,N)均线过滤的有条件下,做空
出场使用并滚动式止盈止损。
在沪深300股指期货与螺纹钢期货里面按照1:50的标准进行投资。测试时间段:2011年1月1日到2017年1月1日。
回测曲线(由Auto-trader提供回测报告)
策略源码:
- function CupC(freq,N,stop_rate)
- % 交易逻辑
- % Cups and Caps―Overnight
- targetList = traderGetTargetList();
- HandleList = traderGetHandleList();
- global entryP;%跟踪价格
- global key0;%用来记录进场价格的开关
- if isempty(entryP)||isempty(key0)
- entryP=zeros(length(targetList),1);
- key0=zeros(length(targetList),1);
- end
- sharenum=50*[1,50];
- for i=1:length(targetList)
- lags=N+3;%策略中每次取数据的长度
- [position,Frozen,AvgPrice] = traderGetAccountPosition(HandleList(1),targetList(i).Market,targetList(i).Code);
- %开仓
- [time,open,high,low,close,volume,turnover,openinterest] = traderGetKData(targetList(i).Market,targetList(i).Code,'min',freq, 0-lags,0,false,'FWard');
- if length(close)<lags
- continue;
- end
- con1=high(end)<high(end-1) && high(end-1)>max(high(end-4:end-2)) && close(end)<mean(close(end-N+1:end));
- con2=low(end)>low(end-1) && low(end-1)<min(low(end-4:end-2)) && close(end)>mean(close(end-N+1:end));
- if key0(i)==1
- entryP(i)=AvgPrice;
- key0(i)=0;
- end
-
- if position>0
-
- if close(end)> entryP(i)*(1+3*stop_rate) || close(end)<entryP(i)*(1-stop_rate)
- traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0 ,0,'market','stopLong');
- end
- if close(end)> entryP(i)*(1+stop_rate)
- entryP(i)=close(end);
- end
- elseif position<0
- if close(end)<entryP(i)*(1-3*stop_rate) || close(end)>entryP(i)*(1+stop_rate)
- traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0 ,0,'market','stopLong');
- end
- if close(end)< entryP(i)*(1-stop_rate)
- entryP(i)=close(end);
- end
- else
- if con1
- order=traderSellShort(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum(i),0,'market','short');
- if order~=0
- key0(i)=1;
- end
- end
- if con2
- order= traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum(i),0,'market','long1');
- if order~=0
- key0(i)=1;
- end
- end
- end
- end
- end
更多免费策略源码下载请登录DigQuant社区-策略资源下载~