策略名称:横盘突破策略策略说明:
日内交易策略,收盘平仓;
横盘突破在过去30根K线的高低点围绕中轴上下0.5%的范围内波动时;
上轨=过去30根K线的最高价;
下轨=过去30根K线的最低价;
当价格突破上轨,买入开仓;
当价格跌穿下轨,卖出开仓。
多头出场条件:止损0.5%,盈利大于0.5%,启动跟踪止盈,回调20%多头出场
空头出场条件:止损0.5%,盈利大于0.5%,启动跟踪止盈,回调20%空头出场
回测曲线:
QQ图片0217114330.png (86.04 KB, 下载次数: 4)
-2-17 11:48 上传
策略代码:
functioncalmbreak(stoploss,stopprofit,trailinggap,Freq,shareNum)
%横盘突破
%日内交易策略,收盘平仓;
%横盘突破在过去30根K线的高低点围绕中轴上下0.5%的范围内波动时;
%上轨=过去30根K线的最高价;
%下轨=过去30根K线的最低价;
%当价格突破上轨,买入开仓;
%当价格跌穿下轨,卖出开仓。
%stoploss止损阈值
%stopprofit止盈阈值
%trailinggap跟踪止盈参数
%Freq数据频率
%shareNum买卖手数
%---------------------策略初始化与是否日内平仓---------------%
traderDailyCloseTime(145000);%每天15:10分平仓
targetList=traderGetTargetList();
HandleList=traderGetHandleList();
marketposition=traderGetAccountPosition(HandleList(1),targetList(1).Market,targetList(1).Code);
lags=35;
[barnum,bartime]=traderGetCurrentBar(targetList(1).Market,targetList(1).Code);
if(barnum<=lags)
return;
end
%---------------------策略提取数据---------------%
[time,open,high,low,close,volume,turnover,openinterest]=traderGetKData(targetList(1).Market,targetList(1).Code,'min',Freq,0-lags,0,false,'FWard');
iflength(close)<31
return;
end
%---------------------策略计算与基本逻辑---------------%
highTar=max(high(end-30:end-1));%过去30根K线的最高价
lowTar=min(low(end-30:end-1));%过去30根K线的最低价
ifmarketposition==0&&close(end)>highTar
orderID1=traderBuy(HandleList(1),targetList(1).Market,targetList(1).Code,shareNum,0,'market','buy');
traderStopLossByOrder(HandleList(1),orderID1,stoploss,'Percent','market','stoplossS');
traderStopTrailingByOrder(HandleList(1),orderID1,stopprofit,'Percent',trailinggap,'Percent','market','trailingS');
end
ifmarketposition==0&&close(end)
orderID2=traderSellShort(HandleList(1),targetList(1).Market,targetList(1).Code,shareNum,0,'market','sell');
traderStopLossByOrder(HandleList(1),orderID2,stoploss,'Percent','market','stoplossB');
traderStopTrailingByOrder(HandleList(1),orderID2,stopprofit,'Percent',trailinggap,'Percent','market','trailingB');
end
end
更多免费策略源码下载,请登录 atrader社区-策略服务进行下载,ww
横盘突破策略源码下载:w /stra.php?mod=model&pid=74