Loading ...

是心动啊

Author: 量价时空, Date: 2020-08-01 20:24:57
Tags:


void main() {
    
    Sleep(10000);
    Log(exchange.GetAccount());
    auto di=0;
    auto max=0;
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].Profit > max){
            max=position[0].Profit;
            }
            
            
            
        if (position[0].Type == 0 && (ticker.Last < di || position[0].Profit > li) && di != 0) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Last - 1000, 1);
                         max=0;
               di=0;
                        Sleep(800);
                        continue;
                    }
        if (position[0].Type == 1 && (ticker.Last > di || position[0].Profit > li)&& di != 0) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Last + 1000, 1);
                         max=0;
               di=0;
                        Sleep(800);
                        continue;
                    }
        if (position[0].Type == 2 && (ticker.Last < di || position[0].Profit > li) && di != 0) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy");
                        exchange.Sell(ticker.Last - 1000, 1);
                        Sleep(800);
                              max=0;
               di=0;
                        continue;
                    }   
            
            
        if (position[0].Type == 3 && (ticker.Last > di || position[0].Profit > li)&& di != 0) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell");
                        exchange.Buy(ticker.Last + 1000, 1);
                              max=0;
            di=0;
                        Sleep(800);
                        continue;
                    }
            
            
              
       /* if(max >= 400 && position[0].Profit <= max*0.55 ){
              if (position[0].Type == 0) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Last - 1000, 1);
                         max=0;
                        Sleep(800);
                        continue;
                    }
               if (position[0].Type == 1) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Last + 1000, 1);
                         max=0;
                        Sleep(800);
                        continue;
                    }
        if (position[0].Type == 2) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy");
                        exchange.Sell(ticker.Last - 1000, 1);
                        Sleep(800);
                              max=0;
                        continue;
                    }   
            
            
        if (position[0].Type == 3) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell");
                        exchange.Buy(ticker.Last + 1000, 1);
                              max=0;
                        Sleep(800);
                        continue;
                    }

            }
            
             if(max >= 600 && position[0].Profit <= max*0.7 ){
              if (position[0].Type == 0) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Last - 1000, 1);
                         max=0;
                        Sleep(800);
                        continue;
                    }
               if (position[0].Type == 1) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Last + 1000, 1);
                         max=0;
                        Sleep(800);
                        continue;
                    }
        if (position[0].Type == 2) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy");
                        exchange.Sell(ticker.Last - 1000, 1);
                        Sleep(800);
                              max=0;
                        continue;
                    }   
            
            
        if (position[0].Type == 3) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell");
                        exchange.Buy(ticker.Last + 1000, 1);
                              max=0;
                        Sleep(800);
                        continue;
                    }
            
            
            
            
            
            
            }*/
            
           /*  if(max < 10 && position[0].Profit < -70 ){
              if (position[0].Type == 0) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Last - 1000, 1);
                         max=0;
                        Sleep(800);
                        continue;
                    }
               if (position[0].Type == 1) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Last + 1000, 1);
                         max=0;
                        Sleep(800);
                        continue;
                    }
        if (position[0].Type == 2) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy");
                        exchange.Sell(ticker.Last - 1000, 1);
                        Sleep(800);
                              max=0;
                        continue;
                    }   
            
            
        if (position[0].Type == 3) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell");
                        exchange.Buy(ticker.Last + 1000, 1);
                              max=0;
                        Sleep(800);
                        continue;
                    }
            }*/
            
            /* if(max >= dian && position[0].Profit <= max*w ){
              if (position[0].Type == 0) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Last - 1000, 1);
                         max=0;
                        Sleep(800);
                        continue;
                    }
               if (position[0].Type == 1) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Last + 1000, 1);
                         max=0;
                        Sleep(800);
                        continue;
                    }
        if (position[0].Type == 2) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy");
                        exchange.Sell(ticker.Last - 1000, 1);
                        Sleep(800);
                              max=0;
                        continue;
                    }   
            
            
        if (position[0].Type == 3) {
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell");
                        exchange.Buy(ticker.Last + 1000, 1);
                              max=0;
                        Sleep(800);
                        continue;
                    }
            
            
            
            
            
            
            }*/
            
            
            
                
            
        } else if(!(position.size() > 0))  {
             Sleep(1000);
            exchange.SetContractType(Symbol);
            auto ticker = exchange.GetTicker();
            auto records1 = exchange.GetRecords(h*7); 
            auto r = exchange.GetRecords(h);
            auto macd = TA.MACD(r);
            auto slow1 = macd[0][macd[0].size() - 1];
            auto fast1 = macd[1][macd[1].size() - 1];
            auto slow2 = macd[0][macd[0].size() - 2];
            auto fast2 = macd[1][macd[1].size() - 2];

            if( fast1 > slow1 && fast2 < slow2 ){
             exchange.SetContractType(Symbol);
             exchange.SetDirection("buy");
             exchange.Buy(ticker.Buy + 1000, 1);  
             di=records1[records1.size() - 1].Low;
            }
            
             if( fast1 < slow1 && fast2 > slow2 ){
            exchange.SetContractType(Symbol);
            exchange.SetDirection("sell");
            exchange.Sell(ticker.Sell - 1000, 1);     
            di=records1[records1.size() - 1].High;
            }

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

More