设为首页收藏本站

 找回密码
 注册
查看: 2371|回复: 0
打印 上一主题 下一主题

DUAL TRUST 非日内 附源码 [复制链接]

精华
0
UID
247176
积分
162
帖子
72
主题
68
阅读权限
0
注册时间
2017-2-14
最后登录
2017-5-18
跳转到指定楼层
1#
发表于 2017-3-22 11:58:23 |只看该作者 |倒序浏览
策略原理:
         仍然按照经典的DualThrust定义上轨和下轨,不设止盈止损,日内不平仓。

function Strategy1(default_unit,default_exitway,freq)%

targetList = traderGetTargetList();
%获取目标资产信息
HandleList = traderGetHandleList();
%获取账户句柄
global enterprice;
for k=1:length(targetList);
   
    %--------------------仓位、K线、当前bar的提取-----------------------------%
    %获取当前仓位
    [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(k).Market,targetList(k).Code);
    %策略中每次取数据的长度
    lags=200;
    dlags=10;
    barnum=traderGetCurrentBar(targetList(k).Market,targetList(k).Code);
    %数据长度限制
    if(barnum<lags)
        continue;
    end
    %获取K线数据
    [time,open,high,low,close,volume,~,~] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq, 0-lags, 0,false,'FWard');
    [Dtime,Dopen,Dhigh,Dlow,Dclose,Dvolume,~,~] = traderGetKData(targetList(k).Market,targetList(k).Code,'day',1, 0-dlags, 0,false,'FWard');
    if length(close)<lags || length(Dclose)<dlags
        continue;
    end;   
    %-------------------------交易逻辑-------------------------------%
    %----------入场信号--------------------%
    N=3;
    k1=0.5;
    k2=0.5;
    stoplossratio=0.5;
    unit=1;
    HH=max(Dhigh(end-N:end-1));
    HC=max(Dclose(end-N:end-1));
    LC=min(Dclose(end-N:end-1));
    LL=min(Dlow(end-N:end-1));
    range=max(HH-LC,HC-LL);
    upline=Dopen(end)+k1*range;
    dnline=Dopen(end)-k2*range;
    buycon=close(end)>upline;
    sellshortcon=close(end)<dnline;
    sellcon=0;
    buytocovercon=0;
    if enterprice~=0
        sellcon=close(end)<dnline || close(end)<enterprice*(1-stoplossratio);
        buytocovercon=close(end)>upline || close(end)>enterprice*(1+stoplossratio);
    end;
    if buytocovercon && marketposition<0
        orderID1=traderBuyToCover(HandleList(1),targetList(k).Market,targetList(k).Code,'all',0,'market','buy');
        if orderID1==0
            continue;
        end;
    end;
    if sellcon && marketposition>0
        orderID1=traderSell(HandleList(1),targetList(k).Market,targetList(k).Code,'all',0,'market','sell');
        if orderID1==0
            continue;
        end;
    end;
    if buycon && marketposition<=0
        orderID1=traderBuy(HandleList(1),targetList(k).Market,targetList(k).Code,unit,0,'market','buy');
        if orderID1==0
            continue;
        end;
        enterprice=close(end);
    end;
    if sellshortcon && marketposition>=0
        orderID1=traderSellShort(HandleList(1),targetList(k).Market,targetList(k).Code,unit,0,'market','sellshort');
        if orderID1==0
            continue;
        end;
        enterprice=close(end);
    end;
end
end

更多免费策略源码下载请登录DigQuant社区-策略资源下载~http://www.digquant.com.cn/stra.php

DUAL TRUST 非日内策略源码下载:http://www.digquant.com.cn/stra.php?mod=model&pid=138
您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-2 08:47

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部