Exemple #1
0
        public List <HSIFutures> GetHSIDataList()
        {
            List <HSIFutures> dataList = new List <HSIFutures>();

            try
            {
                //int slowLine = 30;
                string connStr = "Driver= {MySQL ODBC 3.51 Driver};Server=127.0.0.1;Database=realtimedata;User=root; Password=root; Option=3;";
                //string sql = "SELECT * FROM (SELECT * FROM hsiindh_1min t ORDER BY id DESC)realtimedata LIMIT 0," + slowLine;
                //string sql = "SELECT * FROM (SELECT * FROM hsiindh_1min t WHERE '" + startTime + "' <= t.DATE AND t.DATE <= '" + endTime + "'ORDER BY id DESC) tt LIMIT 0," + slowLine;
                //string sql = "SELECT * FROM hsiindh_1min t WHERE '" + startTime + "' <= t.DATE AND t.DATE <= '" + endTime + "'";
                string sql = "SELECT * FROM hsiindh_1min t  ORDER BY id DESC LIMIT 200";

                // string sql = "SELECT * FROM (SELECT * FROM (SELECT * FROM hsiindh_1min t ORDER BY id DESC)realtimedata LIMIT 0,990)realtimedata2 ORDER BY id";
                OdbcConnection myConnection = new OdbcConnection(connStr);        //创建数据库连接
                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();
            }
            catch (Exception ex)
            {
                Console.WriteLine("数据库连接失败" + " " + ex.Message);
            }
            return(dataList);
        }
Exemple #2
0
        public List <Double> getSARLineDatas(List <HSIFutures> list, float step, float maxStep)
        {
            List <Double> sarList = new List <Double>();

            //记录没有没有初始化过
            double INIT_VALUE = -100;
            //加速因子
            double af = 0;                  //加速因子
                                            //极值
            double ep = INIT_VALUE;         //极点价
                                            //判断是上涨还是下跌  false:下跌
            bool   lasttrend = false;
            double SAR       = 0;

            for (int i = 0; i < list.Count() - 1; i++)
            {
                //上一个周期的sar
                double     priorSAR = SAR;
                HSIFutures item     = list[i];
                if (lasttrend)
                {
                    //上涨
                    if (ep == INIT_VALUE || ep < item.GetHigh())
                    {
                        //重新初始化值
                        ep = item.GetHigh();                //当这个周期为上涨,前一个周期的 ep为 最高价
                        af = Math.Min(af + step, maxStep);  //af
                    }
                    SAR = priorSAR + af * (ep - priorSAR);  //这以周期的的SAR值
                    double lowestPrior2Lows = Math.Min(list[Math.Max(1, i) - 1].GetLow(), list[i].GetLow());
                    if (SAR > list[i + 1].GetLow())
                    {
                        SAR = ep;
                        //重新初始化值
                        af        = 0;
                        ep        = INIT_VALUE;
                        lasttrend = !lasttrend;
                    }
                    else if (SAR > lowestPrior2Lows)
                    {
                        SAR = lowestPrior2Lows;
                    }
                }
                else
                {
                    if (ep == INIT_VALUE || ep > list[i].GetLow())
                    {
                        //重新初始化值
                        ep = list[i].GetLow();
                        af = Math.Min(af + step, maxStep);
                    }
                    SAR = priorSAR + af * (ep - priorSAR);
                    double highestPrior2Highs = Math.Max(list[Math.Max(1, i) - 1].GetHigh(), list[i].GetHigh());
                    if (SAR < list[i + 1].GetHigh())
                    {
                        SAR = ep;
                        //重新初始化值
                        af        = 0;
                        ep        = INIT_VALUE;
                        lasttrend = !lasttrend;
                    }
                    else if (SAR < highestPrior2Highs)
                    {
                        SAR = highestPrior2Highs;
                    }
                }
                sarList.Add(SAR);
            }
            //确保和 传入的list size一致,
            int size = list.Count() - sarList.Count();

            for (int i = 0; i < size; i++)
            {
                sarList.Insert(0, sarList[i]);
            }

            //返回了一个包含所有SAR值的数组
            return(sarList);
        }
Exemple #3
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);
            }
        }
Exemple #4
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);
        }