private void UpdatePriceChart(PriceSeries priceData) { // Create a new series and append Open, High, Low, Close data _ohlcDataSeries = new OhlcDataSeries <DateTime, double>(); _ohlcDataSeries.Append(priceData.TimeData, priceData.OpenData, priceData.HighData, priceData.LowData, priceData.CloseData); PriceData = (IOhlcDataSeries <DateTime, double>)(UseDiscontinuousDateTimeAxis ? new DiscontinuousAxisFilter <double>(_ohlcDataSeries, Calendar).FilteredDataSeries : _ohlcDataSeries); PriceData.SeriesName = priceData.Symbol; var xyDataSeries = new XyDataSeries <DateTime, double>(); xyDataSeries.Append(priceData.TimeData, priceData.CloseData); var discontinuousSeries = new DiscontinuousAxisFilter <double>(xyDataSeries, Calendar).FilteredDataSeries as IDataSeries <DateTime, double>; // Create a series for the 200 period SMA which will be plotted as a line chart Sma200Series = UseDiscontinuousDateTimeAxis ? (IXyDataSeries <DateTime, double>) new MovingAverageFilter <DateTime>(discontinuousSeries, 200).FilteredDataSeries : (IXyDataSeries <DateTime, double>) new MovingAverageFilter <DateTime>(xyDataSeries, 200).FilteredDataSeries; Sma200Series.SeriesName = "200 SMA"; // Create a series for the 50 period SMA which will be plotted as a line chart Sma50Series = UseDiscontinuousDateTimeAxis ? (IXyDataSeries <DateTime, double>) new MovingAverageFilter <DateTime>(discontinuousSeries, 50).FilteredDataSeries : (IXyDataSeries <DateTime, double>) new MovingAverageFilter <DateTime>(xyDataSeries, 50).FilteredDataSeries; Sma50Series.SeriesName = "50 SMA"; // Update the chart type and timeframe with current settings UpdateChartType(_chartType); }
public PricePaneModel(PriceSeries prices) : base(PRICES, "$%.4f", true) { var stockPrices = new OhlcDataSeries <DateTime, double> { SeriesName = "EUR/USD" }; stockPrices.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData); AddRenderableSeries(new SCIFastCandlestickRenderableSeries { DataSeries = stockPrices, YAxisId = PRICES, StrokeUpStyle = new SCISolidPenStyle(0xff52cc54, 1f), FillUpBrushStyle = new SCISolidBrushStyle(0xa052cc54), StrokeDownStyle = new SCISolidPenStyle(0xffe26565, 1f), FillDownBrushStyle = new SCISolidBrushStyle(0xd0e26565) }); var maLow = new XyDataSeries <DateTime, double> { SeriesName = "Low Line" }; maLow.Append(prices.TimeData, prices.CloseData.MovingAverage(50)); AddRenderableSeries(new SCIFastLineRenderableSeries { DataSeries = maLow, StrokeStyle = new SCISolidPenStyle(0xFFFF3333, 1f), YAxisId = PRICES }); var maHigh = new XyDataSeries <DateTime, double> { SeriesName = "High Line" }; maHigh.Append(prices.TimeData, prices.CloseData.MovingAverage(200)); AddRenderableSeries(new SCIFastLineRenderableSeries { DataSeries = maHigh, StrokeStyle = new SCISolidPenStyle(0xFF33DD33, 1f), YAxisId = PRICES }); var priceMarker = new SCIAxisMarkerAnnotation { Position = stockPrices.YValues.ValueAt(stockPrices.Count - 1).ToComparable(), Style = { BackgroundColor = 0xFFFF3333.ToColor() }, YAxisId = PRICES }; var maLowMarker = new SCIAxisMarkerAnnotation { Position = maLow.YValues.ValueAt(maLow.Count - 1).ToComparable(), Style = { BackgroundColor = 0xFFFF3333.ToColor() }, YAxisId = PRICES }; var maHighMarker = new SCIAxisMarkerAnnotation { Position = maHigh.YValues.ValueAt(maHigh.Count - 1).ToComparable(), Style = { BackgroundColor = 0xFF33DD33.ToColor() }, YAxisId = PRICES }; Annotations.Add(priceMarker); Annotations.Add(maLowMarker); Annotations.Add(maHighMarker); }
private void UpdateVolumeChart(PriceSeries prices) { // Create a new series and append Open, High, Low, Close data VolumeData = new XyDataSeries <DateTime, long>(); VolumeData.SeriesName = string.Format("{0} Volume", prices.Symbol); VolumeData.Append(prices.TimeData, prices.VolumeData); }
private double SyncedRankCorrelation(PriceSeries inputSeries1, SyncedDataSeries inputSeries2, int corrPeriod) // SyncedRankCorrelation: Calculate the Spearman Rank Correlation of 2 Data Series, using only the bars which are synchronized // // Inputs: // inputSeries1: 1st DataSeries, typically Closes[x] // inputSeries2: SyncedDataSeries, synced to InputSeries1; some bars (flagged by BoolSeries "Synced") hold valid (synchronized) values // corrPeriod: Period for Correlation calculation; there must be >= CorrPeriod synced bars in the input series, or it will throw an exception // { int index1 = 0; double[] dataArray1 = new double[corrPeriod]; double[] dataArray2 = new double[corrPeriod]; for (int counter = corrPeriod - 1; counter >= 0; counter--) { while (!inputSeries2.Synced[index1]) //Find next synced Bar { index1++; } dataArray1[counter] = inputSeries1[index1]; dataArray2[counter] = inputSeries2[index1]; index1++; } return(KDRankCorrelation(dataArray1, dataArray2, corrPeriod)); }
public VolumePaneModel(PriceSeries prices) : base(VOLUME, "", false) { YAxis.NumberFormatter = new NSNumberFormatter { MaximumIntegerDigits = 3, NumberStyle = NSNumberFormatterStyle.Scientific, ExponentSymbol = @"E+" }; var volumePrices = new XyDataSeries <DateTime, double> { SeriesName = "Volume" }; volumePrices.Append(prices.TimeData, prices.VolumeData.Select(x => (double)x)); AddRenderableSeries(new SCIFastColumnRenderableSeries { DataSeries = volumePrices, YAxisId = VOLUME, FillBrushStyle = new SCISolidBrushStyle(UIColor.White), StrokeStyle = new SCISolidPenStyle(UIColor.White, 1f) }); Annotations.Add(new SCIAxisMarkerAnnotation { Position = volumePrices.YValues.ValueAt(volumePrices.Count - 1).ToComparable(), YAxisId = VOLUME, }); }
private double SyncedPctChangeCorrelation(PriceSeries inputSeries1, SyncedDataSeries inputSeries2, int corrPeriod, int changeLookback) { int index = 0; double[] pctChangeArray1 = new double[corrPeriod]; double[] pctChangeArray2 = new double[corrPeriod]; while (!inputSeries2.Synced[index]) //Find most recent synced Bar { index++; } double val1 = inputSeries1[index]; double val2 = inputSeries2[index]; index++; for (int counter = corrPeriod - 1; counter >= 0; counter--) { int changeIndex; while (!inputSeries2.Synced[index]) //Find previous synced Bar { index++; } double chg2 = inputSeries2.SyncedGet(changeLookback - 1, index, out changeIndex); // this will scan back more synced bars if changeLookback > 0 double chg1 = inputSeries1[changeIndex]; pctChangeArray1[counter] = (val1 - chg1) / chg1; pctChangeArray2[counter] = (val2 - chg2) / chg2; val1 = inputSeries1[index]; val2 = inputSeries2[index]; index++; } // return(KDRankCorrelation(pctChangeArray1,pctChangeArray2,corrPeriod)); // maybe rank correlation of PctChange would be better? return(KDCorrelation(pctChangeArray1, pctChangeArray2, corrPeriod)); }
public MacdPaneModel(Context context, PriceSeries prices) : base(context, MACD, "0.0", false) { var macdPoints = prices.CloseData.Macd(12, 25, 9); var histogramSeries = new XyDataSeries <DateTime, double> { SeriesName = "Histogram" }; histogramSeries.Append(prices.TimeData, macdPoints.Select(x => x.Divergence)); AddRenderableSeries(new FastColumnRenderableSeries { DataSeries = histogramSeries, YAxisId = MACD }); var macdSeries = new XyyDataSeries <DateTime, double> { SeriesName = "MACD" }; macdSeries.Append(prices.TimeData, macdPoints.Select(x => x.Macd), macdPoints.Select(x => x.Signal)); AddRenderableSeries(new FastBandRenderableSeries { DataSeries = macdSeries, YAxisId = MACD }); Annotations.Add(new AxisMarkerAnnotation(context) { Y1 = (Java.Lang.IComparable)histogramSeries.YValues.Get(histogramSeries.Count - 1), YAxisId = MACD }); Annotations.Add(new AxisMarkerAnnotation(context) { Y1 = (Java.Lang.IComparable)macdSeries.YValues.Get(macdSeries.Count - 1), YAxisId = MACD }); }
public StockPriceChart( string name, StockHandle stock, IPriceSeries prices ) { Name = name; Stock = stock; Prices = new PriceSeries( prices ); IndicatorPoints = new Dictionary<string, IPriceSeries>(); Signals = SignalSeries.Null; }
public StockPriceChart(string name, StockHandle stock, IPriceSeries prices) { Name = name; Stock = stock; Prices = new PriceSeries(prices); IndicatorPoints = new Dictionary <string, IPriceSeries>(); Signals = SignalSeries.Null; }
public void Apply_DayMissing_DataFromDayBeforeIsTaken() { var op = new InterpolateMissingDatesOperator(); var monday = new SimplePrice(new DateTime(2011, 1, 10), 123); var weddnesday = new SimplePrice(new DateTime(2011, 1, 12), 456); var input = new PriceSeries(SeriesIdentifier.Null, new[] { monday, weddnesday }); var series = op.Apply(input); Assert.That(series[1].Value, Is.EqualTo(123)); }
public void Apply_LessOrEqualPointsThanMax_SeriesRemainsUnchanged() { var op = new ReducePointsOperator(2); var monday = new SimplePrice(new DateTime(2011, 1, 10), 12); var thuesday = new SimplePrice(new DateTime(2011, 1, 11), 23); var input = new PriceSeries(SeriesIdentifier.Null, new[] { monday, thuesday }); var series = op.Apply(input); Assert.That(series, Is.EquivalentTo(input)); }
public void Apply_NoDataForWeekend_NoDataInterpolatedForWeekend() { var op = new InterpolateMissingDatesOperator(); var friday = new SimplePrice(new DateTime(2011, 1, 7), 0); var monday = new SimplePrice(new DateTime(2011, 1, 10), 0); var input = new PriceSeries(SeriesIdentifier.Null, new[] { friday, monday }); var series = op.Apply(input); Assert.That(series, Is.EquivalentTo(input)); }
public void Apply_NoDataForWeekend_NoDataInterpolatedForWeekend() { var op = new InterpolateMissingDatesOperator(); var friday = new SimplePrice( new DateTime( 2011, 1, 7 ), 0 ); var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 0 ); var input = new PriceSeries( SeriesIdentifier.Null, new[] { friday, monday } ); var series = op.Apply( input ); Assert.That( series, Is.EquivalentTo( input ) ); }
public void Apply_DayMissing_DataFromDayBeforeIsTaken() { var op = new InterpolateMissingDatesOperator(); var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 123 ); var weddnesday = new SimplePrice( new DateTime( 2011, 1, 12 ), 456 ); var input = new PriceSeries( SeriesIdentifier.Null, new[] { monday, weddnesday } ); var series = op.Apply( input ); Assert.That( series[ 1 ].Value, Is.EqualTo( 123 ) ); }
public void Apply_LessOrEqualPointsThanMax_SeriesRemainsUnchanged() { var op = new ReducePointsOperator( 2 ); var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 12 ); var thuesday = new SimplePrice( new DateTime( 2011, 1, 11 ), 23 ); var input = new PriceSeries( SeriesIdentifier.Null, new[] { monday, thuesday } ); var series = op.Apply( input ); Assert.That( series, Is.EquivalentTo( input ) ); }
public PricePaneModel(Context context, PriceSeries prices) : base(context, PRICES, "$0.0000", true) { var stockPrices = new OhlcDataSeries <DateTime, double> { SeriesName = "EUR/USD" }; stockPrices.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData); AddRenderableSeries(new FastCandlestickRenderableSeries { DataSeries = stockPrices, YAxisId = PRICES }); var maLow = new XyDataSeries <DateTime, double> { SeriesName = "Low Line" }; maLow.Append(prices.TimeData, prices.CloseData.MovingAverage(50)); AddRenderableSeries(new FastLineRenderableSeries { DataSeries = maLow, StrokeStyle = new SolidPenStyle(0xFFFF3333, 1f.ToDip(context)), YAxisId = PRICES }); var maHigh = new XyDataSeries <DateTime, double> { SeriesName = "High Line" }; maHigh.Append(prices.TimeData, prices.CloseData.MovingAverage(200)); AddRenderableSeries(new FastLineRenderableSeries { DataSeries = maHigh, StrokeStyle = new SolidPenStyle(0xFF33DD33, 1f.ToDip(context)), YAxisId = PRICES }); var priceMarker = new AxisMarkerAnnotation(context) { Y1 = (Java.Lang.IComparable)stockPrices.YValues.Get(stockPrices.Count - 1), YAxisId = PRICES }; priceMarker.SetBackgroundColor(0xFFFF3333.ToColor()); var maLowMarker = new AxisMarkerAnnotation(context) { Y1 = (Java.Lang.IComparable)maLow.YValues.Get(maLow.Count - 1), YAxisId = PRICES }; maLowMarker.SetBackgroundColor(0xFFFF3333.ToColor()); var maHighMarker = new AxisMarkerAnnotation(context) { Y1 = (Java.Lang.IComparable)maHigh.YValues.Get(maHigh.Count - 1), YAxisId = PRICES }; maHighMarker.SetBackgroundColor(0xFF33DD33.ToColor()); Annotations.Add(priceMarker); Annotations.Add(maLowMarker); Annotations.Add(maHighMarker); }
public void Apply_NoDatesMissing_SeriesRemainsUnchanged() { var op = new InterpolateMissingDatesOperator(); var monday = new SimplePrice(new DateTime(2011, 1, 10), 12); var thuesday = new SimplePrice(new DateTime(2011, 1, 11), 23); var weddnesday = new SimplePrice(new DateTime(2011, 1, 12), 34); var input = new PriceSeries(SeriesIdentifier.Null, new[] { monday, thuesday, weddnesday }); var series = op.Apply(input); Assert.That(series, Is.EquivalentTo(input)); }
public IPriceSeries Apply(IPriceSeries series) { if (!series.Any()) { return(series); } var descriptor = new ObjectDescriptor("InterpolatedMissingDates"); var seriesId = series.Identifier.Modify(descriptor); return(PriceSeries.FromSortedSet(seriesId, FillMissingDates(series))); }
public void Apply_NoDatesMissing_SeriesRemainsUnchanged() { var op = new InterpolateMissingDatesOperator(); var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 12 ); var thuesday = new SimplePrice( new DateTime( 2011, 1, 11 ), 23 ); var weddnesday = new SimplePrice( new DateTime( 2011, 1, 12 ), 34 ); var input = new PriceSeries( SeriesIdentifier.Null, new[] { monday, thuesday, weddnesday } ); var series = op.Apply( input ); Assert.That( series, Is.EquivalentTo( input ) ); }
public IPriceSeries Apply(IPriceSeries series) { double groupInterval = (double)series.Count / (double)myMaxPoints; if (groupInterval <= 1) { return(series); } var descriptor = new ObjectDescriptor("ThinOut", ObjectDescriptor.Param("MaxCount", myMaxPoints)); var seriesId = series.Identifier.Modify(descriptor); return(PriceSeries.FromSortedSet(seriesId, GroupPointsByAverage(series, (int)Math.Ceiling(groupInterval)))); }
public void Apply_MorePointsThanMax_DataGroupedByAverage() { var op = new ReducePointsOperator( 2 ); var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 10 ); var thuesday = new SimplePrice( new DateTime( 2011, 1, 11 ), 20 ); var weddnesday = new SimplePrice( new DateTime( 2011, 1, 12 ), 30 ); var input = new PriceSeries( SeriesIdentifier.Null, new[] { monday, thuesday, weddnesday } ); var series = op.Apply( input ); Assert.That( series.Count, Is.EqualTo( 2 ) ); Assert.That( series[ 0 ].Value, Is.EqualTo( 15 ) ); Assert.That( series[ 1 ].Value, Is.EqualTo( 30 ) ); }
public void Apply_MorePointsThanMax_DataGroupedByAverage() { var op = new ReducePointsOperator(2); var monday = new SimplePrice(new DateTime(2011, 1, 10), 10); var thuesday = new SimplePrice(new DateTime(2011, 1, 11), 20); var weddnesday = new SimplePrice(new DateTime(2011, 1, 12), 30); var input = new PriceSeries(SeriesIdentifier.Null, new[] { monday, thuesday, weddnesday }); var series = op.Apply(input); Assert.That(series.Count, Is.EqualTo(2)); Assert.That(series[0].Value, Is.EqualTo(15)); Assert.That(series[1].Value, Is.EqualTo(30)); }
public VolumePaneModel(Context context, PriceSeries prices) : base(context, VOLUME, "###E+0", false) { var volumePrices = new XyDataSeries <DateTime, double> { SeriesName = "Volume" }; volumePrices.Append(prices.TimeData, prices.VolumeData.Select(x => (double)x)); AddRenderableSeries(new FastColumnRenderableSeries { DataSeries = volumePrices, YAxisId = VOLUME }); Annotations.Add(new AxisMarkerAnnotation(context) { Y1 = (Java.Lang.IComparable)volumePrices.YValues.Get(volumePrices.Count - 1), YAxisId = VOLUME }); }
public RsiPaneViewModel(CreateMultiPaneStockChartsViewModel parentViewModel, PriceSeries prices) : base(parentViewModel) { var rsiSeries = new XyDataSeries <DateTime, double>() { SeriesName = "RSI" }; rsiSeries.Append(prices.TimeData, prices.Rsi(14)); ChartSeriesViewModels.Add(new LineRenderableSeriesViewModel { DataSeries = rsiSeries }); YAxisTextFormatting = "0.0"; Height = 100; }
public RsiPaneModel(Context context, PriceSeries prices) : base(context, RSI, "0.0", false) { var rsiSeries = new XyDataSeries <DateTime, double> { SeriesName = "RSI" }; var xData = prices.TimeData; var yData = prices.Rsi(14); rsiSeries.Append(xData, yData); AddRenderableSeries(new FastLineRenderableSeries { DataSeries = rsiSeries, YAxisId = RSI }); Annotations.Add(new AxisMarkerAnnotation(context) { Y1 = (Java.Lang.IComparable)rsiSeries.YValues.Get(rsiSeries.Count - 1), YAxisId = RSI }); }
public PriceSeries GetPriceData(string dataset) { if (_dataSets.ContainsKey(dataset)) { return(_dataSets[dataset]); } // e.g. resource format: Abt.Controls.SciChart.Example.Resources.EURUSD_Daily.csv var csvResource = string.Format("{0}.{1}", ResourceDirectory, Path.ChangeExtension(dataset, "csv")); var priceSeries = new PriceSeries(); priceSeries.Symbol = dataset; var assembly = typeof(DataManager).Assembly; // Debug.WriteLine(string.Join(", ", assembly.GetManifestResourceNames())); using (var stream = assembly.GetManifestResourceStream(csvResource)) using (var streamReader = new StreamReader(stream)) { string line = streamReader.ReadLine(); while (line != null) { var priceBar = new PriceBar(); // Line Format: // Date, Open, High, Low, Close, Volume // 2007.07.02 03:30, 1.35310, 1.35310, 1.35280, 1.35310, 12 var tokens = line.Split(','); priceBar.DateTime = DateTime.Parse(tokens[0], DateTimeFormatInfo.InvariantInfo); priceBar.Open = double.Parse(tokens[1], NumberFormatInfo.InvariantInfo); priceBar.High = double.Parse(tokens[2], NumberFormatInfo.InvariantInfo); priceBar.Low = double.Parse(tokens[3], NumberFormatInfo.InvariantInfo); priceBar.Close = double.Parse(tokens[4], NumberFormatInfo.InvariantInfo); priceBar.Volume = long.Parse(tokens[5], NumberFormatInfo.InvariantInfo); priceSeries.Add(priceBar); line = streamReader.ReadLine(); } } _dataSets.Add(dataset, priceSeries); return(priceSeries); }
private void UpdatePriceChart(PriceSeries priceData) { // Create a new series and append Open, High, Low, Close data _ohlcDataSeries = new OhlcDataSeries <DateTime, double>(); _ohlcDataSeries.Append(priceData.TimeData, priceData.OpenData, priceData.HighData, priceData.LowData, priceData.CloseData); PriceData = (IOhlcDataSeries <DateTime, double>)(UseDiscontinuousDateTimeAxis ? _ohlcDataSeries.ToDiscontinuousSeries(Calendar) : _ohlcDataSeries); PriceData.SeriesName = priceData.Symbol; // Create a series for the 200 period SMA which will be plotted as a line chart Sma200Series = (IXyDataSeries <DateTime, double>)PriceData.ToMovingAverage(200); Sma200Series.SeriesName = "200 SMA"; // Create a series for the 50 period SMA which will be plotted as a line chart Sma50Series = (IXyDataSeries <DateTime, double>)PriceData.ToMovingAverage(50); Sma50Series.SeriesName = "50 SMA"; // Update the chart type and timeframe with current settings UpdateChartType(_chartType); }
public RsiPaneModel(PriceSeries prices) : base(RSI, "%.1f", false) { var rsiSeries = new XyDataSeries <DateTime, double> { SeriesName = "RSI" }; var xData = prices.TimeData; var yData = prices.Rsi(14); rsiSeries.Append(xData, yData); AddRenderableSeries(new SCIFastLineRenderableSeries { DataSeries = rsiSeries, YAxisId = RSI, StrokeStyle = new SCISolidPenStyle(0xFFC6E6FF, 1f) }); Annotations.Add(new SCIAxisMarkerAnnotation { Position = rsiSeries.YValues.ValueAt(rsiSeries.Count - 1).ToComparable(), YAxisId = RSI }); }
private double SyncedCorrelation(PriceSeries inputSeries1, SyncedDataSeries inputSeries2, int corrPeriod) // SyncedCorrelation: Calculates the Pearson Product Moment Correlation of 2 Data Series, using only the bars which are synchronized // Note: Correlations may differ from Excel if NinjaTrader is set to dividend-adjust historical prices // // Inputs: // inputSeries1: 1st DataSeries, typically Closes[x] // inputSeries2: SyncedDataSeries, synced to InputSeries1; some bars (flagged by BoolSeries "Synced") hold valid (synchronized) values // corrPeriod: Period for Correlation calculation; there must be >= CorrPeriod synced bars in the input series, or it will throw an exception // { double sum1 = 0; double sum2 = 0; double sum3 = 0; int index1 = 0; double mean1, mean2, variance1, variance2, denominator; mean1 = SyncedSMA(inputSeries1, inputSeries2.Synced, corrPeriod); mean2 = SyncedSMA(inputSeries2, inputSeries2.Synced, corrPeriod); for (int counter = 0; counter < corrPeriod; counter++) { while (!inputSeries2.Synced[index1]) //Find next synced Bar { index1++; } variance1 = inputSeries1[index1] - mean1; variance2 = inputSeries2[index1] - mean2; sum1 += variance1 * variance2; sum2 += variance1 * variance1; sum3 += variance2 * variance2; index1++; } denominator = Math.Sqrt(sum2 * sum3); if (denominator == 0) { return(0); // avoid divide-by-zero error; not really the correct result (actual correlation is undefined) } else { return(sum1 / denominator); } }
public VolumePaneModel(PriceSeries prices) : base(VOLUME, "###E+0", false) { var volumePrices = new XyDataSeries <DateTime, double> { SeriesName = "Volume" }; volumePrices.Append(prices.TimeData, prices.VolumeData.Select(x => (double)x)); AddRenderableSeries(new SCIFastColumnRenderableSeries { DataSeries = volumePrices, YAxisId = VOLUME, FillBrushStyle = new SCISolidBrushStyle(UIColor.White), StrokeStyle = new SCISolidPenStyle(UIColor.White, 1f) }); Annotations.Add(new SCIAxisMarkerAnnotation { Position = volumePrices.YValues.ValueAt(volumePrices.Count - 1).ToComparable(), YAxisId = VOLUME, }); }
public MacdPaneModel(PriceSeries prices) : base(MACD, "%.2f", false) { var macdPoints = prices.CloseData.Macd(12, 25, 9); var histogramSeries = new XyDataSeries <DateTime, double> { SeriesName = "Histogram" }; histogramSeries.Append(prices.TimeData, macdPoints.Select(x => x.Divergence)); AddRenderableSeries(new SCIFastColumnRenderableSeries { DataSeries = histogramSeries, YAxisId = MACD, StrokeStyle = new SCISolidPenStyle(UIColor.White, 1f) }); var macdSeries = new XyyDataSeries <DateTime, double> { SeriesName = "MACD" }; macdSeries.Append(prices.TimeData, macdPoints.Select(x => x.Macd), macdPoints.Select(x => x.Signal)); AddRenderableSeries(new SCIFastBandRenderableSeries { DataSeries = macdSeries, YAxisId = MACD, FillBrushStyle = new SCISolidBrushStyle(UIColor.Clear), StrokeStyle = new SCISolidPenStyle(0xffe26565, 1f), FillY1BrushStyle = new SCISolidBrushStyle(UIColor.Clear), StrokeY1Style = new SCISolidPenStyle(0xff52cc54, 1f) }); Annotations.Add(new SCIAxisMarkerAnnotation { Position = histogramSeries.YValues.ValueAt(histogramSeries.Count - 1).ToComparable(), YAxisId = MACD }); Annotations.Add(new SCIAxisMarkerAnnotation { Position = macdSeries.YValues.ValueAt(macdSeries.Count - 1).ToComparable(), YAxisId = MACD }); }
private void UpdateChartData(BarStyle barStyle) { PriceSeries priceData = null; switch (barStyle) { case BarStyle.TimeBar: priceData = TicksAggregator.GetPriceDataByTimeFrame(_ticks, _selectedTimeFrame, _calendar, out _min, out _max); break; case BarStyle.VolumeBar: priceData = TicksAggregator.GetPriceDataByVolume(_ticks, _selectedVolume, _calendar, _barTimeFrame, out _min, out _max); break; case BarStyle.RangeBar: priceData = TicksAggregator.GetPriceDataByRange(_ticks, _selectedRange, _calendar, _barTimeFrame, out _min, out _max); break; } UpdatePriceChart(priceData); _priceSeries.InvalidateParentSurface(RangeMode.ZoomToFit); }
public void SavePrices(IEnumerable <PriceParserResult> priceData) { var dateNow = DateTime.Now; var priceSeries = new List <PriceSeries>(); var dbPriceDetails = priceRepository.GetPriceDetails(); foreach (var price in priceData) { var priceSerie = new PriceSeries(); priceSerie.CreatedDate = dateNow; priceSerie.ParserId = price.ParserConfigId; priceSerie.Price = price.Price; var existingPriceDetail = dbPriceDetails .Where(pd => pd.RetailerNo == price.ProductNo) .OrderByDescending(pd => pd.Id) .FirstOrDefault(); if (existingPriceDetail == null) { var priceDetailsItem = new PriceDetails(); priceDetailsItem.Title = price.Title; priceDetailsItem.RetailerNo = price.ProductNo; priceDetailsItem.CreatedDate = dateNow; priceRepository.SavePriceDetails(priceDetailsItem); existingPriceDetail = priceDetailsItem; } priceSerie.PriceDetailsId = existingPriceDetail.Id; priceSeries.Add(priceSerie); } priceRepository.SavePrices(priceSeries); }
private void UpdatePriceChart(AggregationPriceChart barStyle) { switch (barStyle) { case AggregationPriceChart.Count: PriceSeries = (IOhlcDataSeries <DateTime, double>)_priceData.AggregateByCount(_selectedCount); break; case AggregationPriceChart.Time: PriceSeries = (IOhlcDataSeries <DateTime, double>)_priceData.AggregateByTime(TimeSpan.FromMinutes(_selectedTimeFrame)); break; case AggregationPriceChart.Volume: PriceSeries = (IOhlcDataSeries <DateTime, double>)_priceData.AggregateByVolume(_ticks.Select(x => x.Volume.ToDouble()).ToList(), _selectedVolume); break; case AggregationPriceChart.Range: PriceSeries = (IOhlcDataSeries <DateTime, double>)_priceData.AggregateByRange(_selectedRange); break; case AggregationPriceChart.Renko: PriceSeries = (IOhlcDataSeries <DateTime, double>)_priceData.AggregateByRenko(_selectedBrickSize); break; } PriceSeries.SeriesName = "PriceData"; // Create a series for the 200 period SMA which will be plotted as a line chart Sma200Series = (IXyDataSeries <DateTime, double>)PriceSeries.ToMovingAverage(200); Sma200Series.SeriesName = "200 SMA"; // Create a series for the 50 period SMA which will be plotted as a line chart Sma50Series = (IXyDataSeries <DateTime, double>)PriceSeries.ToMovingAverage(50); Sma50Series.SeriesName = "50 SMA"; _priceSeries.InvalidateParentSurface(RangeMode.ZoomToFit); }
private void UpdatePriceChart(PriceSeries priceData) { // Create a new series and append Open, High, Low, Close data this.PriceData = new OhlcDataSeries <DateTime, double>(); PriceData.SeriesName = priceData.Symbol; PriceData.Append(priceData.TimeData, priceData.OpenData, priceData.HighData, priceData.LowData, priceData.CloseData); // Create a series for the 200 period SMA which will be plotted as a line chart Sma200Series = new XyDataSeries <DateTime, double>(); Sma200Series.SeriesName = "200 SMA"; var ma200 = DataManager.Instance.ComputeMovingAverage(priceData.CloseData, 200); Sma200Series.Append(priceData.TimeData, ma200); // Create a series for the 50 period SMA which will be plotted as a line chart Sma50Series = new XyDataSeries <DateTime, double>(); Sma50Series.SeriesName = "50 SMA"; var ma50 = DataManager.Instance.ComputeMovingAverage(priceData.CloseData, 50); Sma50Series.Append(priceData.TimeData, ma50); // Update the chart type and timeframe with current settings UpdateChartType(_chartType); }
private double SyncedResidualCorrelation(PriceSeries inputSeries1, SyncedDataSeries inputSeries2, int corrPeriod) // Correlation of residuals (residual = error = difference between actual values and linear regression line) { int index1 = 0; double[] residualArray1 = new double[corrPeriod]; double[] residualArray2 = new double[corrPeriod]; double[] dataArray1 = new double[corrPeriod]; double[] dataArray2 = new double[corrPeriod]; for (int counter = corrPeriod - 1; counter >= 0; counter--) { while (!inputSeries2.Synced[index1]) //Find next synced Bar { index1++; } dataArray1[counter] = inputSeries1[index1]; dataArray2[counter] = inputSeries2[index1]; index1++; } KDResidual(dataArray1, corrPeriod, residualArray1); KDResidual(dataArray2, corrPeriod, residualArray2); // return(KDRankCorrelation(residualArray1,residualArray2,corrPeriod)); // maybe rank correlation of residuals would be better? return(KDCorrelation(residualArray1, residualArray2, corrPeriod)); }
private PriceBar Next(PriceSeries priceSeries) { return priceSeries[_currentIndex++]; }
public PriceSeries GetRandomTrades(out List<Trade> trades, out List<NewsEvent> news) { var priceSeries = new PriceSeries(); trades = new List<Trade>(); news = new List<NewsEvent>(); var startDate = new DateTime(2012, 01, 01); double randomWalk = 0.0; // Note: Change the value below to increase or decrease the point count and trade frequency const int Count = 1000; const uint TradeFrequency = 14; // Generate the X,Y data with sequential dates on the X-Axis and slightly positively biased random walk on the Y-Axis for (int i = 0; i < Count; i++) { randomWalk += (_random.NextDouble() - 0.498); priceSeries.Add(new PriceBar(startDate.AddMinutes(i*10), randomWalk, randomWalk, randomWalk, randomWalk, 0)); } // The random walk is a truly random series, so it may contain negative values. Here we find the minimum and offset it // so it is always positive. double yOffset = -priceSeries.CloseData.Min() + _random.NextDouble(); for (int i = 0; i < Count; i++) { // Now update with the offset so it is never negative priceSeries[i].Close += yOffset; // Every N'th tick create a random trade if (i % TradeFrequency == 0) { var trade = new Trade(); // randomize buy or sell trade.BuySell = _random.NextDouble() > 0.48 ? BuySell.Buy : BuySell.Sell; // Set dealprice and date trade.DealPrice = priceSeries[i].Close; trade.TradeDate = priceSeries[i].DateTime; // Set instrument and quantity trade.Instrument = Instrument.CrudeOil; trade.Quantity = _random.Next(100, 500); trades.Add(trade); } // Every N'th tick create a random news event if (_random.Next(0, 99) > 95) { var newsEvent = new NewsEvent(); newsEvent.EventDate = priceSeries[i].DateTime; newsEvent.Headline = "OPEC meeting minutes"; newsEvent.Body = "The Organization of the Petroleum Exporting Countries voted today to increase production of Crude oil from its member states"; news.Add(newsEvent); } } return priceSeries; }
public PriceSeries GetPriceData(string dataset) { if (_dataSets.ContainsKey(dataset)) { return _dataSets[dataset]; } // e.g. resource format: Abt.Controls.SciChart.Example.Resources.EURUSD_Daily.csv var csvResource = string.Format("{0}.{1}", ResourceDirectory, Path.ChangeExtension(dataset, "csv")); var priceSeries = new PriceSeries(); priceSeries.Symbol = dataset; var assembly = typeof(DataManager).Assembly; // Debug.WriteLine(string.Join(", ", assembly.GetManifestResourceNames())); using (var stream = assembly.GetManifestResourceStream(csvResource)) using (var streamReader = new StreamReader(stream)) { string line = streamReader.ReadLine(); while (line != null) { var priceBar = new PriceBar(); // Line Format: // Date, Open, High, Low, Close, Volume // 2007.07.02 03:30, 1.35310, 1.35310, 1.35280, 1.35310, 12 var tokens = line.Split(','); priceBar.DateTime = DateTime.Parse(tokens[0], DateTimeFormatInfo.InvariantInfo); priceBar.Open = double.Parse(tokens[1], NumberFormatInfo.InvariantInfo); priceBar.High = double.Parse(tokens[2], NumberFormatInfo.InvariantInfo); priceBar.Low = double.Parse(tokens[3], NumberFormatInfo.InvariantInfo); priceBar.Close = double.Parse(tokens[4], NumberFormatInfo.InvariantInfo); priceBar.Volume = long.Parse(tokens[5], NumberFormatInfo.InvariantInfo); priceSeries.Add(priceBar); line = streamReader.ReadLine(); } } _dataSets.Add(dataset, priceSeries); return priceSeries; }