1 Star 0 Fork 27

回回会挥挥灰 / FMZ-strategies

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
均线突破法.md 2.93 KB
一键复制 编辑 原始数据 按行查看 历史
Zero 提交于 2020-12-09 16:43 . update

策略名称

均线突破法

策略作者

量价时空

策略参数

参数 默认值 描述
Symbol ni2010 合约
z 200 赚钱数
k 50 亏钱数
q 2 k线周期

源码 (cpp)

/*backtest
start: 2020-06-18 09:00:00
end: 2020-07-08 15:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES","balance":200000}]
*/

void main() {
    Sleep(10000);
    Log(exchange.GetAccount());
    while (1) {
        if (exchange.IO("status") == 1) {
            exchange.SetContractType(Symbol);
            auto r = exchange.GetRecords(60);
            auto ma = TA.MA(r, 20);
            // Log(ma[ma.size() - 1]);
            auto records = exchange.GetRecords(60 * 3);
            auto ticker = exchange.GetTicker();
            auto position = exchange.GetPosition();
            auto orders = exchange.GetOrders();
            if (position.size() > 0 && !(orders.size() > 0)) {
                if (!position[0].Type) {
                    if (position[0].Profit > z || position[0].Profit < -k) {
                        
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Buy - 100, 1);
                        Sleep(500);
                    }
                }
                if (position[0].Type) {
                    if (position[0].Profit > z || position[0].Profit < -k) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Sell + 100, 1);
                        Sleep(500);
                    }
                }



            } else {
                 auto r = exchange.GetRecords(60*q);
                            auto ma = TA.MA(r, 20);
                           auto a = ma[ma.size() - 1];
                          
                         auto r1 = exchange.GetRecords(60*q);
                          auto ma1 = TA.MA(r1, 120);
                         auto c = ma1[ma1.size() - 1];
                if (a < c && records[records.size() - 1].High > ma[ma.size() - 1] && ticker.Buy < ma[ma.size() - 1]) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("sell");
                    exchange.Sell((ticker.Sell - 1000), 1);
                    Sleep(500);
                }else if (a > c && records[records.size() - 1].Low < ma[ma.size() - 1] && ticker.Sell > ma[ma.size() - 1]) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("buy");
                    exchange.Buy((ticker.Buy + 1000), 1);
                    Sleep(500);
                }
            }
        } else {
            LogStatus(_D(), "未连接CTP !");
            Sleep(1000);
        }
        Sleep(500);
    }
}

策略出处

https://www.fmz.com/strategy/218413

更新时间

2020-07-14 15:48:27

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/maxwellh/FMZ-strategies.git
git@gitee.com:maxwellh/FMZ-strategies.git
maxwellh
FMZ-strategies
FMZ-strategies
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891