public void AssignProperties(DataItem item, double level, TrendlineType type, DataItem previousItem) { this.item = item; this.level = level; this.type = type; this.previousHit = previousItem; }
//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; }
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); }
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; }
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>"); }
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); }
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); } } }
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; }
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; }
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; }
public void LoadDataSets(DataItem[] items) { Items = items; Items.AppendIndexNumbers(); }
private double EvaluatePriceDistance(DataItem item) { return 0; }
private void setCurrentExtremum(ExtremumType type, DataItem item) { currentExtrema[type] = item; }
public void runRightSide(IAnalyzer analyzer, DataItem item, AssetTimeframe atf) { }
private TrendBreak getTrendBreakIfExists(Trendline trendline, DataItem item) { return null; }
public override void Analyze(DataItem[] items) { var x = "Działa"; }
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); }
public ValuePoint(DataItem dataItem, double value) { this.dataItem = dataItem; this.value = value; }
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); }
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)); }
public void Compare(DataItem item, double level, TrendlineType type, DataItem previousItem) { }
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 = }
public override void Analyze(DataItem[] items) { }
//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; } }
public void runFull(IAnalyzer analyzer, DataItem item, AssetTimeframe atf) { }
/* * Funkcja zwraca liczbę notowań, które zostały do końca zestawu. */ private int quotationsLeft(DataItem item) { return analyzer.getDataItemsLength() - item.Index - 1; }
private double calculatePointForBreakExtremum(Trendline trendline, DataItem item) { return 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); }
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); }
/* 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; }