Ejemplo n.º 1
0
 public void AssignProperties(DataItem item, double level, TrendlineType type, DataItem previousItem)
 {
     this.item = item;
     this.level = level;
     this.type = type;
     this.previousHit = previousItem;
 }
Ejemplo n.º 2
0
 //public TrendHit()
 //{
 //    Guid = System.Guid.NewGuid();
 //}
 //public TrendHit(Trendline trendline) : this()
 //{
 //    this.Trendline = trendline;
 //}
 public TrendHit(Trendline trendline, DataItem item, double crossPoint, TrendlineType type)
 {
     Guid = System.Guid.NewGuid();
     this.Trendline = trendline;
     this.Item = item;
     this.CrossLevel = crossPoint;
     this.Type = type;
 }
Ejemplo n.º 3
0
        public void runFull(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
        {
            this.atf = atf;
            if (item == null) return;
            if (item.Quotation == null) return;

            runLeftSide(analyzer, item, atf);
        }
Ejemplo n.º 4
0
        public static DataItem generateDataItem(DateTime d, List<AnalysisType> types)
        {
            var item = new DataItem();
            item.Asset = testAsset();
            item.Timeframe = testTimeframe();
            item.Date = d;

            if (types.Contains(AnalysisType.Price)) item.Price = new Price() { Date = d };
            if (types.Contains(AnalysisType.MACD)) item.Macd = new Macd() { Date = d };
            if (types.Contains(AnalysisType.ADX)) item.Adx = new Adx() { Date = d };

            return item;
        }
Ejemplo n.º 5
0
        public override void Analyze(DataItem[] items)
        {
            Debug.WriteLine("+;<TrendlineAnalyzer.Analyze>");

            preAnalysisStaff(items);

            //Add new trendlines to collection of trendlines.
            var newTrendlines = getNewTrendlines();
            this.activeTrendlines.AddRange(newTrendlines);

            AnalyzeExistingTrendlines(items);

            Debug.WriteLine("+;<///TrendlineAnalyzer.Analyze>");
        }
Ejemplo n.º 6
0
        public void runRightSide(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
        {
            this.atf = atf;
            if (item == null) return;
            if (item.Quotation == null) return;

            //Calculate new values for peaks and troughs and apply them to the current item price.
            //If any of this is changed, this price will have flag [IsChange] set to @true.
            //This is the only thing that can be changed for items being only updated.
            CheckForExtremum(item, ExtremumType.PeakByClose, false);
            CheckForExtremum(item, ExtremumType.PeakByHigh, false);
            CheckForExtremum(item, ExtremumType.TroughByClose, false);
            CheckForExtremum(item, ExtremumType.TroughByLow, false);
            CheckPriceGap(item);
        }
Ejemplo n.º 7
0
        public void Analyze(Trendline trendline, DataItem[] items, DataItem startItem)
        {
            var _startItem = (startItem == null ? trendline.InitialPoint.dataItem : startItem);
            var _startIndex = _startItem.Index;
            var currentHit = trendline.LastHit();
            var currentBounce = trendline.LastBounce();

            for (var i = _startIndex; i < items.Length; i++)
            {
                DataItem item = items[i];
                TrendlineType type = trendline.CurrentType;
                bool isExtremum = item.Price.IsExtremum(type);
                double level = trendline.GetLevel(i);

                ////Get points for this dataItem.
                //var points = item.Price.calculateTrendlineQuotationPoints(trendline);

                if (isExtremum &&
                    trendline.IsMinimumForHit(item) &&
                    (currentHit == null || i - currentHit.Item.Index > 1))
                {

                    //Hit.
                    trendline.setNewHit(item, level, type);
                    currentHit = trendline.currentHit;
                    currentBounce = trendline.currentBounce;

                }
                else
                {

                    bool isBreakClose = ((item.Quotation.Close - trendline.GetLevel(i)) * trendline.CurrentType.GetFactor() > 0);
                    double ptBreakExtremum = calculatePointForBreakExtremum(trendline, item);

                    if (isBreakClose)
                    {
                        trendline.setNewBreak(item);
                    }

                    currentBounce.AddExtremumBreak(ptBreakExtremum);
                    currentBounce.AddQuotation(trendline, item);

                }

            }
        }
Ejemplo n.º 8
0
        public static DataItem FromDto(DataItemDto dto)
        {
            var item = new DataItem();
            //item.AssetId = dto.AssetId;
            item.Asset = Asset.GetAssetById(dto.AssetId);
            item.Date = dto.PriceDate;
            item.Timeframe = Timeframe.GetTimeframeByShortName(dto.Timeframe);

            if (dto.QuotationId > 0)
            {
                item.Quotation = new Quotation
                {
                    AssetId = dto.AssetId,
                    Date = dto.PriceDate,
                    Open = dto.OpenPrice,
                    Low = dto.LowPrice,
                    High = dto.HighPrice,
                    Close = dto.ClosePrice,
                    Volume = dto.Volume ?? 0,
                    Id = dto.QuotationId
                };
            }

            if (dto.Price != null)
            {
                item.Price = Price.FromDto(dto.Price);
            }

            if (dto.Macd != null)
            {
                item.Macd = Macd.FromDto(dto.Macd);
            }

            if (dto.Adx != null)
            {
                item.Adx = Adx.FromDto(dto.Adx);
            }

            if (dto.Candlestick != null)
            {

            }

            return item;
        }
Ejemplo n.º 9
0
        public void Compare(DataItem item, double level, TrendlineType type, DataItem previousItem)
        {
            /* Zresetuj obiekt przed rozpoczęciem nowych obliczeń. */
            Reset();
            AssignProperties(item, level, type, previousItem);

            this.priceOverBreak = CalculatePriceOverBreak();

            /* Oblicz różnicę w dystansie. Jeżeli świeca leży daleko od linii trendu
             * jej punktacja wynosi 0 i funkcja od razu kończy działanie, żeby nie
             * marnować zasobów.
             * Świece leżące po złej stronie linii trendu otrzymują ocenę ujemną.
             * Świece leżące blisko linii trendu otrzymują ocenę dodatnią. */
            var priceScore = EvaluateScore();

            /* Najpierw sprawdza czy notowanie jest przełamaniem linii trendu
             * (czyli cena zamknięcia powyżej linii oporu lub poniżej linii wsparcia).
             * Jeżeli tak, obliczenia nie są kontynuowane.*/
            AnalyzeBreak(item, level, type);
            if (IsBreak()) return;
        }
Ejemplo n.º 10
0
        protected bool CheckForExtremum(DataItem item, ExtremumType type, bool fromScratch)
        {
            Extremum extremum;

            if (!fromScratch)
            {
                //Jeżeli analiza nie jest przeprowadzana od początku, sprawdzane jest czy dla tego DataItemu
                //przypisany jest obieket ExtremumCalculator danego typu. Jeżeli nie, oznacza to, że już
                //wcześniej został zdyskwalifikowany i nie ma sensu go sprawdzać.
                extremum = item.Price.GetExtremumObject(type);
                if (extremum == null) return false;
                if (!extremum.IsOpen) return false;

                //Sprawdź czy notowania późniejsze względem tego pozwalają uznać je za ekstremum.
                var laterCounter = CountSerie(item.Index, type.IsPeak(), type.ByClose(), false);
                if (laterCounter < MinRange && laterCounter < (analyzer.getDataItemsLength() - 1 - item.Index))
                {
                    extremum.Cancelled = true;
                    item.Price.ApplyExtremumValue(type, null);
                    item.Price.IsUpdated = true;
                    return true;
                }
                else
                {
                    extremum.LaterCounter = laterCounter;
                }

            }
            else
            {
                //Wartości oparte na wcześniejszych notowaniach obliczane są tylko, jeżeli analiza wykonywana jest od zera.
                var earlierCounter = CountSerie(item.Index, type.IsPeak(), type.ByClose(), true);
                var laterCounter = CountSerie(item.Index, type.IsPeak(), type.ByClose(), false);

                //Jeżeli liczba wcześniejszych lub późniejszych notowań gorszych od tego notowania nie osiągnęła
                //minimalnego poziomu, to notowanie jest dyskwalifikowane jako ekstremum i nie ma sensu go dalej sprawdzać.
                if (earlierCounter < MinRange) return false;
                if (laterCounter < MinRange && laterCounter < (analyzer.getDataItemsLength() - 1 - item.Index)) return false;

                extremum = new Extremum(item.Date, atf, type.IsPeak(), type.ByClose());
                extremum.EarlierCounter = earlierCounter;
                extremum.LaterCounter = laterCounter;
                extremum.EarlierAmplitude = FindEarlierPriceAmplitude(type, item, getCurrentExtremum(type));
                extremum.EarlierChange1 = GetPriceChange(item, extremum, true, 1);
                extremum.EarlierChange2 = GetPriceChange(item, extremum, true, 2);
                extremum.EarlierChange3 = GetPriceChange(item, extremum, true, 3);
                extremum.EarlierChange5 = GetPriceChange(item, extremum, true, 5);
                extremum.EarlierChange10 = GetPriceChange(item, extremum, true, 10);
                extremum.Volatility = item.Quotation.Volatility();

                //Calculate [LaterAmplitude] for previous extremum.
                var prevExtremumDataItem = getCurrentExtremum(type);
                if (prevExtremumDataItem != null)
                {
                    var prevExtremum = prevExtremumDataItem.Extremum(type);
                    if (prevExtremum != null)
                    {
                        var laterAmplitude = FindLaterPriceAmplitude(type, prevExtremumDataItem, item);
                        prevExtremum.LaterAmplitude = laterAmplitude;
                        prevExtremumDataItem.Price.IsUpdated = true;
                    }
                }

            }

            //Właściwie, to już wcześniej zostało zapewnione, że do tego miejsca wykonanie programu dotrze
            //tylko, jeżeli extremum nie jest puste, ale mimo to kompilator nie przepuszcza bez takiego warunku tutaj.
            if (extremum != null)
            {
                //extremum.LaterAmplitude = FindPriceAmplitude(item, extremum, false);
                if (extremum.LaterChange1 == null) extremum.LaterChange1 = GetPriceChange(item, extremum, false, 1);
                if (extremum.LaterChange2 == null) extremum.LaterChange2 = GetPriceChange(item, extremum, false, 2);
                if (extremum.LaterChange3 == null) extremum.LaterChange3 = GetPriceChange(item, extremum, false, 3);
                if (extremum.LaterChange5 == null) extremum.LaterChange5 = GetPriceChange(item, extremum, false, 5);
                if (extremum.LaterChange10 == null) extremum.LaterChange10 = GetPriceChange(item, extremum, false, 10);
                extremum.IsOpen = (item.Index + extremum.LaterCounter == analyzer.getDataItemsLength() - 1) || quotationsLeft(item) < 10;
                if (extremum.IsConfirmed())
                {
                    setCurrentExtremum(type, item);
                }
                item.Price.ApplyExtremumValue(type, extremum);
                item.Price.IsUpdated = true;
            }

            return true;
        }
Ejemplo n.º 11
0
 public void LoadDataSets(DataItem[] items)
 {
     Items = items;
     Items.AppendIndexNumbers();
 }
Ejemplo n.º 12
0
 private double EvaluatePriceDistance(DataItem item)
 {
     return 0;
 }
Ejemplo n.º 13
0
 private void setCurrentExtremum(ExtremumType type, DataItem item)
 {
     currentExtrema[type] = item;
 }
Ejemplo n.º 14
0
 public void runRightSide(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
 {
 }
Ejemplo n.º 15
0
 private TrendBreak getTrendBreakIfExists(Trendline trendline, DataItem item)
 {
     return null;
 }
Ejemplo n.º 16
0
 public override void Analyze(DataItem[] items)
 {
     var x = "Działa";
 }
Ejemplo n.º 17
0
        protected double? GetPriceChange(DataItem item, Extremum extremum, bool earlier, int counter)
        {
            if (!earlier && quotationsLeft(item) < counter) return null;

            var index = earlier ?
                Math.Max(0, item.Index - counter) :
                Math.Min(item.Index + counter, analyzer.getDataItemsLength() - 1);

            double comparedValue = analyzer.getDataItem(index).Quotation.ProperValue(extremum.Type);
            double baseValue = item.Quotation.ProperValue(extremum.Type);
            double difference = (baseValue - comparedValue) / Math.Max(comparedValue, baseValue);
            return difference * (extremum.Type.IsPeak() ? 1 : -1);
        }
Ejemplo n.º 18
0
 public ValuePoint(DataItem dataItem, double value)
 {
     this.dataItem = dataItem;
     this.value = value;
 }
Ejemplo n.º 19
0
        protected double FindEarlierPriceAmplitude(ExtremumType type, DataItem item, DataItem prevExtremum)
        {
            int startIndex;
            int endIndex;

            startIndex = (prevExtremum == null ? 0 : prevExtremum.Index);
            endIndex = item.Index - 1;
            IEnumerable<DataItem> items = analyzer.getDataItems();
            var itemsRange = items.Where(i => i.Index >= startIndex && i.Index <= endIndex);
            if (itemsRange.Count() == 0) return 0;
            double oppositeValue = (type.IsPeak() ?
                                        itemsRange.Min(i => i.Quotation.Low) :
                                        itemsRange.Max(i => i.Quotation.High));
            double baseValue = item.Quotation.ProperValue(type);

            return Math.Abs(oppositeValue - baseValue) / Math.Max(oppositeValue, baseValue);
        }
Ejemplo n.º 20
0
        public void if_quotationService_returns_empty_array_of_data_items_Run_returns_false()
        {
            var mockQuotationService = UnitTestTools.mockedQuotationService();
            DataItem[] items = new DataItem[] { };
            mockQuotationService.Setup(q => q.fetchData(It.IsAny<Dictionary<AnalysisType, IAnalyzer>>())).Returns(items);

            Asset asset = new Asset(1, "USD");
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M15);
            ProcessService service = new ProcessService(asset, timeframe);
            AnalysisType[] types = new AnalysisType[] { AnalysisType.Price };
            service.Setup(types);

            Assert.IsFalse(service.Run(true));
        }
Ejemplo n.º 21
0
 public void Compare(DataItem item, double level, TrendlineType type, DataItem previousItem)
 {
 }
Ejemplo n.º 22
0
        public virtual void Analyze(DataItem[] items)
        {
            //Create price processor (unless it is already loaded).
            if (processor == null) processor = getProcessor();

            //Save [items] array for future reference.
            this.items = items.ToArray();

            int indexAnalysisStart = 0;
            int indexLastCalculation = -1;

            //Calculate required index numbers.
            if (LastCalculationDate != null){
                DateTime ldc = ((DateTime)LastCalculationDate).Proper(AssetTimeframe.timeframe.Symbol);
                DateTime lastRequiredForRightOnlyAnalysis = ldc.addTimeUnits(AssetTimeframe.timeframe.Symbol, -ItemsForAnalysis);
                indexAnalysisStart = findItemIndexByDate(items, lastRequiredForRightOnlyAnalysis);
                indexLastCalculation = findItemIndexByDate(items, ldc);
            }

            //Only right analysis.
            for (var i = Math.Max(indexAnalysisStart, 0) ; i <= indexLastCalculation; i++)
            {
                processor.runRightSide(this, items[i], AssetTimeframe);
            }

            //Complete analysis.
            for (var i = indexLastCalculation + 1; i < items.Length; i++)
            {
                processor.runFull(this, items[i], AssetTimeframe);
            }

            LastCalculationDate = items[items.Length - 1].Date;

            //Save info about analysis to Analysis object.
            //analysis.AnalysisStart =
        }
Ejemplo n.º 23
0
 public override void Analyze(DataItem[] items)
 {
 }
Ejemplo n.º 24
0
        //private bool LaterQuotationsExists(int index)
        //{
        //    for (var i = index; i < analyzer.getDataItemsLength(); i++)
        //    {
        //        DataItem item = analyzer.getDataItem(i);
        //        if (item.Price.IsComplete) return true;
        //    }
        //    return false;
        //}
        private void CheckPriceGap(DataItem item)
        {
            //If [PriceGap] is already calculated, no need to do it again.
            if (item.Price.PriceGap != 0) return;

            //It is impossible to calculate price gap for the first and last item.
            if (item.Index == 0) return;
            if (item.Index == analyzer.getDataItemsLength() - 1) return;

            var previousItem = analyzer.getDataItem(item.Index - 1);
            var nextItem = analyzer.getDataItem(item.Index + 1);

            if (previousItem.Quotation.High < nextItem.Quotation.Low)
            {
                item.Price.PriceGap = 100 * ((nextItem.Quotation.Low - previousItem.Quotation.High) / item.Quotation.Close);
                item.Price.IsUpdated = true;
            }
            else if (previousItem.Quotation.Low > nextItem.Quotation.High)
            {
                item.Price.PriceGap = 100 * ((nextItem.Quotation.High - previousItem.Quotation.Low) / item.Quotation.Close);
                item.Price.IsUpdated = true;
            }
        }
Ejemplo n.º 25
0
 public void runFull(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
 {
 }
Ejemplo n.º 26
0
 /*
  * Funkcja zwraca liczbę notowań, które zostały do końca zestawu.
  */
 private int quotationsLeft(DataItem item)
 {
     return analyzer.getDataItemsLength() - item.Index - 1;
 }
Ejemplo n.º 27
0
 private double calculatePointForBreakExtremum(Trendline trendline, DataItem item)
 {
     return 0;
 }
Ejemplo n.º 28
0
        private void runLeftSide(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
        {
            //Check if quotation is missing (but only in the middle of not-missing quotations,
            //because missing quotations at the end of array was excluded one line above).
            //If it is copy data from the previous quotation.
            if (!item.Quotation.IsComplete())
            {
                var previousQuotation = (item.Index > 0 ? analyzer.getDataItem(item.Index - 1).Quotation : null);
                if (previousQuotation != null)
                {
                    item.Quotation.CompleteMissing(previousQuotation);
                    //_dataService.UpdateQuotation(item.Quotation, Symbol);
                }

            }

            //Ensure that [Price] object is appended to this [DataItem].
            item.Price = new Price();
            item.Price.Date = item.Date;
            if (item.Index > 0) item.Price.CloseDelta = CalculateDeltaClosePrice(item.Quotation.Close, item.Index);
            item.Price.Direction2D = CalculateDirection2D(item.Index);
            item.Price.Direction3D = CalculateDirection3D(item.Index);

            //Calculate new values for peaks and troughs and apply them to the current item price.
            //If any of this is changed, this price will have flag [IsChange] set to @true.
            //This is the only thing that can be changed for items being only updated.
            CheckForExtremum(item, ExtremumType.PeakByClose, true);
            CheckForExtremum(item, ExtremumType.PeakByHigh, true);
            CheckForExtremum(item, ExtremumType.TroughByClose, true);
            CheckForExtremum(item, ExtremumType.TroughByLow, true);
            CheckPriceGap(item);
        }
Ejemplo n.º 29
0
        protected double FindLaterPriceAmplitude(ExtremumType type, DataItem item, DataItem nextExtremum)
        {
            int startIndex = item.Index + 1;
            int endIndex = nextExtremum.Index - 1;
            var itemsRange = analyzer.getDataItems().Where(i => i.Index >= startIndex && i.Index <= endIndex);

            if (itemsRange.Count() == 0) return 0;

            double oppositeValue = (type.IsPeak() ?
                                        itemsRange.Min(i => i.Quotation.Low) :
                                        itemsRange.Max(i => i.Quotation.High));
            double baseValue = item.Quotation.ProperValue(type);

            return Math.Abs(oppositeValue - baseValue) / Math.Max(oppositeValue, baseValue);
        }
Ejemplo n.º 30
0
 /* Funkcja przeliczająca na punktu wahanice ceny w danej świecy.
  * Wysoko ocenione muszą być dwie sytuacje:
  * - świeca z bardzo małym korpusem, ale tylko wtedy, kiedy występuje
  *   od razu po innym trafieniu (najlepiej ze świecą o dużym korpusie).
  * - w innych sytuacjach im większy korpus, tym lepiej.
  */
 private double EvaluatePriceChange(DataItem item)
 {
     return 0;
 }