Loading ...

整数突破

Author: 量价时空, Date: 2020-07-08 21:36:41
Tags: Breakthrough




void main() {
    
    Sleep(10000);
    Log(exchange.GetAccount());
    auto a=xia;
    auto b=shang;
   
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 == 0 && (ticker.Last < b-20 || ticker.Last > b+960)) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Last - 1000, 1);
                        Sleep(800);
                        continue;
                    }
        if (position[0].Type == 1 && (ticker.Last < a-960 || ticker.Last > a+20)) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Last + 1000, 1);
                        Sleep(800);
                        continue;
                    }
        if (position[0].Type == 2 && (ticker.Last < b-20 || ticker.Last > b+960) ) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy");
                        exchange.Sell(ticker.Last - 1000, 1);
                        Sleep(800);
                        continue;
                    }   
            
            
        if (position[0].Type == 3 && (ticker.Last < a-960 || ticker.Last > a+20)) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell");
                        exchange.Buy(ticker.Last + 1000, 1);
                        Sleep(800);
                        continue;
                    }
              
            
            
            
                
            
        } else if(!(position.size() > 0))  {
            exchange.SetContractType(Symbol);
            auto ticker = exchange.GetTicker();
            auto records = exchange.GetRecords(10); 
            
            b = (((int) records[records.size() - 1].Low) / 1000 + 1) * 1000;  // 得到整数区间值
              
            a = (((int) records[records.size() - 1].High) / 1000) * 1000;
            
            if(ticker.Last > b){
             exchange.SetContractType(Symbol);
            exchange.SetDirection("buy");
            exchange.Buy(ticker.Buy + 1000, 1);
            }
            
             if( ticker.Last < a ){
              exchange.SetContractType(Symbol);
            exchange.SetDirection("sell");
            exchange.Sell(ticker.Sell - 1000, 1); 
            }

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


Related

More