예제 #1
0
        internal void Update(Parameters parameters, ChartSettings settings, Quotes quotes)
        {
            if (m_grid.BackgroundColor != settings.BackgroundColor)
            {
                m_grid.BackgroundColor = settings.BackgroundColor;
            }
            Quote quote = quotes.Last.Quote;

            int count = (null == quote) ? 0 : settings.Lines.Count;

            Update(count);


            for (int index = 0; index < count; ++index)
            {
                LineSettings line        = settings.Lines[index];
                Color        volumeColor = CalculateColor(line.BidColor, line.AskColor, settings.ForegroundColor);
                Update(settings, index, 0, (float)line.Volume, volumeColor);

                double volume = line.Volume * parameters.LotSize;
                float? bid    = MathEx.CalculateWAVP(volume, quote.Bids);
                float? ask    = MathEx.CalculateWAVP(volume, quote.Asks);
                if (bid.HasValue)
                {
                    bid = (float)MathEx.RoundDown(bid.Value, parameters.PricePip);
                }
                if (ask.HasValue)
                {
                    ask = (float)MathEx.RoundUp(ask.Value, parameters.PricePip);
                }
                Update(settings, index, 1, bid, line.BidColor);
                Update(settings, index, 2, ask, line.AskColor);

                float?spread = null;
                if (bid.HasValue && ask.HasValue)
                {
                    spread = (float)Math.Round(parameters.PriceFactor * (ask.Value - bid.Value));
                }
                Color spreadColor = CalculateColor(line.BidColor, line.AskColor, settings.ForegroundColor);
                Update(settings, index, 3, spread, spreadColor);
            }
            Size size = m_grid.PreferredSize;

            if (this.Size != size)
            {
                this.Size = size;
            }
            //if (!this.Visible)
            //{
            //	this.Visible = true;
            //}
        }