Exemplo n.º 1
0
        public static void Run(string toolName, List <Day> days)
        {
            var outPath = toolName + @"\";

            Directory.CreateDirectory(outPath + candlesPath);
            Directory.CreateDirectory(outPath + firstMaxPath);
            Directory.CreateDirectory(outPath + firstMinPath);
            Directory.CreateDirectory(outPath + secondMaxPath);
            Directory.CreateDirectory(outPath + secondMinPath);

            var extremumsFindex = new ExtremumsFinder(pegTopSize);

            for (int i = 0; i < days.Count; ++i)
            {
                var day           = days[i];
                var candles       = day.FiveMins;
                var firstMaximums = extremumsFindex.FindFirstExtremums(candles, false);
                var firstMinimums = extremumsFindex.FindFirstExtremums(candles, true);

                var secondMaximums = extremumsFindex.FindSecondExtremums(firstMaximums, false);
                var secondMinimums = extremumsFindex.FindSecondExtremums(firstMinimums, true);

                File.WriteAllLines(outPath + candlesPath + i + ".txt", candles.ConvertAll(c => c.High + "\t" + c.Low + "\t" + c.Close + "\t" + c.Open));

                File.WriteAllLines(outPath + firstMaxPath + i + ".txt", firstMaximums.Select(ex => (candles.FindIndex(c => c.Time == ex.Date.TimeOfDay) + 1).ToString()));
                File.WriteAllLines(outPath + firstMinPath + i + ".txt", firstMinimums.Select(ex => (candles.FindIndex(c => c.Time == ex.Date.TimeOfDay) + 1).ToString()));

                File.WriteAllLines(outPath + secondMaxPath + i + ".txt", secondMaximums.Select(ex => (candles.FindIndex(c => c.Time == ex.Date.TimeOfDay) + 1).ToString()));
                File.WriteAllLines(outPath + secondMinPath + i + ".txt", secondMinimums.Select(ex => (candles.FindIndex(c => c.Time == ex.Date.TimeOfDay) + 1).ToString()));
            }
        }
Exemplo n.º 2
0
        public static void TestSecondExtremumsAlternation(string toolName, int pegTopSize)
        {
            //TODO ошибка в том, что реализм требует сортировки firstExtremums по checkerIndex, а текущий метод поиска secondExtremums - сортировки по Date. В общем случае, обоюдная сортировка невозможна
            var repository     = new HistoryRepository(toolName, false);
            var extremumFinder = new ExtremumsFinder(pegTopSize);

            bool bad = false;

            foreach (var day in repository.Days)
            {
                var firstMaximums = extremumFinder.FindFirstExtremums(day.FiveMins, false);
                var maximums      = extremumFinder.FindSecondExtremums(firstMaximums, false);

                var firstMinimums = extremumFinder.FindFirstExtremums(day.FiveMins, true);
                var minimums      = extremumFinder.FindSecondExtremums(firstMinimums, true);

                var allExtremums = maximums
                                   .Concat(minimums)
                                   .OrderBy(ex => ex.CheckerIndex)
                                   .ToList();

                for (int i = 0; i < allExtremums.Count - 1; ++i)
                {
                    if (allExtremums[i].Date >= allExtremums[i + 1].Date && allExtremums[i].IsMinimum == allExtremums[i + 1].IsMinimum)
                    {
                        bad = true;
                        Console.Out.WriteLine(allExtremums[i] + "\t" + allExtremums[i + 1]);
                    }
                }
            }
            Assert.That(!bad);
        }
Exemplo n.º 3
0
        public static void TestFirstExtremumsOrder(string toolName, int pegTopSize, bool isMinimums)
        {
            var repository = new HistoryRepository(toolName, false);

            var extremumFinder = new ExtremumsFinder(pegTopSize);

            foreach (var day in repository.Days)
            {
                var extremums = extremumFinder.FindFirstExtremums(day.FiveMins, isMinimums);

                bool bad = false;
                for (int i = 0; i < extremums.Count; ++i)                       //TODO Люой экстремум
                {
                    for (int j = i + 1; j < extremums.Count; ++j)
                    {
                        if (extremums[j].Date >= extremums[i].Date && extremums[j].CheckerIndex < extremums[i].CheckerIndex)
                        {
                            Console.Out.WriteLine(extremums[i] + "\t" + extremums[j]);
                            bad = true;
                        }
                    }
                }

                Assert.That(!bad);
            }
        }
        private Deal GetDaysDeal(List <Candle> daysCandles)
        {
            var longExtremums  = finder.FindFirstExtremums(daysCandles, true);
            var shortExtremums = finder.FindFirstExtremums(daysCandles, false);

            var allExtremums = finder.MergeExtremums(longExtremums, shortExtremums);

            foreach (var extremum in allExtremums)
            {
                if (extremum.Date.TimeOfDay > lastTradeTime)
                {
                    break;
                }

                var startIndex = extremum.CheckerIndex;
                if (startIndex == daysCandles.Count - 1)
                {
                    break;
                }

                var currentLong  = longExtremums.TakeWhile(ex => ex.Date <= extremum.Date).ToList();
                var currentShort = shortExtremums.TakeWhile(ex => ex.Date <= extremum.Date).ToList();

                int trendDirection = GetTrendDirection(currentLong, currentShort, extremum);
                if (trendDirection == 0)
                {
                    continue;
                }

                bool isTrendLong = trendDirection == 1;

                var startPrice = daysCandles[startIndex + 1].Open;
                var stopResult = stopLossManager.GetBreakevenStopResult(daysCandles.Skip(startIndex + 1), isTrendLong);

                var endPrice = stopResult != -1 ? stopResult : daysCandles[daysCandles.Count - 1].Close;

                return(new Deal(startPrice, endPrice, isTrendLong));
            }
            return(null);
        }
Exemplo n.º 5
0
        public static void TestFirstExtremumsSortByChecker(string toolName, int pegTopSize, bool isMinimums)
        {
            var repository     = new HistoryRepository(toolName, false);
            var extremumFinder = new ExtremumsFinder(pegTopSize);

            bool bad = false;

            foreach (var day in repository.Days)
            {
                var extremums = extremumFinder.FindFirstExtremums(day.FiveMins, isMinimums);

                for (int i = 1; i < extremums.Count; ++i)
                {
                    if (extremums[i - 1].CheckerIndex > extremums[i].CheckerIndex)
                    {
                        Console.Out.WriteLine(extremums[i - 1] + "\t" + extremums[i]);
                        bad = true;
                    }
                }

                Assert.That(!bad);
            }
        }