该楼层疑似违规已被系统折叠隐藏此楼查看此楼
策略名称:横盘突破策略
策略思路:
日内交易策略,收盘平仓;
横盘突破在过去30根K线的高低点围绕中轴上下0.5%的范围内波动时;
上轨=过去30根K线的最高价;
下轨=过去30根K线的最低价;
当价格突破上轨,买入开仓;
当价格跌穿下轨,卖出开仓。
多头出场条件:止损0.5%,盈利大于0.5%,启动跟踪止盈,回调20%多头出场
空头出场条件:止损0.5%,盈利大于0.5%,启动跟踪止盈,回调20%空头出场
策略代码:
function calmbreak(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');
if length(close)<31
return;
end
%---------------------策略计算与基本逻辑---------------%
highTar = max(high(end-30:end-1));% 过去30根K线的最高价
lowTar = min(low(end-30:end-1));% 过去30根K线的最低价
if marketposition == 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
if marketposition == 0 && close(end) < lowTar
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社区-策略服务下载,/stra.php
如果觉得《期货量化交易matlab 【策略分享】Matlab量化交易策略源码分享》对你有帮助,请点赞、收藏,并留下你的观点哦!