Loading ...

高频1

Author: 量价时空, Date: 2020-07-13 22:35:25
Tags: C++ High-frequency


/*backtest
start: 2020-07-01 09:00:00
end: 2020-07-13 15:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
mode: 1
*/


void main() {
    Sleep(10000);
    Log(exchange.GetAccount());
    while (1) {
        if (exchange.IO("status") == 1) {
            exchange.SetContractType(Symbol);
            auto records = exchange.GetRecords(60*5);
           auto a = records[records.size()-1].Volume - records[records.size()-2].Volume; 
           auto b = records[records.size()-2].Open - records[records.size()-2].Close;
            
           /* auto ma = TA.MA(r, 20);
            auto a = ma[ma.size() - 1];
            auto b = ma[ma.size() - 3];
            auto r1 = exchange.GetRecords(70);
            auto ma1 = TA.MA(r1, 120);
            auto c = ma1[ma1.size() - 1];
            auto d = ma1[ma1.size() - 3];*/
            auto ticker = exchange.GetTicker();
            auto position = exchange.GetPosition();
            auto orders = exchange.GetOrders();
            if (position.size() > 0 && !(orders.size() > 0)) {
                if (!position[0].Type ) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("closebuy_today");
                    exchange.Sell(position[0].Price + 200, 1);
                }
                if (position[0].Type) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("closesell_today");
                   exchange.Buy(position[0].Price - 200, 1);
                }
            } else if (!(orders.size() > 0)) {
                auto position1 = exchange.GetPosition();
               
                    if (a < 0 && b < 0) {
                       /* exchange.SetContractType(Symbol);
                        exchange.SetDirection("sell");
                       exchange.Sell(ticker.Sell - 1000, 1);*/
                       
                        continue;
                    } else if ( a > 0 && b > 0) {
                        
                      exchange.SetContractType(Symbol);
                        exchange.SetDirection("buy");
                      exchange.Buy(ticker.Buy + 1000, 1);
                       
                        continue;
                    }
            
            } else if (orders.size() > 0 && position[0].Profit < -160) {
                auto orders = exchange.GetOrders();
                 exchange.CancelOrder(orders[0].Id);  
                  Sleep(100);
                auto position = exchange.GetPosition();
                if (position[0].Type == 0) {    
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("closebuy_today");
                    exchange.Sell(ticker.Buy - 1000, 1);
                } else if (position[0].Type == 1) {                 
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("closesell_today");
                    exchange.Buy(orders[0].Price + 1000, 1);
                }
            }
        } else {
            LogStatus(_D(), "未连接CTP !");
            Sleep(1000);
        }

    }
}

Related

More

ananinami What is the settings for FIL_USDT? The numbers 1000, 200, -160 in the code does not work for this coin. Please help

m0606 This strategy is designed for commodity future only. If you want to run it with your cryptocurrency, you need to rewrite the code.