Exemplo n.º 1
0
        private IInteractiveLine GetInteractiveLine(IGraphPane pane, IReadOnlyList <IDataBar> bars)
        {
            var minDate              = bars.First().Date;
            var maxDate              = bars.Last().Date;
            var interactiveLine      = (IInteractiveLine)pane.GetInteractiveObject(VariableId);
            var intColor             = ColorParser.Parse(Color);
            var firstMarketPosition  = new MarketPoint(FirstDateTime.Value, FirstValue.Value);
            var secondMarketPosition = new MarketPoint(SecondDateTime.Value, SecondValue.Value);

            if (interactiveLine != null)
            {
                interactiveLine.ExecutionDataBars = bars;
                CorrectMarketPointsEx(ref firstMarketPosition, ref secondMarketPosition, minDate, maxDate);

                if (interactiveLine.PaneSides == PaneSide && interactiveLine.Color == intColor && interactiveLine.Mode == Mode)
                {
                    pane.AddUnremovableInteractiveObjectId(VariableId);
                    interactiveLine.Thickness = Thickness;
                    interactiveLine.FirstPoint.MarketPosition  = firstMarketPosition;
                    interactiveLine.SecondPoint.MarketPosition = secondMarketPosition;
                    return(m_interactiveLine = interactiveLine);
                }
                pane.RemoveInteractiveObject(VariableId);
            }
            else
            {
                CorrectMarketPointsEx(ref firstMarketPosition, ref secondMarketPosition, minDate, maxDate);
            }

            m_interactiveLine                   = pane.AddInteractiveLine(VariableId, PaneSide, false, intColor, Mode, firstMarketPosition, secondMarketPosition);
            m_interactiveLine.Thickness         = Thickness;
            m_interactiveLine.ExecutionDataBars = bars;
            return(m_interactiveLine);
        }
Exemplo n.º 2
0
        private IList <double> GetLine(IGraphPane pane, IReadOnlyList <IDataBar> bars)
        {
            m_interactiveLine = null;
            if (bars == null || bars.Count == 0)
            {
                return(EmptyArrays.Double);
            }

            if (bars.Count == 1)
            {
                return(s_defaultResult1);
            }

            var interactiveLine = GetInteractiveLine(pane, bars);
            var firstPosition   = interactiveLine.FirstPoint.MarketPosition;
            var secondPosition  = interactiveLine.SecondPoint.MarketPosition;

            if (firstPosition.X == secondPosition.X)
            {
                return(new ConstList(double.NaN, bars.Count));
            }

            var firstBarIndex  = GetBarIndex(bars, firstPosition.X);
            var secondBarIndex = GetBarIndex(bars, secondPosition.X);

            if (firstBarIndex == null || secondBarIndex == null || firstBarIndex == secondBarIndex)
            {
                return(new ConstList(double.NaN, bars.Count));
            }

            var a = (secondPosition.Y - firstPosition.Y) / (secondBarIndex.Value - firstBarIndex.Value);
            var b = firstPosition.Y - a * firstBarIndex.Value;

            int minIndex;
            int maxIndex;

            switch (Mode)
            {
            case InteractiveLineMode.Finite:
                if (firstBarIndex < secondBarIndex)
                {
                    minIndex = firstBarIndex.Value;
                    maxIndex = secondBarIndex.Value;
                }
                else
                {
                    minIndex = secondBarIndex.Value;
                    maxIndex = firstBarIndex.Value;
                }
                break;

            case InteractiveLineMode.Infinite:
                minIndex = 0;
                maxIndex = bars.Count - 1;
                break;

            case InteractiveLineMode.Ray:
                if (firstBarIndex < secondBarIndex)
                {
                    minIndex = firstBarIndex.Value;
                    maxIndex = bars.Count - 1;
                }
                else
                {
                    minIndex = 0;
                    maxIndex = firstBarIndex.Value;
                }
                break;

            default:
                throw new InvalidOperationException();
            }
            return(a == 0 ? (IList <double>) new ConstList(b, bars.Count, minIndex, maxIndex) : new LineList(a, b, bars.Count, minIndex, maxIndex));
        }