Loading ...

移动平滑

Author: 量价时空, Date: 2020-07-16 10:23:11
Tags: C++ MA


void main() {
    Sleep(10000);
    Log(exchange.GetAccount());
    auto id=0;
    while (1) {
        if (exchange.IO("status") == 1) {
            exchange.SetContractType(Symbol);

            auto r = exchange.GetRecords(zhouqi);
            auto ma = TA.MA(r, xiao);
            auto a = ma[ma.size() - 1];
         
            

            
            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 >l || position[0].Profit<-k ){
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Sell - 1000, 1);
                         exchange.SetContractType(Symbol);
                  
                        
                    }
                }
                if (position[0].Type) {
                  if(position[0].Profit >l || position[0].Profit<-k){
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Buy + 1000, 1);
                  
                      
                      
                      
                  }
                
                }



            } else if( !(orders.size() > 0)) {
                auto position1 = exchange.GetPosition();
                auto ticker = exchange.GetTicker();
                if (!(position1.size() > 0)){
                if (ticker.Sell < a) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("sell");
                  exchange.Sell(ticker.Sell - 1000, 1);
                    continue;
                } else if ( ticker.Sell > a ) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("buy");
                   exchange.Buy(ticker.Buy + 1000, 1);
                    continue;
                }
                }
            }
        } else {
            LogStatus(_D(), "未连接CTP !");
            Sleep(1000);
        }
      
    }
}

Related

More