Beispiel #1
0
        private void sar(object sender, EventArgs e)
        {
            GetHSIData        getHSIData   = new GetHSIData();
            List <HSIFutures> findByTime   = getHSIData.GetHSIDataList();
            List <HSIFutures> positiveData = new List <HSIFutures>(); //排序后的数组

            for (int i = findByTime.Count - 1; i >= 0; i--)           //此方法为排序方法
            {
                positiveData.Add(findByTime[i]);
            }

            //for (int i = 0; i < positiveData.Count; i++)
            //{
            //    string data = "时间" + positiveData[i].GetDate();
            //    Spcommon.APIDLL.output(data);
            //}



            SAR           sar     = new SAR();
            float         step    = float.Parse(textBox3.Text);
            float         maxStep = float.Parse(textBox4.Text);
            List <Double> sarList = sar.getSARLineDatas(positiveData, step, maxStep);
            List <int>    buy     = new List <int>();
            List <int>    sell    = new List <int>();
            int           number  = 0;

            for (int i = 1; i < positiveData.Count(); i++)
            {
                if (positiveData[i - 1].GetClose() <= sarList[i - 1])
                {
                    if (positiveData[i].GetClose() > sarList[i] && number % 2 == 0)
                    {
                        buy.Add(i);
                        number++;
                    }
                }

                if (positiveData[i - 1].GetClose() >= sarList[i - 1])
                {
                    if (positiveData[i].GetClose() < sarList[i] && number % 2 != 0)
                    {
                        sell.Add(i);
                        number++;
                    }
                }
            }
            String data = sarList.Count() + "######################" + positiveData.Count() + "##################################";

            Spcommon.APIDLL.output(data);

            for (int i = 0; i < sell.Count(); i++)
            {
                String data1 = "买的信号" + positiveData[buy[i]].GetDate() + "--" + "卖的信号" + positiveData[sell[i]].GetDate();
                Spcommon.APIDLL.output(data1);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 不停查询数据库方法
        /// </summary>
        private static void Run()
        {
            try
            {
                string         connStr      = "Driver= {MySQL ODBC 3.51 Driver};Server=127.0.0.1;Database=realtimedata;User=root; Password=root; Option=3;";
                OdbcConnection myConnection = new OdbcConnection(connStr);  //创建数据库连接
                while (true)
                {
                    List <HSIFutures> dataList  = new List <HSIFutures>();            //历史数据数组
                    SAR               sar       = new SAR();
                    List <double>     sarList   = new List <double>();                //sar值数组
                    List <HSIFutures> buy       = new List <HSIFutures>();            //买信号数组
                    List <HSIFutures> sell      = new List <HSIFutures>();            //卖信号数组
                    string            sql       = "SELECT * FROM hsiindh_1min t  ORDER BY id DESC LIMIT 100";
                    OdbcCommand       myCommand = new OdbcCommand(sql, myConnection); //创建sql和连接实例化的对象
                    myConnection.Open();
                    //           Console.WriteLine(myCommand.ExecuteNonQuery().ToString());
                    OdbcDataReader myReader = myCommand.ExecuteReader();

                    while (myReader.Read())
                    {
                        HSIFutures hSIFutures = new HSIFutures();
                        hSIFutures.SetSymbol(myReader[1].ToString());
                        hSIFutures.SetDate((DateTime)myReader[2]);
                        hSIFutures.SetOpen(double.Parse(myReader[3].ToString()));
                        hSIFutures.SetHigh(double.Parse(myReader[4].ToString()));
                        hSIFutures.SetLow(double.Parse(myReader[5].ToString()));
                        hSIFutures.SetClose(double.Parse(myReader[6].ToString()));
                        //hSIFutures.SetCreatedate(long.Parse(myReader[10].ToString()));
                        dataList.Add(hSIFutures);
                    }
                    myConnection.Close();
                    List <HSIFutures> positiveData = new List <HSIFutures>(); //排序后的数组
                    for (int i = dataList.Count - 1; i >= 0; i--)             //此方法为排序方法
                    {
                        positiveData.Add(dataList[i]);
                    }

                    sarList = sar.getSARLineDatas(positiveData, float.Parse("0.02"), float.Parse("0.2"));    //获取SAR的值


                    if (positiveData[98].GetClose() <= sarList[98])
                    {
                        if (positiveData[99].GetClose() > sarList[99] && number % 2 == 0)
                        {
                            HSIFutures hSIFutures = new HSIFutures();
                            hSIFutures.SetSymbol(positiveData[99].GetSymbol());
                            hSIFutures.SetDate(positiveData[99].GetDate());
                            hSIFutures.SetOpen(positiveData[99].GetOpen());
                            hSIFutures.SetHigh(positiveData[99].GetHigh());
                            hSIFutures.SetLow(positiveData[99].GetLow());
                            hSIFutures.SetClose(positiveData[99].GetClose());
                            buy.Add(hSIFutures);
                            number++;
                            DialogResult result = MessageBox.Show("可以买入了!!!买入信号时间为" + buy[99].GetDate(), "买卖信号提示", MessageBoxButtons.YesNoCancel,
                                                                  MessageBoxIcon.Information);
                            String data3 = "######################" + "买入时间" + buy[99].GetDate();
                            Spcommon.APIDLL.output(data3);
                        }
                    }

                    if (positiveData[98].GetClose() >= sarList[98])
                    {
                        if (positiveData[99].GetClose() < sarList[99] && number % 2 != 0)
                        {
                            HSIFutures hSIFutures = new HSIFutures();
                            hSIFutures.SetSymbol(positiveData[99].GetSymbol());
                            hSIFutures.SetDate(positiveData[99].GetDate());
                            hSIFutures.SetOpen(positiveData[99].GetOpen());
                            hSIFutures.SetHigh(positiveData[99].GetHigh());
                            hSIFutures.SetLow(positiveData[99].GetLow());
                            hSIFutures.SetClose(positiveData[99].GetClose());
                            sell.Add(hSIFutures);
                            number++;
                            DialogResult result = MessageBox.Show("可以卖出了!!!卖出信号时间为" + sell[99].GetDate(), "买卖信号提示", MessageBoxButtons.YesNoCancel,
                                                                  MessageBoxIcon.Information);
                            String data2 = "######################" + "卖出时间" + sell[99].GetDate();
                            Spcommon.APIDLL.output(data2);
                        }
                    }


                    String data1 = "上一秒的SAR值" + sarList[98] + "现在的SAR值" + sarList[99] + "######################" + "上一秒的底价" + positiveData[98].GetClose() + "现在的底价" + positiveData[99].GetClose();
                    Spcommon.APIDLL.output(data1);

                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("数据库连接失败" + "或者线程出现问题 " + ex.Message);
            }
        }
Beispiel #3
0
        private List <Student> GetStudentList()
        {
            //买卖信号版本内容
            int number             = 0;
            List <HSIFutures> buy  = new List <HSIFutures>();   //买信号数组
            List <HSIFutures> sell = new List <HSIFutures>();   //卖信号数组
            SAR           sar      = new SAR();
            List <double> sarList  = new List <double>();       //sar值数组


            //历史数据版本内容
            List <HSIFutures> dataList     = new List <HSIFutures>();            //历史数据数组
            string            connStr      = "Driver= {MySQL ODBC 3.51 Driver};Server=127.0.0.1;Database=realtimedata;User=root; Password=root; Option=3;";
            OdbcConnection    myConnection = new OdbcConnection(connStr);        //创建数据库连接
            string            sql          = "SELECT * FROM hsiindh_1min t  ORDER BY id DESC LIMIT 200";
            OdbcCommand       myCommand    = new OdbcCommand(sql, myConnection); //创建sql和连接实例化的对象

            myConnection.Open();
            OdbcDataReader myReader = myCommand.ExecuteReader();

            while (myReader.Read())
            {
                HSIFutures hSIFutures = new HSIFutures();
                hSIFutures.SetSymbol(myReader[1].ToString());
                hSIFutures.SetDate((DateTime)myReader[2]);
                hSIFutures.SetOpen(double.Parse(myReader[3].ToString()));
                hSIFutures.SetHigh(double.Parse(myReader[4].ToString()));
                hSIFutures.SetLow(double.Parse(myReader[5].ToString()));
                hSIFutures.SetClose(double.Parse(myReader[6].ToString()));
                //hSIFutures.SetCreatedate(long.Parse(myReader[10].ToString()));
                dataList.Add(hSIFutures);
            }
            myConnection.Close();



            //买卖信号版本内容
            //    List<HSIFutures> positiveData = new List<HSIFutures>(); //排序后的数组
            //    for (int i = dataList.Count - 1; i >= 0; i--)  //此方法为排序方法
            //    {
            //        positiveData.Add(dataList[i]);
            //    }
            //    sarList = sar.getSARLineDatas(positiveData, float.Parse("0.02"), float.Parse("0.2"));    //获取SAR的值

            //for (int i = 1; i < positiveData.Count(); i++)
            //{
            //        if (positiveData[i - 1].GetClose() <= sarList[i - 1])
            //        {
            //            if (positiveData[i].GetClose() > sarList[i] && number % 2 == 0)
            //            {
            //                HSIFutures hSIFutures = new HSIFutures();
            //            hSIFutures.SetSymbol(positiveData[i].GetSymbol());
            //            hSIFutures.SetDate(positiveData[i].GetDate());
            //            hSIFutures.SetOpen(positiveData[i].GetOpen());
            //            hSIFutures.SetHigh(positiveData[i].GetHigh());
            //            hSIFutures.SetLow(positiveData[i].GetLow());
            //            hSIFutures.SetClose(positiveData[i].GetClose());
            //            buy.Add(hSIFutures);
            //            number++;
            //        }
            //    }
            //        if (positiveData[i - 1].GetClose() >= sarList[i - 1])
            //        {
            //            if (positiveData[i].GetClose() < sarList[i] && number % 2 != 0)
            //            {
            //               HSIFutures hSIFutures = new HSIFutures();
            //            hSIFutures.SetSymbol(positiveData[i].GetSymbol());
            //            hSIFutures.SetDate(positiveData[i].GetDate());
            //            hSIFutures.SetOpen(positiveData[i].GetOpen());
            //            hSIFutures.SetHigh(positiveData[i].GetHigh());
            //            hSIFutures.SetLow(positiveData[i].GetLow());
            //            hSIFutures.SetClose(positiveData[i].GetClose());
            //            sell.Add(hSIFutures);
            //            number++;
            //        }
            //    }
            // }

            List <Student> studentList = new List <Student>();

            //历史数据版本内容
            for (int i = 0; i < dataList.Count; i++)
            {
                studentList.Add(new Student
                {
                    Date  = dataList[i].GetDate(),
                    Open  = dataList[i].GetOpen(),
                    High  = dataList[i].GetHigh(),
                    Low   = dataList[i].GetLow(),
                    Close = dataList[i].GetClose()
                });
            }


            //买卖信号版本内容
            //for (int i = 0; i < sell.Count; i++)
            //{
            //    studentList.Add(new Student
            //    {
            //        Date = buy[i].GetDate(),
            //        Open = buy[i].GetOpen(),
            //        High = buy[i].GetHigh(),
            //        Low = buy[i].GetLow(),
            //        Close = buy[i].GetClose()
            //    });

            //    studentList.Add(new Student
            //    {
            //        Date = sell[i].GetDate(),
            //        Open = sell[i].GetOpen(),
            //        High = sell[i].GetHigh(),
            //        Low = sell[i].GetLow(),
            //        Close = sell[i].GetClose()
            //    });

            //}
            return(studentList);
        }