Пример #1
0
        private void LoadBricks(Symbol symbol)
        {
            var ticks = GetTicks(symbol);

            var decimals = (symbol == Symbol.USDJPY) ? Decimals.Three : Decimals.Five;

            var feed = new RenkoFeed(3.2, decimals);

            foreach (var tick in ticks)
            {
                feed.HandleTick(tick);
            }

            var dataSeries = new OhlcDataSeries <DateTime, double>();

            foreach (var brick in feed)
            {
                if (brick.Trend == Trend.Rising)
                {
                    dataSeries.Append(brick.OpenOn, brick.OpenRate,
                                      brick.CloseRate, brick.OpenRate, brick.CloseRate);
                }
                else
                {
                    dataSeries.Append(brick.OpenOn, brick.OpenRate,
                                      brick.OpenRate, brick.CloseRate, brick.CloseRate);
                }
            }

            chart.RenderableSeries[0].DataSeries = dataSeries;

            chart.ZoomExtents();
        }
        private void InitData(IMarketDataService marketDataService)
        {
            var prices = marketDataService.GetHistoricalData(DefaultPointCount);

            _lastPrice = prices.Last();

            // Populate data series with some data
            _ohlcDataSeries.Append(prices.Select(x => x.DateTime),
                                   prices.Select(x => x.Open),
                                   prices.Select(x => x.High),
                                   prices.Select(x => x.Low),
                                   prices.Select(x => x.Close));
            _xyDataSeries.Append(prices.Select(x => x.DateTime), prices.Select(y => _sma50.Push(y.Close).Current));
        }
Пример #3
0
        private void CandlesticksWithLines_Loaded(object sender, RoutedEventArgs e)
        {
            var dataSeries0 = new OhlcDataSeries <DateTime, double>();
            var dataSeries1 = new XyDataSeries <DateTime, long>();

            var viewModel = new CandlesViewModel();
            var prices    = viewModel.Prices;

            dataSeries0.Append(
                prices.TimeData,
                prices.OpenData,
                prices.HighData,
                prices.LowData,
                prices.CloseData
                );
            dataSeries1.Append(prices.TimeData, prices.VolumeData);
            sciChart.RenderableSeries[0].DataSeries = dataSeries0;
            sciChart.RenderableSeries[1].DataSeries = dataSeries1;
            int index = 0;

            foreach (var pattern in prices.Patterns)
            {
                if (pattern > 0)
                {
                    sciChart.Annotations.Add(new TextAnnotation()
                    {
                        Text = pattern.ToString(), X1 = prices.TimeData[index], Y1 = prices.OpenData[index], Background = Brushes.Blue
                    });
                }
                index++;
            }

            sciChart.ZoomExtents();
        }
Пример #4
0
        private void AddNewCandle(Candle candle, double?indicatorValue1, double?indicatorValue2, double?indicatorValue3)
        {
            using (ohlcSeries.SuspendUpdates())
                using (BBMiddleSeries.SuspendUpdates())
                    using (BBUpperSeries.SuspendUpdates())
                        using (BBLowerSeries.SuspendUpdates())
                        {
                            candlesCount++;
                            ohlcSeries.Append(candle.Time, (double)candle.Open, (double)candle.High, (double)candle.Low, (double)candle.Close);
                            StockChart.XAxis.VisibleRange = new IndexRange(candlesCount - 50, candlesCount);

                            if (indicatorValue1 != null)
                            {
                                BBMiddleSeries.Append(candle.Time, indicatorValue1.Value);
                            }
                            if (indicatorValue2 != null)
                            {
                                BBUpperSeries.Append(candle.Time, indicatorValue2.Value);
                            }
                            if (indicatorValue3 != null)
                            {
                                BBLowerSeries.Append(candle.Time, indicatorValue3.Value);
                            }
                        }
        }
Пример #5
0
        public void ModifyAxisPropertiesLoaded(object sender, EventArgs e)
        {
            using (sciChart.SuspendUpdates())
            {
                // Add a data series
                var dataSeries0 = new XyDataSeries <DateTime, double>();
                var dataSeries1 = new OhlcDataSeries <DateTime, double>();
                var dataSeries2 = new XyDataSeries <DateTime, double>();

                var dataSource = DataManager.Instance;

                // Prices are in the format Time, Open, High, Low, Close (all IList)
                var prices = dataSource.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);

                // Append data to series.
                dataSeries0.Append(prices.TimeData, dataSource.Offset(prices.LowData, -1000));
                dataSeries1.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData);
                dataSeries2.Append(prices.TimeData, dataSource.ComputeMovingAverage(prices.CloseData, 50));

                columnSeries.DataSeries = dataSeries0;
                ohlcSeries.DataSeries   = dataSeries1;
                lineSeries.DataSeries   = dataSeries2;

                sciChart.ZoomExtents();
            }
        }
Пример #6
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            using (sciChart.SuspendUpdates())
            {
                // Create some DataSeries of type x=DateTime, y=Double
                var dataSeries0 = new XyDataSeries <DateTime, double>();
                var dataSeries1 = new OhlcDataSeries <DateTime, double>();
                var dataSeries2 = new XyDataSeries <DateTime, double>();
                var dataSeries3 = new XyDataSeries <DateTime, double>();

                var dataSource = DataManager.Instance;

                // Prices are in the format Time, Open, High, Low, Close (all IList)
                var prices = dataSource.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);

                // Append data to series.
                dataSeries0.Append(prices.TimeData, dataSource.Offset(prices.LowData, -1000));
                dataSeries1.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData);
                dataSeries2.Append(prices.TimeData, dataSource.ComputeMovingAverage(prices.CloseData, 50));
                dataSeries3.Append(prices.TimeData, prices.VolumeData.Select(x => (double)x));

                // Assign data to RenderableSeries
                mountainSeries.DataSeries    = dataSeries0;
                candlestickSeries.DataSeries = dataSeries1;
                lineSeries.DataSeries        = dataSeries2;
                columnSeries.DataSeries      = dataSeries3;

                sciChart.ZoomExtents();
            }
        }
Пример #7
0
        protected override void InitExample()
        {
            var data = DataManager.Instance.GetPriceDataIndu();

            var dataSeries = new OhlcDataSeries <DateTime, double>();

            dataSeries.Append(data.TimeData, data.OpenData, data.HighData, data.LowData, data.CloseData);

            var xAxis = new CategoryDateAxis(Activity);
            var yAxis = new NumericAxis(Activity)
            {
                GrowBy = new DoubleRange(0, 0.1)
            };

            var rs = new FastCandlestickRenderableSeries
            {
                DataSeries         = dataSeries,
                StrokeUpStyle      = new PenStyle.Builder(Activity).WithColor(Color.Green).Build(),
                StrokeDownStyle    = new PenStyle.Builder(Activity).WithColor(Color.Red).Build(),
                FillUpBrushStyle   = new SolidBrushStyle(Color.Green),
                FillDownBrushStyle = new SolidBrushStyle(Color.Red)
            };

            Surface.XAxes.Add(xAxis);
            Surface.YAxes.Add(yAxis);
            Surface.RenderableSeries.Add(rs);

            Surface.ChartModifiers = new ChartModifierCollection()
            {
                new ZoomPanModifier(),
                new PinchZoomModifier(),
                new ZoomExtentsModifier(),
            };
        }
Пример #8
0
            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 CandlesticksWithLines_Loaded(object sender, RoutedEventArgs e)
        {
            // Create multiple DataSeries to store OHLC candlestick data, and Xy moving average data
            var dataSeries0 = new OhlcDataSeries <DateTime, double>();
            var dataSeries1 = new XyDataSeries <DateTime, double>();
            var dataSeries2 = new XyDataSeries <DateTime, double>();
            var dataSeries3 = new XyDataSeries <DateTime, double>();

            // Prices are in the format Time, Open, High, Low, Close (all IList)
            var prices = DataManager.Instance.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);

            // Append data to series.
            // First series is rendered as a Candlestick Chart so we append OHLC data
            dataSeries0.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData);

            // Subsequent series append moving average of the close prices
            dataSeries1.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 100));
            dataSeries2.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 50));
            dataSeries3.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 20));

            sciChart.RenderableSeries[0].DataSeries = dataSeries0;
            sciChart.RenderableSeries[1].DataSeries = dataSeries1;
            sciChart.RenderableSeries[2].DataSeries = dataSeries2;
            sciChart.RenderableSeries[3].DataSeries = dataSeries3;

            sciChart.ZoomExtents();
        }
        public HitTestDatapoints()
        {
            InitializeComponent();

            // Append some data
            var series0 = new XyDataSeries <double, double> {
                SeriesName = "Line Series"
            };

            series0.Append(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new double[] { 0, 0.1, 0.3, 0.5, 0.4, 0.35, 0.3, 0.25, 0.2, 0.1 });
            renderableLineSeries.DataSeries = series0;

            var series1 = new XyDataSeries <double, double> {
                SeriesName = "Column Series"
            };

            series1.Append(series0.XValues, series0.YValues.Select(x => x * 0.7));
            renderableColumnSeries.DataSeries = series1;

            var series2 = new OhlcDataSeries <double, double> {
                SeriesName = "Candlestick Series"
            };

            series2.Append(series0.XValues, series0.YValues.Select(x => x + 0.5), series0.YValues.Select(x => x + 1.0), series0.YValues.Select(x => x + 0.3), series0.YValues.Select(x => x + 0.7));
            renderableCandlestickSeries.DataSeries = series2;
        }
Пример #11
0
        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);
        }
Пример #12
0
        private void MouseWheelToZoomPan_Loaded(object sender, RoutedEventArgs e)
        {
            using (sciChart.SuspendUpdates())
            {
                // Create some dataseries of type x=DateTime, y=Double
                var dataSeries0 = new OhlcDataSeries <DateTime, double>();
                var dataSeries1 = new XyDataSeries <DateTime, double>();
                var dataSeries2 = new XyDataSeries <DateTime, double>();
                var dataSeries3 = new XyDataSeries <DateTime, double>();

                // Prices are in the format Time, Open, High, Low, Close (all IList)
                var prices = DataManager.Instance.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);

                // Append data to series.
                // First series is rendered as a Candlestick Chart so we append OHLC data
                dataSeries0.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData);

                // Subsequent series append moving average of the close prices
                dataSeries1.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 100));
                dataSeries2.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 50));
                dataSeries3.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 20));

                candlestickSeries.DataSeries = dataSeries0;
                lineSeries0.DataSeries       = dataSeries1;
                lineSeries1.DataSeries       = dataSeries2;
                lineSeries2.DataSeries       = dataSeries3;

                sciChart.ZoomExtents();
            }
        }
        private void ProcessCandles(string data)
        {
            List <Candle> list;
            Candles       candles;

            using (var reader = new StringReader(data))
            {
                list = new List <Candle>();
                var candleSerializer = new XmlSerializer(typeof(Candles));
                candles =
                    (Candles)
                    candleSerializer.Deserialize(reader);
                reader.Close();
            }
            //check if seccode matches
            if (candles.Seccode != Seccode)
            {
                return;
            }
            list = candles.Candle.Where(
                item =>
                item.TradeTime.Date >= DateTime.Today).ToList();

            if (list.Count == 0)
            {
                return;
            }
            OhlcDataSeries.Append(GetDateTime(list), GetValues(list));
            TXmlConnector.SendNewCandles -= ProcessCandles;
        }
        private IOhlcDataSeries GetPriceDataSeries()
        {
            var stockPrices = new OhlcDataSeries <DateTime, double>();

            var prices = DataManager.Instance.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);

            stockPrices.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData);

            return(stockPrices);
        }
Пример #15
0
        private void SetupRenderableSeries()
        {
            var dataManager = DataManager.Instance;
            var priceBars   = dataManager.GetPriceDataIndu();

            var mountainDataSeries = new XyDataSeries <double, double> {
                SeriesName = "Mountain Series"
            };
            var lineDataSeries = new XyDataSeries <double, double> {
                SeriesName = "Line Series"
            };
            var columnDataSeries = new XyDataSeries <double, long> {
                SeriesName = "Column Series"
            };
            var candlestickDataSeries = new OhlcDataSeries <double, double> {
                SeriesName = "Candlestick Series"
            };

            var xValues = Enumerable.Range(0, priceBars.Count).Select(x => (double)x).ToArray();

            mountainDataSeries.Append(xValues, priceBars.LowData.Select(x => x - 1000d));
            lineDataSeries.Append(xValues, dataManager.ComputeMovingAverage(priceBars.CloseData, 50));
            columnDataSeries.Append(xValues, priceBars.VolumeData);
            candlestickDataSeries.Append(xValues, priceBars.OpenData, priceBars.HighData, priceBars.LowData, priceBars.CloseData);

            var mountainRenderableSeries = new SCIFastMountainRenderableSeries {
                DataSeries = mountainDataSeries, YAxisId = "PrimaryAxisId"
            };
            var lineRenderableSeries = new SCIFastLineRenderableSeries {
                DataSeries = lineDataSeries, YAxisId = "PrimaryAxisId"
            };
            var columnRenderableSeries = new SCIFastColumnRenderableSeries {
                DataSeries = columnDataSeries, YAxisId = "SecondaryAxisId"
            };
            var candlestickRenderableSeries = new SCIFastCandlestickRenderableSeries {
                DataSeries = candlestickDataSeries, YAxisId = "PrimaryAxisId"
            };

            using (Surface.SuspendUpdates())
            {
                Surface.RenderableSeries.Add(mountainRenderableSeries);
                Surface.RenderableSeries.Add(lineRenderableSeries);
                Surface.RenderableSeries.Add(columnRenderableSeries);
                Surface.RenderableSeries.Add(candlestickRenderableSeries);
                Surface.ChartModifiers = new SCIChartModifierCollection
                {
                    new SCILegendModifier {
                        ShowCheckBoxes = false
                    },
                    new SCICursorModifier(),
                    new SCIZoomExtentsModifier()
                };
            }
        }
Пример #16
0
            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);
            }
Пример #17
0
        public static void SetChartViewModelPriceData(IList <Candle> candles, ChartViewModel cvm)
        {
            var priceDataSeries = new OhlcDataSeries <DateTime, double>();
            var xvalues         = new List <DateTime>();
            var openValues      = new List <double>();
            var highValues      = new List <double>();
            var lowValues       = new List <double>();
            var closeValues     = new List <double>();

            var atr = new AverageTrueRange();

            for (var i = 0; i < candles.Count; i++)
            {
                var time = new DateTime(candles[i].CloseTimeTicks, DateTimeKind.Utc).ToLocalTime();

                xvalues.Add(time);
                openValues.Add((double)candles[i].OpenBid);
                highValues.Add((double)candles[i].HighBid);
                lowValues.Add((double)candles[i].LowBid);
                closeValues.Add((double)candles[i].CloseBid);
            }

            priceDataSeries.Append(xvalues, openValues, highValues, lowValues, closeValues);
            priceDataSeries.SeriesName = "Price";

            var pricePaneVm = cvm.ChartPaneViewModels.Count > 0 ? cvm.ChartPaneViewModels[0] : null;
            var atrPaneVm   = cvm.ChartPaneViewModels.Count > 1 ? cvm.ChartPaneViewModels[1] : null;

            if (pricePaneVm == null)
            {
                pricePaneVm = new ChartPaneViewModel(cvm, cvm.ViewportManager)
                {
                    IsFirstChartPane = true,
                    IsLastChartPane  = false
                };

                var series = new FastCandlestickRenderableSeries {
                    AntiAliasing = false
                };
                series.SetValue(FilteringLegendModifier.IncludeSeriesProperty, false);
                series.SeriesColor = Colors.DarkBlue;
                pricePaneVm.ChartSeriesViewModels.Add(new ChartSeriesViewModel(priceDataSeries, series));
                cvm.ChartPaneViewModels.Add(pricePaneVm);
            }
            else
            {
                pricePaneVm.ChartSeriesViewModels.Clear();
                var renderableSeries = new FastCandlestickRenderableSeries {
                    AntiAliasing = false
                };
                renderableSeries.SetValue(FilteringLegendModifier.IncludeSeriesProperty, false);
                pricePaneVm.ChartSeriesViewModels.Add(new ChartSeriesViewModel(priceDataSeries, renderableSeries));
            }
        }
        void InteractionWithAnnotationsLoaded(object sender, RoutedEventArgs e)
        {
            var series = new OhlcDataSeries <DateTime, double>();

            var marketDataService = new MarketDataService(DateTime.Now, 5, 5);
            var data = marketDataService.GetHistoricalData(200);

            series.Append(data.Select(x => x.DateTime), data.Select(x => x.Open), data.Select(x => x.High), data.Select(x => x.Low), data.Select(x => x.Close));

            sciChart.RenderableSeries[0].DataSeries = series;
        }
        private static IOhlcDataSeries <double, double> GetOhlcDataSeries(IEnumerable <double> data)
        {
            var dataSeries = new OhlcDataSeries <double, double>();

            dataSeries.Append(data,
                              data.Select(x => x + 2.4),
                              data.Select(x => x + 4.9),
                              data.Select(x => x - 5.3),
                              data.Select(x => x - 2.7));

            return(dataSeries);
        }
Пример #20
0
        private void AddNewCandle(Candle candle, decimal indicator)
        {
            using (dataSeries.SuspendUpdates())
                using (ohlcSeries.SuspendUpdates())
                {
                    ohlcSeries.Append(candle.Time, (double)candle.Open, (double)candle.High, (double)candle.Low, (double)candle.Close);
                    dataSeries.Append(candle.Time, (double)indicator);
                    candleCount++;

                    StockChart.XAxis.VisibleRange    = new IndexRange(candleCount - 50, candleCount);
                    indicatorChar.XAxis.VisibleRange = new IndexRange(candleCount - 50, candleCount);
                }
        }
        void CreateAnnotationsDynamicallyLoaded(object sender, RoutedEventArgs e)
        {
            var dataSeries = new OhlcDataSeries <DateTime, double>();

            var marketDataService = new MarketDataService(DateTime.Now, 5, 5);
            var data = marketDataService.GetHistoricalData(200);

            dataSeries.Append(data.Select(x => x.DateTime), data.Select(x => x.Open), data.Select(x => x.High), data.Select(x => x.Low), data.Select(x => x.Close));

            sciChart.RenderableSeries[0].DataSeries = dataSeries;
            pointerButton.IsChecked     = true;
            AnnotationTypes.ItemsSource = _annotationTypes.Keys;
        }
Пример #22
0
 private void AddNewCandle(Candle candle, decimal indicator)
 {
     using (macdDataSeries.SuspendUpdates())
         using (dataSeries.SuspendUpdates())
             using (ohlcSeries.SuspendUpdates())
             {
                 ohlcSeries.Append(candle.Time, (double)candle.Open, (double)candle.High, (double)candle.Low, (double)candle.Close);
                 macdDataSeries.Append(candle.Time, macdPoints[candleCount].Macd, macdPoints[candleCount].Signal);
                 candleCount++;
                 dataSeries.Append(candle.Time, (double)Monitor.Indicator.Calculate(candle));
                 StockChart.XAxis.VisibleRange    = new IndexRange(candleCount - 50, candleCount);
                 indicatorChar.XAxis.VisibleRange = new IndexRange(candleCount - 50, candleCount);
             }
 }
        public PricePaneViewModel(CreateMultiPaneStockChartsViewModel parentViewModel, PriceSeries prices)
            : base(parentViewModel)
        {
            // We can add Series via the SeriesSource API, where SciStockChart or SciChartSurface bind to IEnumerable<IChartSeriesViewModel>
            // Alternatively, you can delcare your RenderableSeries in the SciStockChart and just bind to DataSeries
            // A third method (which we don't have an example for yet, but you can try out) is to create an Attached Behaviour to transform a collection of IDataSeries into IRenderableSeries

            // Add the main OHLC chart
            var stockPrices = new OhlcDataSeries <DateTime, double>()
            {
                SeriesName = "OHLC"
            };

            stockPrices.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData);
            ChartSeriesViewModels.Add(new CandlestickRenderableSeriesViewModel
            {
                DataSeries   = stockPrices,
                AntiAliasing = false,
            });

            // Add a moving average
            var maLow = new XyDataSeries <DateTime, double>()
            {
                SeriesName = "Low Line"
            };

            maLow.Append(prices.TimeData, prices.CloseData.MovingAverage(50));
            ChartSeriesViewModels.Add(new LineRenderableSeriesViewModel
            {
                DataSeries = maLow,
                StyleKey   = "LowLineStyle",
            });

            // Add a moving average
            var maHigh = new XyDataSeries <DateTime, double>()
            {
                SeriesName = "High Line"
            };

            maHigh.Append(prices.TimeData, prices.CloseData.MovingAverage(200));
            ChartSeriesViewModels.Add(new LineRenderableSeriesViewModel
            {
                DataSeries = maHigh,
                StyleKey   = "HighLineStyle",
            });

            YAxisTextFormatting = "$0.0000";
        }
        private void OnLoaded_SciChartSurface(object sender, RoutedEventArgs e)
        {
            // Create multiple DataSeries to store OHLC candlestick data, and Xy moving average data
            var dataSeries0 = new OhlcDataSeries <DateTime, double>()
            {
                SeriesName = "Candles"
            };
            var dataSeries1 = new XyDataSeries <DateTime, double>()
            {
                SeriesName = "Red"
            };
            var dataSeries2 = new XyDataSeries <DateTime, double>()
            {
                SeriesName = "Blue"
            };
            var dataSeries3 = new XyDataSeries <DateTime, double>()
            {
                SeriesName = "Yellow"
            };

            // Prices are in the format Time, Open, High, Low, Close (all IList)
            var prices = DataManager.Instance.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);

            // Append data to series.
            // First series is rendered as a Candlestick Chart so we append OHLC data
            dataSeries0.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData);

            // Subsequent series append moving average of the close prices
            dataSeries1.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 100));
            dataSeries2.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 50));
            dataSeries3.Append(prices.TimeData, DataManager.Instance.ComputeMovingAverage(prices.CloseData, 20));

            sciChart.RenderableSeries[0].DataSeries = dataSeries0;
            sciChart.RenderableSeries[1].DataSeries = dataSeries1;
            sciChart.RenderableSeries[2].DataSeries = dataSeries2;
            sciChart.RenderableSeries[3].DataSeries = dataSeries3;

            boxAnnotation.X1 = new DateTime(2011, 7, 21, 17, 2, 39);
            boxAnnotation.X2 = new DateTime(2011, 3, 16, 6, 44, 18);

            buyTxtAnnot.X1 = new DateTime(2011, 3, 14, 0, 24, 11);
            buyTxtAnnot.X2 = buyTxtAnnot.X1;

            sellTxtAnnot.X1 = new DateTime(2011, 7, 15, 21, 19, 28);
            sellTxtAnnot.X2 = sellTxtAnnot.X1;

            sciChart.ZoomExtents();
        }
Пример #25
0
        private void AddNewCandle(Candle candle, double?indicatorValue)
        {
            using (ohlcSeries.SuspendUpdates())
                using (sarSeries.SuspendUpdates())
                {
                    ohlcSeries.Append(candle.Time, (double)candle.Open, (double)candle.High, (double)candle.Low, (double)candle.Close);

                    if (indicatorValue != null)
                    {
                        sarSeries.Append(candle.Time, indicatorValue.Value);
                    }

                    candlesCount++;

                    StockChart.XAxis.VisibleRange = new IndexRange(candlesCount - 50, candlesCount);
                }
        }
Пример #26
0
        protected override void InitExample()
        {
            var priceSeries = DataManager.Instance.GetPriceDataIndu();

            var dataSeries = new OhlcDataSeries <DateTime, double>();

            dataSeries.Append(priceSeries.TimeData, priceSeries.OpenData, priceSeries.HighData, priceSeries.LowData, priceSeries.CloseData);

            var size  = priceSeries.Count;
            var xAxis = new CategoryDateAxis(Activity)
            {
                VisibleRange = new DoubleRange(size - 30, size), GrowBy = new DoubleRange(0, 0.1)
            };
            var yAxis = new NumericAxis(Activity)
            {
                GrowBy = new DoubleRange(0, 0.1), AutoRange = AutoRange.Always
            };

            var rSeries = new FastCandlestickRenderableSeries
            {
                DataSeries         = dataSeries,
                StrokeUpStyle      = new SolidPenStyle(0xFF00AA00, 1.ToDip(Activity)),
                StrokeDownStyle    = new SolidPenStyle(0xFFFF0000, 1.ToDip(Activity)),
                FillUpBrushStyle   = new SolidBrushStyle(0x8800AA00),
                FillDownBrushStyle = new SolidBrushStyle(0x88FF0000)
            };

            using (Surface.SuspendUpdates())
            {
                Surface.XAxes.Add(xAxis);
                Surface.YAxes.Add(yAxis);
                Surface.RenderableSeries.Add(rSeries);
                Surface.ChartModifiers = new ChartModifierCollection
                {
                    new ZoomPanModifier(),
                    new PinchZoomModifier(),
                    new ZoomExtentsModifier(),
                };

                new WaveAnimatorBuilder(rSeries)
                {
                    Interpolator = new DecelerateInterpolator(), Duration = 3000, StartDelay = 350
                }.Start();
            }
        }
Пример #27
0
        private void CreateSciTradeChartLoaded(object sender, RoutedEventArgs e)
        {
            var dataSeries = new OhlcDataSeries <DateTime, double>()
            {
                // Note: SeriesName is needed to display the legend correctly.
                SeriesName = "Price Data"
            };

            // Append price data
            var prices = DataManager.Instance.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);

            dataSeries.Append(prices.TimeData, prices.OpenData, prices.HighData, prices.LowData, prices.CloseData);

            // Set BarTimeFrame = 3600 seconds (time of one bar in the input data)
            StockChart.BarTimeFrame = TimeSpan.FromHours(1).TotalSeconds;

            StockChart.RenderableSeries[0].DataSeries = dataSeries;
        }
Пример #28
0
        protected override void InitExampleInternal()
        {
            Surface = new SCIChartSurface(_exampleViewLayout.SciChartSurfaceView);
            StyleHelper.SetSurfaceDefaultStyle(Surface);

            var data = DataManager.Instance.GetPriceDataIndu();

            var dataSeries = new OhlcDataSeries <DateTime, double>(TypeOfSeries.XCategory);

            dataSeries.Append(data.TimeData, data.OpenData, data.HighData, data.LowData, data.CloseData);

            var axisStyle = StyleHelper.GetDefaultAxisStyle();
            var xAxis     = new SCICategoryDateTimeAxis {
                IsXAxis = true, Style = axisStyle
            };
            var yAxis = new SCINumericAxis {
                GrowBy = new SCIDoubleRange(0.1, 0.1), Style = axisStyle
            };

            var renderSeries = new SCIFastCandlestickRenderableSeries
            {
                DataSeries = dataSeries,
                Style      =
                {
                    StrokeUpStyle      = new SCIPenSolid(UIColor.Green,    1f),
                    StrokeDownStyle    = new SCIPenSolid(UIColor.Red,      1f),
                    FillUpBrushStyle   = new SCIBrushSolid(UIColor.Green),
                    FillDownBrushStyle = new SCIBrushSolid(UIColor.Red)
                }
            };

            Surface.AttachAxis(xAxis, true);
            Surface.AttachAxis(yAxis, false);
            Surface.AttachRenderableSeries(renderSeries);

            Surface.ChartModifier = new SCIModifierGroup(new ISCIChartModifierProtocol[]
            {
                new SCIZoomPanModifier(),
                new SCIPinchZoomModifier(),
                new SCIZoomExtentsModifier()
            });

            Surface.InvalidateElement();
        }
Пример #29
0
        protected override void InitExample()
        {
            var priceSeries = DataManager.Instance.GetPriceDataIndu();

            var dataSeries = new OhlcDataSeries <DateTime, double>();

            dataSeries.Append(priceSeries.TimeData, priceSeries.OpenData, priceSeries.HighData, priceSeries.LowData, priceSeries.CloseData);

            var size  = priceSeries.Count;
            var xAxis = new SCICategoryDateTimeAxis {
                VisibleRange = new SCIDoubleRange(size - 30, size), GrowBy = new SCIDoubleRange(0, 0.1)
            };
            var yAxis = new SCINumericAxis {
                GrowBy = new SCIDoubleRange(0, 0.1), AutoRange = SCIAutoRange.Always
            };

            var renderSeries = new SCIFastCandlestickRenderableSeries
            {
                DataSeries         = dataSeries,
                StrokeUpStyle      = new SCISolidPenStyle(0xFF00AA00, 1f),
                StrokeDownStyle    = new SCISolidPenStyle(0xFFFF0000, 1f),
                FillUpBrushStyle   = new SCISolidBrushStyle(0x8800AA00),
                FillDownBrushStyle = new SCISolidBrushStyle(0x88FF0000)
            };

            var animation = new SCIWaveRenderableSeriesAnimation(3, SCIAnimationCurve.EaseOut);

            animation.StartAfterDelay(0.3f);
            renderSeries.AddAnimation(animation);

            using (Surface.SuspendUpdates())
            {
                Surface.XAxes.Add(xAxis);
                Surface.YAxes.Add(yAxis);
                Surface.RenderableSeries.Add(renderSeries);

                Surface.ChartModifiers = new SCIChartModifierCollection
                {
                    new SCIZoomPanModifier(),
                    new SCIPinchZoomModifier(),
                    new SCIZoomExtentsModifier()
                };
            }
        }
Пример #30
0
        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);
        }
Пример #31
0
        public ChartViewModel()
        {
            this.SetDefaults();

            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
                _marketDataService = new MarketDataService(new DateTime(2015, 08, 11), 1, 5000);
            }
            else
            {
                // Code runs "for real"
                _marketDataService = new MarketDataService(new DateTime(2015, 08, 11), 1, 1000);
            }

            var ds0 = new OhlcDataSeries<DateTime, double>();
            _seriesViewModels.Add(new ChartSeriesViewModel(ds0, new FastOhlcRenderableSeries() { Name = "Series1", XAxisId = "dateTimeXAxis", YAxisId = "Y1" }));
            // Append 500 historical bars to data series
            var prices = _marketDataService.GetHistoricalData(500);
            ds0.Append(
                prices.Select(x => x.DateTime),
                prices.Select(x => x.Open),
                prices.Select(x => x.High),
                prices.Select(x => x.Low),
                prices.Select(x => x.Close));

            //Create price/volume distribution
            double minPrice = prices.Select(x => x.Low).Min();
            double maxPrice = prices.Select(x => x.High).Max();

            int numBins = 5;
            double interval = (maxPrice - minPrice) / numBins;
            var bins = new Tuple<double, double>[numBins];
            double binLower = minPrice;
            for (int i = 0; i < numBins; i++)
            {
                bins[i] = new Tuple<double, double>(binLower, binLower + interval);
                binLower += interval;
            }

            var dsVolByPrice = new XyDataSeries<double, double>();
            _seriesViewModels.Add(new ChartSeriesViewModel(dsVolByPrice, new FastColumnRenderableSeries() { Name = "PriceByVol", XAxisId = "verticalXAxis", YAxisId = "Y2" }));

            var dblVolume = new List<double>();
            for (int i = 0; i < numBins; i++) dblVolume.Add(10 - i);

            dsVolByPrice.Append(bins.Select(x => x.Item1), dblVolume);

            _marketDataService.SubscribePriceUpdate(OnNewPrice);
            _xVisibleRange = new IndexRange(0, 1000);

            SelectedChartType = ChartType.FastOhlc;

            //this.DeleteCommand = new RelayCommand(DeleteCommandExecuted);
        }