sdfg123 发表于 2017-2-22 10:25:31

FourLine策略(附源码)

策略名称:FourLine

策略思路:

多头进场条件:两组均线均成多头排列时且当前价高于上根BAR最高价入场
平掉多头条件:两组均线分别空头排列且低于上根BAR最低价出场 或者 小周期多头均线组合成空头排列出场

回测曲线:


策略代码:

function  FourLine(lefast,leslow,lxfast,lxslow,sefast,seslow,sxfast,sxslow,shareNum,Freq)%上面十个为输入参数  
%  ------------  FourLine  Strategy-------------------
%  Freq  为输入时间频率
%  shareNum  为操作的手数
%  lefast(5);  为多头入场短均线周期参数
%  leslow(20);为多头入场长均线周期参数
%  lxfast(3);  为多头出场短均线周期参数
%  lxslow(10);为多头出场长均线周期参数
%  sefast(5);  为空头入场短均线周期参数
%  seslow(20);为空头入场长均线周期参数
%  sxfast(3);  为空头出场短均线周期参数
%  sxslow(10);为空头出场长均线周期参数
%---------------------策略初始化与是否日内平仓---------------%
traderDailyCloseTime(145000);          %  每天14:50分平仓        如果没有日内平仓,去掉这句话就可以了。
targetList  =  traderGetTargetList();  %获取交易标的句柄
HandleList  =  traderGetHandleList();  %获取账户句柄
=traderGetAccountPosition(HandleList(1),targetList(1).Market,targetList(1).Code);  %获取当前仓位状况
lags=300;
barnum=traderGetCurrentBar(targetList(1).Market,targetList(1).Code);  %当前Bar的编号
if(barnum<=lags)  %当编号不超过所取的数据长度时,返回
        return;
end
%---------------------策略提取数据---------------%
  =  traderGetKData(targetList(1).Market,targetList(1).Code,'min',Freq,  0-lags,  0,false,'FWard');  %提取数据,从当前开始往前取lags个数据
%---------------------策略计算与基本逻辑---------------%
MALEFast=mean(close(end-lefast+1:end));  %多头入场短均线
MALESlow=mean(close(end-leslow+1:end));  %多头入场长均线
MALXFast=mean(close(end-lxfast+1:end));  %多头出场短均线
MALXSlow=mean(close(end-lxslow+1:end));  %多头出场长均线
MASEFast=mean(close(end-sefast+1:end));  %空头入场短均线
MASESlow=mean(close(end-seslow+1:end));  %空头入场长均线
MASXFast=mean(close(end-sxfast+1:end));  %空头出场短均线
MASXSlow=mean(close(end-sxslow+1:end));  %空头出场长均线
con1=MALEFast(end)>  MALESlow(end)    &&    MALXFast(end)>  MALXSlow(end)      &&    high(end)>=high(end-1);    %两组均线均成多头排列时且当前价高于上根BAR最高价入场
con2=MASEFast(end)<  MASESlow(end)  &&  MASXFast(end)<  MASXSlow(end)    &&    low(end)<=low(end-1);    %两组均线分别空头排列且低于上根BAR最低价出场
con3=MALXFast(end)<  MALXSlow(end);    %小周期多头均线组合成空头排列出场
%----------------------策略主体-------------------------------%
if  marketposition<=0
        if  con1
                traderBuy(HandleList(1),targetList(1).Market,targetList(1).Code,shareNum,0,'market','buy1');%开多单   
        end
end
if  marketposition>0
        if  con2  ||  con3
        traderSell(HandleList(1),targetList(1).Market,targetList(1).Code,shareNum,0,'market','sell1');%平多单
        end
end
end

更多免费策略源码下载请登录atrader社区-策略服务下载,http://www.atrader.com.cn/stra.php

FourLine策略源码下载,http://www.atrader.com.cn/stra.php?mod=model&pid=55
                       
页: [1]
查看完整版本: FourLine策略(附源码)