资源加载中... loading...

均线趋势法

Author: 量价时空, Date: 2020-07-08 16:14:49
Tags:


/*backtest
start: 2020-06-18 09:00:00
end: 2020-07-07 15:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES","balance":200000};
mode: 1
args: [["Symbol","ni888"]]
*/

void main() {
    Sleep(10000);
    Log(exchange.GetAccount());
    while (1) {
        if (exchange.IO("status") == 1) {
            exchange.SetContractType(Symbol);
            auto ticker = exchange.GetTicker();
            auto position = exchange.GetPosition();
            if (position.size() > 0) {
                if (!position[0].Type) {
                    if (position[0].Profit > 1800 || position[0].Profit < -90) {

                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Buy, 1);
                    }
                }
                if (position[0].Type) {
                    if (position[0].Profit > 1800 || position[0].Profit < -90) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Sell, 1);
                    }
                }
            } else {
                exchange.SetContractType(Symbol);
                auto r = exchange.GetRecords(60);
                auto ma = TA.MA(r, 20);
                auto ma1 = TA.MA(r, 120);
                if (ma[ma.size() - 1] <= ma1[ma1.size() - 1] && ma[ma.size() - 2] > ma1[ma1.size() - 2]) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("sell");
                    exchange.Sell(ticker.Sell, 1);
                } else if (ma[ma.size() - 1] >= ma1[ma1.size() - 1] && ma[ma.size() - 2] < ma1[ma1.size() - 2]) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("buy");
                    exchange.Buy(ticker.Buy, 1);
                }


            }











        } else {
            LogStatus(_D(), "未连接CTP !");
            Sleep(1000);
        }
    }


}

更多内容