深蓝 1 号交易策略源码

/*backtest

start: 2017-01-01 09:00:00

end: 2017-11-27 15:00:00

period: 1h

*/
var into = 0; // 入场价格
var out = 0; // 出场价格
var myPosition = 0; // 虚拟持仓
var myProfit = 0; // 虚拟利润
var uu = 30; // 超卖
var nn = 70; // 超买
// 语法固定格式,调用main主函数
function main() {
    // 调用商品期货交易类库中的CTA框架
    $.CTA(contractType,
        function (st) {
            var mp = st.position.amount;
            //获取K线数组
            var j = st.records;
            //指标运算参考的最大K线数量
            if (j.length < Math.max(fastLength, slowLength, rsiLength)) {
                return
            }
            var h0 = j[j.length - 1].High;
            var h1 = j[j.length - 2].High;
            var l0 = j[j.length - 1].Low;
            var l1 = j[j.length - 2].Low;
            var o0 = j[j.length - 1].Open;
            var c0 = j[j.length - 1].Close;
            //短期指数平均线数组和长期指数平均线数组
            var fastMas = talib.MA(j, fastLength);
            var slowMas = talib.MA(j, slowLength);
            var fastMa1 = fastMas[fastMas.length - 2];
            var slowMa1 = slowMas[slowMas.length - 2];
            //获取RSI数组
            var rsis = talib.RSI(j, rsiLength);
            var rsi1 = rsis[rsis.length - 2];
            //获取唐奇安通道
            var highest = TA.Highest(j, Donchian, "High");
            var lowest = TA.Lowest(j, Donchian, "Low");
            // 平多
            if (l0 <= lowest) {
                if (myPosition > 0) {
                    out = Math.min(o0, lowest);
                    myProfit = into - out;
                    myPosition = 0;
                }
                if (mp > 0) {
                    return -1;
                }
            }
            // 平空
            if (h0 >= highest) {
                if (myPosition < 0) {
                    out = Math.max(o0, highest);
                    myProfit = into - out;
                    myPosition = 0;
                }
                if (mp < 0) {
                    return 1;
                }
            }
            // 开多
            if (fastMa1 > slowMa1 && rsi1 < nn && h0 >= h1) {
                if (myPosition === 0) {
                    into = Math.max(o0, h1);
                    myPosition = 1;
                }
                if (myProfit < 0 && mp < 1) {
                    return 1;
                }
            }
            // 开空
            if (fastMa1 < slowMa1 && rsi1 > uu && l0 <= l1) {
                if (myPosition === 0) {
                    into = Math.min(o0, l1);
                    myPosition = -1;
                }
                if (myProfit < 0 && mp > -1) {
                    return -1;
                }
            }
        });
}

 

免责声明:信息仅供参考,不构成投资及交易建议。投资者据此操作,风险自担。
如果觉得文章对你有用,请随意赞赏收藏
1317246517 only 霭鬕衙壨 春暖花开 4人赞赏收藏
相关推荐
相关下载
登录后评论
Copyright © 2019 宽客在线