public void AddMacd(Macd macd, string symbol) { }
private void AnalyzeMacd(int index, bool fromScratch) { //Check if this item should be analyzed. DataItem item = (index < 0 || index >= Items.Length ? null : Items[index]); if (item == null) return; if (item.Quotation == null) return; //If this item nor any later item has complete quotation, it means the previous one //was the last real quotation and analysis should finish here. if (!item.Quotation.IsComplete() && !LaterQuotationsExists(index)) return; //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 = (index > 0 ? Items[index - 1].Quotation : null); if (previousQuotation != null) { item.Quotation.CompleteMissing(previousQuotation); _dataService.UpdateQuotation(item.Quotation, Symbol); } } //Ensure that [Macd] object is appended to this [DataItem]. var isChanged = false; if (item.Macd == null || fromScratch) { item.Macd = new Macd(); item.Macd.Date = item.Date; //Basic MACD values. item.Macd.Ma13 = calculateMa(index, Fast); item.Macd.Ema13 = calculateEma(index, Fast, (index > 0 ? previousMacd.Ema13 : 0)); item.Macd.Ma26 = calculateMa(index, Slow); item.Macd.Ema26 = calculateEma(index, Slow, (index > 0 ? previousMacd.Ema26 : 0)); item.Macd.MacdLine = item.Macd.Ema13 - item.Macd.Ema26; item.Macd.SignalLine = calculateSignalLine(index, item.Macd.MacdLine); item.Macd.Histogram = item.Macd.MacdLine - item.Macd.SignalLine; //[TM] Additional indicators. item.Macd.DeltaHistogram = (previousMacd == null ? 0 : item.Macd.Histogram - previousMacd.Histogram); //[???] histogramExtremum //item.Macd.HistogramDirection3D; //item.Macd.HistogramDirection2D; //item.Macd.HistogramDirectionChanged; item.Macd.HistogramToOx = Math.Sign(item.Macd.Histogram); if (index >= Fast - 1){ if (item.Macd.HistogramToOx == previousMacd.HistogramToOx) { item.Macd.HistogramRow = previousMacd.HistogramRow + 1; } else { item.Macd.HistogramRow = 1; //obliczyć! item.Macd.OxCrossing = 1; } } //Peak and troughs. } //Set previousMacd variable to speed up calculations for next items. previousMacd = item.Macd; if (item.Macd.Id == 0) { _dataService.AddMacd(item.Macd, Symbol); } else if (isChanged) { _dataService.UpdateMacd(item.Macd, Symbol); } }
public void UpdateMacd(Macd macd, string symbol) { }
public static Macd FromDto(MacdDto dto) { var macd = new Macd(); macd.Id = dto.Id; macd.AssetId = dto.AssetId; macd.Date = dto.PriceDate; macd.Ma13 = dto.Ma13; macd.Ema13 = dto.Ema13; macd.Ma26 = dto.Ma26; macd.Ema26 = dto.Ema26; macd.MacdLine = dto.MacdLine; macd.SignalLine = dto.SignalLine; macd.Histogram = dto.Histogram; macd.HistogramAvg = dto.HistogramAvg; macd.HistogramExtremum = dto.HistogramExtremum; macd.DeltaHistogram = dto.DeltaHistogram; macd.DeltaHistogramPositive = dto.DeltaHistogramPositive; macd.DeltaHistogramNegative = dto.DeltaHistogramNegative; macd.DeltaHistogramZero = dto.DeltaHistogramZero; macd.HistogramDirection2D = dto.HistogramDirection2D; macd.HistogramDirection3D = dto.HistogramDirection3D; macd.HistogramDirectionChanged = dto.HistogramDirectionChanged; macd.HistogramToOx = dto.HistogramToOx; macd.HistogramRow = dto.HistogramRow; macd.OxCrossing = dto.OxCrossing; macd.MacdPeak = dto.MacdPeak; macd.LastMacdPeak = dto.LastMacdPeak; macd.MacdPeakSlope = dto.MacdPeakSlope; macd.MacdTrough = dto.MacdTrough; macd.LastMacdTrough = dto.LastMacdTrough; macd.MacdTroughSlope = dto.MacdTroughSlope; return macd; }