コード例 #1
0
        public void AddOrUpdateIndicator(IndicatorEntry newEntry)
        {
            var existing = context.IndicatorEntries.FirstOrDefault(
                x => x.PriceEntryId == newEntry.PriceEntryId && x.Type == newEntry.Type);

            if (existing != null)
            {
                existing.Data = newEntry.Data;
            }
            else
            {
                context.IndicatorEntries.Add(newEntry);
            }
        }
コード例 #2
0
ファイル: RamBrowser.cs プロジェクト: skykying/traces
        private void _setBounds(int width, int height)
        {
            // Update width of the entire indicator axis
            // We have n indicators, each one separated by a 1 pixel line
            int indicatorDim = 0;

            foreach (var entry in _indicators)
            {
                indicatorDim += entry.Indicator.Dimension;
            }

            _indicatorAxisWidth = indicatorDim + _indicators.Count * 1;

            // Width and height of the border and axis
            // The border contains the ticks and text, the indicator axis and
            // a 2 pixel line separating the axis from the ram view
            _axisWidth  = _borderWidth + _indicatorAxisWidth + _innerLineWidth;
            _axisHeight = _borderHeight + _indicatorAxisWidth + _innerLineWidth;

            // We scale the plot only in units of major ticks to
            // always keep the axis frame consistent.
            _width  = width - ((width - _axisWidth * 2) % _majorTick);
            _height = height - ((height - _axisHeight * 2) % _majorTick);

            // The inner rectangle into which we will draw the ram
            // excluding the inner frame line
            _innerBounds = new Rectangle(_axisWidth, _axisHeight,
                                         _width - _axisWidth * 2, _height - _axisHeight * 2);

            // The outer rectangle that we take as basis for the tick
            // and text drawing. The rectangle does not include the outer
            // frame line.
            _outerBounds = new Rectangle(_borderWidth, _borderHeight,
                                         _width - _borderWidth * 2, _height - _borderHeight * 2);

            // Now, that we know the dimensions of the inner view, we can
            // update the bounds of the indicators.
            for (int i = 0; i < _indicators.Count; ++i)
            {
                IndicatorEntry e   = _indicators[i];
                int            dim = e.Indicator.Dimension;

                e.Indicator.SetBounds(_innerBounds.Width, _innerBounds.Height);

                e.TopBar = new Rectangle(_innerBounds.Left,
                                         _innerBounds.Top - _innerLineWidth - (dim * (i + 1)) - i,
                                         _innerBounds.Width, dim);

                e.BottomBar = new Rectangle(_innerBounds.Left,
                                            _innerBounds.Bottom + _innerLineWidth + (dim * i) + i,
                                            _innerBounds.Width, dim);

                e.LeftBar = new Rectangle(
                    _innerBounds.Left - _innerLineWidth - (dim * (i + 1)) - i,
                    _innerBounds.Top, dim, _innerBounds.Height);

                e.RightBar = new Rectangle(
                    _innerBounds.Right + _innerLineWidth + (dim * i) + i,
                    _innerBounds.Top, dim, _innerBounds.Height);

                e.Bounds = new Rectangle(e.LeftBar.Left, e.TopBar.Top,
                                         e.RightBar.Right - e.LeftBar.Left,
                                         e.BottomBar.Bottom - e.TopBar.Top);
            }

            if (_ramBitmap != null)
            {
                _ramBitmap.SetBounds(_innerBounds.Width, _innerBounds.Height);
            }

            _setupCanvas(width, height);
        }
コード例 #3
0
        public void UpdateIndicatorData(PriceEntry newPrice)
        {
            LoggerExtensions.LogInformation(logger, "PriceEntry Repo Updating Indicator Data for " + newPrice.BrokerInstrumentId + ", " + newPrice.TimeStamp);
            //var oldIndicatorData = Queryable.Where<IndicatorEntry>(context.IndicatorEntries, x => x.PriceEntry == newPrice);
            //if(oldIndicatorData !=null) context.IndicatorEntries.RemoveRange(oldIndicatorData);

            var prices = Queryable.Where <PriceEntry>(context.PriceEntries, x => x.BrokerInstrumentId == newPrice.BrokerInstrumentId &&
                                                      x.TimeIntervalId == newPrice.TimeIntervalId &&
                                                      x.TimeStamp <= newPrice.TimeStamp)
                         .OrderByDescending(t => t.TimeStamp)
                         .Take(78).ToList();

            if (prices.Count() < 52)
            {
                LoggerExtensions.LogInformation(logger, "PriceEntry Repo  " + newPrice.BrokerInstrumentId + "not enough history " + prices.Count());
                return;
            }
            var prices_at   = prices.Take(52);
            var prices_orig = prices;


            // Calculate all Indicators , should possibly be moved somewhere else

            // Span A, SpanB nach AT

            var highs = new List <decimal>(prices_at.Select(y => y.High));
            var lows  = new List <decimal>(prices_at.Select(y => y.Low));

            var temp9      = (highs.GetRange(0, 9).Max() + lows.GetRange(0, 9).Min()) / 2;
            var temp26     = (highs.GetRange(0, 26).Max() + lows.GetRange(0, 26).Min()) / 2;
            var spanb      = (highs.GetRange(0, 52).Max() + lows.GetRange(0, 52).Min()) / 2;
            var spana      = (temp9 + temp26) / 2;
            var entrySpanA = new IndicatorEntry {
                Data = spana, PriceEntryId = newPrice.Id, Type = IndicatorDataType.Wolke_SpanA, IsDirty = false
            };
            var entrySpanB = new IndicatorEntry {
                Data = spanb, PriceEntryId = newPrice.Id, Type = IndicatorDataType.Wolke_SpanB, IsDirty = false
            };

            prices_orig.RemoveRange(0, 26);
            if (prices_orig.Count() >= 52)
            {
                var highs_orig = new List <decimal>(prices_orig.Select(y => y.High));
                var lows_orig  = new List <decimal>(prices_orig.Select(y => y.Low));

                var temp9_orig  = (highs_orig.GetRange(0, 9).Max() + lows_orig.GetRange(0, 9).Min()) / 2;
                var temp26_orig = (highs_orig.GetRange(0, 26).Max() + lows_orig.GetRange(0, 26).Min()) / 2;
                var spanb_orig  = (highs_orig.GetRange(0, 52).Max() + lows_orig.GetRange(0, 52).Min()) / 2;
                var spana_orig  = (temp9_orig + temp26_orig) / 2;

                var entrySpanAorig = new IndicatorEntry
                {
                    Data         = spana_orig,
                    PriceEntryId = newPrice.Id,
                    Type         = IndicatorDataType.OrigWolke_SpanA,
                    IsDirty      = false
                };
                var entrySpanBorig = new IndicatorEntry
                {
                    Data         = spanb_orig,
                    PriceEntryId = newPrice.Id,
                    Type         = IndicatorDataType.OrigWolke_SpanB,
                    IsDirty      = false
                };
                AddOrUpdateIndicator(entrySpanAorig);
                AddOrUpdateIndicator(entrySpanBorig);
                LoggerExtensions.LogInformation(logger, "PriceEntry Repo  " + newPrice.BrokerInstrumentId + "orig Wolke added");
            }

            LoggerExtensions.LogInformation(logger, "PriceEntry Repo  " + newPrice.BrokerInstrumentId + "Wolke added");
            AddOrUpdateIndicator(entrySpanA);
            AddOrUpdateIndicator(entrySpanB);
        }