Loading ...

顺大逆小

Author: 量价时空, Date: 2020-07-15 20:51:52
Tags: C++


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();
                auto orders = exchange.GetOrders();
                auto records = exchange.GetRecords(xiao);
                auto records1 = exchange.GetRecords(da);
               auto a = records[records.size() - 1].Open- records[records.size() - 1].Close;
               auto b = records1[records1.size() - 1].Open- records1[records1.size() - 1].Close;
               auto records2 = exchange.GetRecords(3); 
                auto c = records2[records2.size() - 1].High - records2[records2.size() - 1].Low;
                if(c<0){
                c=-c;
                }
                
                if ((position.size() > 0) && !(orders.size() > 0)) {
                        if (!position[0].Type) {
                            if (position[0].Profit > y || position[0].Profit < -k) {

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

                    } else if(!(orders.size() > 0)) {
                            if (b>200 && a<-50 && c<20 ) {
                                exchange.SetContractType(Symbol);
                                exchange.SetDirection("buy");
                                exchange.Buy((ticker.Buy + 1000), 1);
                               
                            } else if (b < -200 && a>50 && c<20) {
                                exchange.SetContractType(Symbol);
                                exchange.SetDirection("sell");
                                exchange.Sell((ticker.Sell - 1000), 1);
                            
                            }
                        }





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

                }




            }

Related

More