コード例 #1
0
        private Deal GetDaysDeal(List <Candle> daysCandles)
        {
            var allExtremums = extremumsFinder.FindAllSecondExtremums(daysCandles);

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

                var startCandle = daysCandles[startIndex + 1];
                var startPrice  = startCandle.Open;

                var  distFromOpen = startPrice - daysCandles.First().Open;
                bool isTrendLong  = distFromOpen > 0;
                if (isTrendLong != extremum.IsMinimum)
                {
                    continue;
                }

                if (Math.Abs(distFromOpen) > maxDistFromOpen)
                {
                    return(null);
                }

                var stopResult = stopLossManager.GetTrailingStopResult(daysCandles, startIndex, isTrendLong, allExtremums.SkipWhile(ex => ex.CheckerIndex <= startIndex).ToList());
//                var stopResult = stopLossManager.GetTrailingStopResult(daysCandles.Skip(startIndex + 1), isTrendLong);
                var endPrice = stopResult != -1 ? stopResult : daysCandles[daysCandles.Count - 1].Close;

                return(new Deal(startPrice, endPrice, isTrendLong, startCandle.DateTime));
            }
            return(null);
        }
コード例 #2
0
        private Deal GetDaysDeal(List <Candle> daysCandles)
        {
            var allExtremums = extremumsFinder.FindAllSecondExtremums(daysCandles);

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

                var startCandle = daysCandles[startIndex + 1];
                if (startCandle.Time > lastTradeTime)
                {
                    break;
                }

                var startPrice = startCandle.Open;

//				bool isTrendLong = extremum.Value > daysCandles.First().Open;
                bool isTrendLong = startPrice > daysCandles.First().Open;

                if (isTrendLong != extremum.IsMinimum)
                {
                    continue;
                }
                //isTrendLong = extremum.IsMinimum;

                /*if (!isTrendLong)
                 *      continue;*/

                var dynamicStopLoss = GetDynamicStopLoss(startPrice, isTrendLong, extremum);

                var stopResult = GetStopResult(daysCandles.Skip(startIndex + 1), isTrendLong, dynamicStopLoss);

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

                return(new Deal(startPrice, endPrice, isTrendLong));
            }
            return(null);
        }
コード例 #3
0
ファイル: UnitTests.cs プロジェクト: VPetukhov/StratTester
        public static void TestSecondExtremumsOrder(string toolName, int pegTopSize)
        {
            var repository = new HistoryRepository(toolName, false);

            var extremumFinder = new ExtremumsFinder(pegTopSize);

            foreach (var day in repository.Days)
            {
                var extremums = extremumFinder.FindAllSecondExtremums(day.FiveMins);

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

                Assert.That(!bad);
            }
        }
コード例 #4
0
        private List <Deal> GetDaysDeal(List <Candle> daysCandles)
        {
            var  allExtremums = extremumsFinder.FindAllSecondExtremums(daysCandles);
            bool inDeal       = false;
            bool isTrendLong  = false;
            int  startIndex   = 0;

            var      deals         = new List <Deal>();
            Extremum startExtremum = null;

            foreach (var extremum in allExtremums)
            {
                if (inDeal)
                {
                    if (extremum.IsMinimum == isTrendLong)
                    {
                        continue;
                    }

                    if (isTrendLong && (extremum.Value - startExtremum.Value) < minExtremumStep ||
                        !isTrendLong && (startExtremum.Value - extremum.Value) < minExtremumStep)
                    {
                        continue;
                    }

                    var startPrice  = daysCandles[startIndex + 1].Open;
                    var dealCandles = daysCandles.Skip(startIndex + 1).Take(extremum.CheckerIndex - startIndex).ToList();

                    var stopResult = stopLossManager.GetBreakevenStopResult(dealCandles, isTrendLong);
                    var endPrice   = stopResult != -1 ? stopResult : daysCandles[extremum.CheckerIndex].Close;
                    deals.Add(new Deal(startPrice, endPrice, isTrendLong, daysCandles[startIndex + 1].DateTime, startIndex + 1));

                    inDeal = false;
                    if (stopResult != -1)
                    {
                        break;
                    }
                }

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

                isTrendLong = extremum.IsMinimum;
                inDeal      = true;
            }

            if (inDeal)
            {
                var startPrice = daysCandles[startIndex + 1].Open;

                var dealCandles = daysCandles.Skip(startIndex + 1).ToList();
                var stopResult  = stopLossManager.GetBreakevenStopResult(dealCandles, isTrendLong);
                var endPrice    = stopResult != -1 ? stopResult : daysCandles[dealCandles.Count - 1].Close;
                deals.Add(new Deal(startPrice, endPrice, isTrendLong, daysCandles[startIndex + 1].DateTime, startIndex + 1));
            }
            return(deals);
        }