Exemple #1
0
        void add3minKLData(DateTime time, KLData kLData)
        {
            int      step        = time.Minute % 3;
            DateTime target_time = time.AddMinutes(-step);

            if (KLDataArr_3min.ContainsKey(target_time))
            {
                KLData okLData = KLDataArr_3min[target_time];
                if (kLData.Low < okLData.Low)
                {
                    okLData.Low = kLData.Low;
                }
                if (kLData.High > okLData.High)
                {
                    okLData.High = kLData.High;
                }

                /*if (step == 0)
                *   okLData.Open = kLData.Open;
                *  if (step == 2)*/
                okLData.Close = kLData.Close;

                okLData.sysTime = target_time;
            }
            else
            {
                KLDataArr_3min.Add(target_time, kLData);
            }

            updateKDJ(ref target_time, ref KLDataArr_3min);
            updateDark_Test(ref target_time, ref KLDataArr_3min);
        }
 /// <summary>
 /// Creates and adds a few ItemViewModel objects into the Items collection.
 /// </summary>
 public void LoadData()
 {
     int i = 0;
     data = new KLData();
     Items.Clear();
     foreach (KLPlace place in data.getPlaces())
     {
         if (chosenTags.Count == 0)
         {
             loadPlace(place, i);
         } else
         if (containsChosenTags(place))
         {
             loadPlace(place, i);    
         } 
         MapOverlay overlay = new MapOverlay()
         {
             GeoCoordinate = place.getCoordinates(),
             Content = new KLPushpin()
             {
                 id = i,
                 
                 PlaceName = place.getName(),
                 Margin = new Thickness(0, -60, 0, 0)
             }
         };
     layer.Add(overlay);       
         i++;
     }
     this.IsDataLoaded = true;
 }
Exemple #3
0
        void updateKLData(JObject o)
        {
            if ((int)o["ErrCode"] != 0)
            {
                Debug.error(o.ToString());
                isInit = false;
                return;
            }
            if ((string)o["RetData"]["StockCode"] != stockno || o["RetData"]["KLDataArr"] == null)
            {
                Debug.error("No date in");
                isInit = false;
                return;
            }

            foreach (JObject arro in o["RetData"]["KLDataArr"])
            {
                try
                {
                    KLData   kLData = new KLData();
                    DateTime time   =
                        FTNN.cov.str2DateTime((string)arro["Time"]);

                    kLData.Close        = FTNN.cov.int2price((int)arro["Close"]);
                    kLData.High         = FTNN.cov.int2price((int)arro["High"]);
                    kLData.Low          = FTNN.cov.int2price((int)arro["Low"]);
                    kLData.Open         = FTNN.cov.int2price((int)arro["Open"]);
                    kLData.Volume       = (long)arro["Volume"];
                    kLData.Turnover     = (long)arro["Turnover"];
                    kLData.PERatio      = (int)arro["PERatio"];
                    kLData.TurnoverRate = (int)arro["TurnoverRate"];
                    kLData.Time         = (string)arro["Time"];
                    kLData.sysTime      = time;

                    addKLData(ref time, ref kLData, ref KLDataArr);
                }
                catch (Exception e)
                {
                    Debug.LogError(e.ToString());
                }
                // Debug.LogInfo(arro.ToString());
            }
            Task.Run(() => {
                try
                {
                    if (OnUpdate != null)
                    {
                        OnUpdate.Invoke();
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("Quote update Error \n" + e.ToString());
                }
            });
        }
Exemple #4
0
        void buy(int orientation, KLData kLData, string other = "")
        {
            Tran tran = new Tran();

            tran.orientation = orientation;
            tran.kLData      = kLData;
            tran.isClose     = false;
            //tran.buyPrice = orientation > 0 ? kLData.High : kLData.Low;
            tran.buyPrice  = kLData.Close;
            tran.other     = other;
            tran.isOuputed = false;
            tranList.Add(tran);

            //Debug.consol("\n[Byu "+ orientation+ "]\n");
        }
Exemple #5
0
        void addKLData(ref DateTime time, ref KLData kLData, ref SortedList <DateTime, KLData> KLDataArr)
        {
            if (kLData.Close == 0 && kLData.High == 0 && kLData.Low == 0 && kLData.Open == 0)
            {
                return;
            }

            if (!KLDataArr.ContainsKey(time))
            {
                KLDataArr.Add(time, kLData);
            }
            else
            {
                KLDataArr[time] = kLData;
            }

            updateKDJ(ref time, ref KLDataArr);
            updateDark_Test(ref time, ref KLDataArr);
            add3minKLData(time, kLData);
        }
Exemple #6
0
        public void updateHistory(DateTime From, DateTime To, Action callback)
        {
            var sql = JObject.FromObject(new
            {
                Market     = market,
                StockCode  = stockno,
                KLType     = "1",
                RehabType  = "1",
                MaxKLNum   = "0",
                NeedKLData = "",
                start_date = FTNN.cov.dateTime2Str(From),
                end_date   = FTNN.cov.dateTime2Str(To)
            });

            string filePath = Program.tmpPath + @"1024\" + tools.MD5Hash(sql.ToString()) + "_" + market + "_" + stockno + "_" + From.Year + From.Month + From.Day + "_" + To.Year + To.Month + To.Day + ".1024.tmp";

            System.IO.Directory.CreateDirectory(Program.tmpPath + @"1024\");
            Debug.LogInfo("Start update");
            if (File.Exists(filePath))
            {
                using (StreamReader file = File.OpenText(filePath))
                    using (JsonTextReader reader = new JsonTextReader(file))
                    {
                        JObject o = (JObject)JToken.ReadFrom(reader);
                        if ((int)o["ErrCode"] != 0)
                        {
                            Debug.error("updateHistory Error \n" + o.ToString());
                            isInit = false;
                            callback();
                            return;
                        }
                        //Debug.info("updateHistory in file " + o.ToString());
                        foreach (JObject arro in o["RetData"]["HistoryKLArr"])
                        {
                            try
                            {
                                KLData   kLData = new KLData();
                                DateTime time   =
                                    FTNN.cov.str2DateTime((string)arro["Time"]);

                                kLData.Close        = (long)arro["Close"] / 1000000000;
                                kLData.High         = (long)arro["High"] / 1000000000;
                                kLData.Low          = (long)arro["Low"] / 1000000000;
                                kLData.Open         = (long)arro["Open"] / 1000000000;
                                kLData.Volume       = (long)arro["Volume"] / 1000;
                                kLData.Turnover     = (long)arro["Turnover"];
                                kLData.PERatio      = (int)arro["PERatio"];
                                kLData.TurnoverRate = (int)arro["TurnoverRate"];
                                kLData.Time         = (string)arro["Time"];
                                kLData.sysTime      = time;

                                addKLData(ref time, ref kLData, ref KLDataArr);
                            }
                            catch (Exception e)
                            {
                                Debug.LogError(e.ToString());
                            }
                            // Debug.LogInfo(arro.ToString());
                        }
                        Debug.LogInfo("updateHistory callback");
                        callback();
                    }
            }
            else
            {
                Program.ftnn.request(FTNN.protocol.历史K线,
                                     sql, (o) => {
                    if ((int)o["ErrCode"] != 0)
                    {
                        Debug.error("updateHistory Error \n" + o.ToString());
                        isInit = false;
                        callback();
                        return;
                    }
                    //Debug.info("updateHistory online " + o.ToString());
                    foreach (JObject arro in o["RetData"]["HistoryKLArr"])
                    {
                        try
                        {
                            KLData kLData = new KLData();
                            DateTime time =
                                FTNN.cov.str2DateTime((string)arro["Time"]);

                            kLData.Close        = (long)arro["Close"] / 1000000000;
                            kLData.High         = (long)arro["High"] / 1000000000;
                            kLData.Low          = (long)arro["Low"] / 1000000000;
                            kLData.Open         = (long)arro["Open"] / 1000000000;
                            kLData.Volume       = (long)arro["Volume"] / 1000;
                            kLData.Turnover     = (long)arro["Turnover"];
                            kLData.PERatio      = (int)arro["PERatio"];
                            kLData.TurnoverRate = (int)arro["TurnoverRate"];
                            kLData.Time         = (string)arro["Time"];
                            kLData.sysTime      = time;

                            addKLData(ref time, ref kLData, ref KLDataArr);
                        }
                        catch (Exception e)
                        {
                            Debug.LogError(e.ToString());
                        }
                        // Debug.LogInfo(arro.ToString());
                    }
                    Debug.LogInfo("updateHistory callback");
                    callback();

                    if (To < DateTime.Now.AddDays(-1) && o["RetData"]["HistoryKLArr"] != null)
                    {
                        using (StreamWriter file = File.CreateText(filePath))
                            using (JsonTextWriter writer = new JsonTextWriter(file))
                            {
                                o.WriteTo(writer);
                            }
                    }
                });
            }
        }
Exemple #7
0
        public void updateDark_Test(/*ref KLData kLData,*/ ref DateTime time, ref SortedList <DateTime, KLData> KLDataArr)
        {
            KLData     kLData = KLDataArr[time];
            _Dark_Test dt     = new _Dark_Test();

            //Update MA



            double N = 50, N_10 = 0, N_20 = 0, N_50 = 0;
            double MID = 0, MID_10 = 0, MID_20 = 0, MID_50 = 0;
            int    index = KLDataArr.IndexOfKey(time);

            for (int i = index; i >= 0 && i > index - N; i--)
            {
                if (N_10 < 10)
                {
                    N_10++;
                    MID_10 += KLDataArr.Values[i].Close;
                }
                if (N_20 < 20)
                {
                    N_20++;
                    MID_20 += KLDataArr.Values[i].Close;
                }
                if (N_50 < 50)
                {
                    N_50++;
                    MID_50 += KLDataArr.Values[i].Close;
                }

                MID += KLDataArr.Values[i].Close;
            }
            MID    /= N;
            MID_10 /= N_10;
            MID_20 /= N_20;
            MID_50 /= N_50;

            dt.MA_10 = MID_10;
            dt.MA_20 = MID_20;
            dt.MA_50 = MID_50;


            for (int i = index; i >= 0 && i > index - N_20; i--)
            {
                dt.Avg_dt_20 += Math.Abs(KLDataArr.Values[i].Close - MID_20);
            }
            dt.Avg_dt_20 /= N_20;

            for (int i = index; i >= 0 && i > index - N_10; i--)
            {
                dt.Avg_dt_10 += Math.Abs(KLDataArr.Values[i].Close - MID_10);
            }
            dt.Avg_dt_10 /= N_10;


            N   = 20;
            MID = 0;
            for (int i = index; i >= 0 && i > index - N; i--)
            {
                MID += KLDataArr.Values[i].Close;
            }
            MID /= N;
            for (int i = index; i >= 0 && i > index - N; i--)
            {
                dt.Avg_dt_20_bug += Math.Abs(KLDataArr.Values[i].Close - MID);
            }
            dt.Avg_dt_20_bug /= 20;


            /*N = 9;
             * MID = 0;
             * for (int i = index; i >= 0 && i > index - N; i--)
             * {
             *  MID += KLDataArr.Values[i].Close;
             * }
             * MID /= N;
             * for (int i = index; i >= 0 && i > index - N; i--)
             * {
             *  dt.Avg_dt_9 += Math.Abs(KLDataArr.Values[i].Close - MID);
             * }
             * dt.Avg_dt_9 /= N;*/


            kLData._dark_Test = dt;
            KLDataArr[time]   = kLData;
        }
Exemple #8
0
        void updateKDJ(/*ref KLData kLData,*/ ref DateTime time, ref SortedList <DateTime, KLData> KLDataArr)
        {
            KLData       kLData = KLDataArr[time];
            const double N = 9, M1 = 3, M2 = 3;

            KDJ    kdj = new KDJ();
            double K = 0, D = 0, J = 0, RSV = 0;
            int    index = KLDataArr.IndexOfKey(time);


            //Update MinMaxPirce
            double min = Double.MaxValue, max = Double.MinValue;

            for (int i = index; i >= 0 && i > index - N; i--)
            {
                //A slow way!!
                //var t = KLDataArr.ElementAt(i).Value;
                var t = KLDataArr.Values[i];
                if (t.Low < min)
                {
                    min = t.Low;
                }
                if (t.High > max)
                {
                    max = t.High;
                }
            }

            if (index == 0 || Double.IsNaN(KLDataArr.Values[index - 1].kdj.K))
            {
                RSV = (kLData.Close - min) / (max - min) * 100;
                K   = (1 * RSV + (M1 - 1) * 0) / 1;
                D   = (1 * K + (M2 - 1) * 0) / 1;
                J   = 3 * K - 2 * D;
            }
            else
            {
                var okLData = KLDataArr.Values[index - 1];
                RSV = (kLData.Close - min) / (max - min) * 100;
                K   = (1 * RSV + (M1 - 1) * okLData.kdj.K) / M1;
                D   = (1 * K + (M2 - 1) * okLData.kdj.D) / M2;
                J   = 3 * K - 2 * D;

                //For other
                long timeBetween = kLData.sysTime.Ticks - okLData.sysTime.Ticks;

                kdj.crossPoint = Vector2.checkCrossPoint
                                 (
                    new Vector2(okLData.kdj.K, 0),
                    new Vector2(K, timeBetween),
                    new Vector2(okLData.kdj.J, 0),
                    new Vector2(J, timeBetween)
                                 );

                /*kdj.angle_KJ =
                 *  angleBetween(*/
            }

            kdj.K      = K;
            kdj.D      = D;
            kdj.J      = J;
            kdj.RSV    = RSV;
            kLData.kdj = kdj;

            KLDataArr[time] = kLData;
        }
Exemple #9
0
        void settlement(KLData kLData)
        {
            for (int i = 0; i < tranList.Count; i++)
            {
                Tran t = tranList[i];
                if (t.isClose)
                {
                    continue;
                }

                /*if (false)
                 *  if (kLData.kdj.crossPoint.Y != 0)
                 *  {
                 *      t.skLData = kLData;
                 *      t.sellPrice = kLData.Close;
                 *
                 *      t.result = (t.orientation > 0 )?( t.sellPrice>t.buyPrice?"Win":"Lost"   ): (t.sellPrice < t.buyPrice ? "Win" : "Lost");
                 *
                 *      t.isClose = true;
                 *  }*/

                if (t.orientation > 0)
                {
                    if (kLData.Low < t.buyPrice - (Scale * cutOffPoint))
                    {
                        t.isClose = true;
                        lost++;
                        t.sellPrice = kLData.Low;
                        t.result    = "Lost";
                        t.skLData   = kLData;
                    }
                    else if (t.buyPrice + Scale * (1 + cutSellPoint) < kLData.High)
                    {
                        t.isClose = true;
                        win++;
                        t.sellPrice = kLData.High;
                        t.result    = "Win";
                        t.skLData   = kLData;
                    }
                }
                else if (t.orientation < 0)
                {
                    if (kLData.High > t.buyPrice + (Scale * cutOffPoint))
                    {
                        t.isClose = true;
                        lost++;
                        t.sellPrice = kLData.High;
                        t.result    = "Lost";
                        t.skLData   = kLData;
                    }
                    else if (t.buyPrice - Scale * (1 + cutSellPoint) > kLData.Low)
                    {
                        t.isClose = true;
                        win++;
                        t.sellPrice = kLData.High;
                        t.result    = "Win";
                        t.skLData   = kLData;
                    }
                }
                tranList[i] = t;
            }
        }