public void Add(TTick item) { var periodInstance = Period.CreateInstance(); if (Ticks.Any()) { var tickEndTime = periodInstance.NextTimestamp(Ticks.Last().DateTime); if (item.DateTime < tickEndTime) { throw new InvalidTimeFrameException(item.DateTime); } if (_maxTickCount.HasValue && Ticks.Count >= _maxTickCount.Value) { Ticks = Ticks.Skip(Ticks.Count - _maxTickCount.Value + 1).Take(_maxTickCount.Value).ToList(); } } Ticks.Add(item); }
private void UpdatePlot(DurationEnum duration) { Plots.Clear(); if (Ticks == null || !Ticks.Any()) { return; } var candles = CreatePlot(Name, CreateCandleStickSeries(Name + " " + duration, Ticks)); var dateValues = Ticks.ToDateValuePoints(x => x.Close).ToList(); var ema = MovingAverage.CalculateEma(Ticks, 22); var channels = MovingAverage.CalculateEmaChannels(Ticks, 22, 60); var lowerChannel = channels.Select(x => new DateValue { Date = x.Date, Value = x.LowerValue }).ToList(); var upperChannel = channels.Select(x => new DateValue { Date = x.Date, Value = x.UpperValue }).ToList(); var plotChannels = CreatePlot("Channels", CreateLineSeries("Close Price", OxyColor.FromUInt32(0xCCF0A30A), dateValues), CreateLineSeries("EMA 22", OxyColor.FromUInt32(0xCCFA6800), ema), CreateLineSeries("Lower Channel", OxyColor.FromUInt32(0xCCA4C400), lowerChannel), CreateLineSeries("Upper Channel", OxyColor.FromUInt32(0xCC60A917), upperChannel)); var plotMa = CreatePlot("Moving Average", CreateLineSeries("Close Price", OxyColor.FromUInt32(0xCCF0A30A), dateValues), CreateLineSeries("MA 10", OxyColor.FromUInt32(0xCCA4C400), BasicAnalysis.CalculateMovingAverage(Ticks, 10)), CreateLineSeries("MA 100", OxyColor.FromUInt32(0xCC60A917), BasicAnalysis.CalculateMovingAverage(Ticks, 100))); var plotMinMax = CreatePlot("Min max", CreateLineSeries("Close Price", OxyColor.FromUInt32(0xCCF0A30A), dateValues), CreateLineSeries("Max 50", OxyColor.FromUInt32(0xCCA4C400), BasicAnalysis.CalculateMax(Ticks, 50)), CreateLineSeries("Min 50", OxyColor.FromUInt32(0xCC60A917), BasicAnalysis.CalculateMin(Ticks, 50))); var returns = CreatePlot("Returns", "P4", CreateTwoColorLineSeries("Annualized Returns", OxyColor.FromUInt32(0xCC60A917), OxyColor.FromUInt32(0xCCFA6800), CalculateReturns(dateValues))); Plots.Add(new PlotViewModel(candles)); Plots.Add(new PlotViewModel(plotChannels)); Plots.Add(new PlotViewModel(plotMa)); Plots.Add(new PlotViewModel(plotMinMax)); Plots.Add(new PlotViewModel(returns)); //analysisPlotModel.Series.Add(closePrices); //analysisPlotModel.Series.Add(CreateLineSeries("MA 10", OxyColor.FromUInt32(0xCCA4C400), BasicAnalysis.CalculateMovingAverage(Ticks, 10))); //analysisPlotModel.Series.Add(CreateLineSeries("MA 100", OxyColor.FromUInt32(0xCC60A917), BasicAnalysis.CalculateMovingAverage(Ticks, 100))); //analysisPlotModel.Series.Add(CreateLineSeries("Max 10", OxyColor.FromUInt32(0xCC911A0E), BasicAnalysis.CalculateMax(Ticks, 10))); //analysisPlotModel.Series.Add(CreateLineSeries("Max 100", OxyColor.FromUInt32(0xCC1569CE), BasicAnalysis.CalculateMax(Ticks, 100))); //if (dateValues.Count > 30) //{ // var anno1 = new TextAnnotation(); // anno1.Text = "sdkjfhsdjkfhsd"; // anno1.TextPosition = DateTimeAxis.CreateDataPoint(dateValues[10].Date, dateValues[10].Value); // analysisPlotModel.Annotations.Add(anno1); // var anno2 = new ArrowAnnotation(); // anno2.Text = "bla blas bla"; // anno2.EndPoint = DateTimeAxis.CreateDataPoint(dateValues[30].Date, dateValues[30].Value); // anno2.ArrowDirection = new ScreenVector(50, anno2.EndPoint.Y * 0.3); // analysisPlotModel.Annotations.Add(anno2); //} //Plots.Add(new PlotViewModel(analysisPlotModel)); var clenow = new SimpleClenow(Ticks); }