Ejemplo n.º 1
0
        /// <summary>
        /// Copy parameters.
        /// </summary>
        /// <param name="copy">Copy.</param>
        /// <returns>Copy.</returns>
        protected CandleMessage CopyTo(CandleMessage copy)
        {
            base.CopyTo(copy);

            copy.OriginalTransactionId = OriginalTransactionId;
            copy.SubscriptionId        = SubscriptionId;
            copy.SubscriptionIds       = SubscriptionIds;      //?.ToArray();

            copy.OpenPrice      = OpenPrice;
            copy.OpenTime       = OpenTime;
            copy.OpenVolume     = OpenVolume;
            copy.ClosePrice     = ClosePrice;
            copy.CloseTime      = CloseTime;
            copy.CloseVolume    = CloseVolume;
            copy.HighPrice      = HighPrice;
            copy.HighVolume     = HighVolume;
            copy.HighTime       = HighTime;
            copy.LowPrice       = LowPrice;
            copy.LowVolume      = LowVolume;
            copy.LowTime        = LowTime;
            copy.OpenInterest   = OpenInterest;
            copy.SecurityId     = SecurityId;
            copy.TotalVolume    = TotalVolume;
            copy.RelativeVolume = RelativeVolume;
            copy.DownTicks      = DownTicks;
            copy.UpTicks        = UpTicks;
            copy.TotalTicks     = TotalTicks;
            copy.PriceLevels    = PriceLevels?/*.Select(l => l.Clone())*/.ToArray();
            copy.State          = State;

            return(copy);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copy parameters.
        /// </summary>
        /// <param name="copy">Copy.</param>
        /// <returns>Copy.</returns>
        protected CandleMessage CopyTo(CandleMessage copy)
        {
            if (copy == null)
            {
                throw new ArgumentNullException(nameof(copy));
            }

            copy.LocalTime             = LocalTime;
            copy.OpenPrice             = OpenPrice;
            copy.OpenTime              = OpenTime;
            copy.OpenVolume            = OpenVolume;
            copy.ClosePrice            = ClosePrice;
            copy.CloseTime             = CloseTime;
            copy.CloseVolume           = CloseVolume;
            copy.HighPrice             = HighPrice;
            copy.HighVolume            = HighVolume;
            copy.HighTime              = HighTime;
            copy.LowPrice              = LowPrice;
            copy.LowVolume             = LowVolume;
            copy.LowTime               = LowTime;
            copy.OpenInterest          = OpenInterest;
            copy.SecurityId            = SecurityId;
            copy.TotalVolume           = TotalVolume;
            copy.RelativeVolume        = RelativeVolume;
            copy.OriginalTransactionId = OriginalTransactionId;
            copy.DownTicks             = DownTicks;
            copy.UpTicks               = UpTicks;
            copy.TotalTicks            = TotalTicks;
            copy.IsFinished            = IsFinished;
            copy.PriceLevels           = PriceLevels?.Select(l => l.Clone()).ToArray();
            copy.State = State;

            return(copy);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Copy the message into the <paramref name="destination" />.
        /// </summary>
        /// <typeparam name="TCandle">The candle type.</typeparam>
        /// <param name="destination">The object, which copied information.</param>
        /// <returns>The object, which copied information.</returns>
        protected TCandle CopyTo <TCandle>(TCandle destination)
            where TCandle : Candle
        {
            destination.Arg            = Arg;
            destination.ClosePrice     = ClosePrice;
            destination.CloseTime      = CloseTime;
            destination.CloseVolume    = CloseVolume;
            destination.DownTicks      = DownTicks;
            destination.HighPrice      = HighPrice;
            destination.HighTime       = HighTime;
            destination.HighVolume     = HighVolume;
            destination.LowPrice       = LowPrice;
            destination.LowTime        = LowTime;
            destination.LowVolume      = LowVolume;
            destination.OpenInterest   = OpenInterest;
            destination.OpenPrice      = OpenPrice;
            destination.OpenTime       = OpenTime;
            destination.OpenVolume     = OpenVolume;
            destination.RelativeVolume = RelativeVolume;
            destination.Security       = Security;
            //destination.Series = Series;
            //destination.Source = Source;
            //destination.State = State;
            destination.TotalPrice  = TotalPrice;
            destination.TotalTicks  = TotalTicks;
            destination.TotalVolume = TotalVolume;
            //destination.VolumeProfileInfo = VolumeProfileInfo;
            destination.PriceLevels = PriceLevels?.Select(l => l.Clone()).ToArray();

            return(destination);
        }
Ejemplo n.º 4
0
        public override void ProcessProperty(ref Product product, XElement property)
        {
            //we have next structure

            /*
             * <priceLevels>
             *      <normalPricing from="2017-02-13" to="2018-07-18">
             *   <price level="1" moq="1" currency="EUR">61.22</price>
             *  </normalPricing>
             *  <specialOfferPricing></specialOfferPricing>
             * <goingPriceInclVAT currency="EUR" quantity="1">119.99</goingPriceInclVAT>
             * </priceLevels>
             */

            var normalPrice = new NormalPricing();

            normalPrice.From = property.Element("normalPricing").Attribute("from").Value;
            normalPrice.To   = property.Element("normalPricing").Attribute("to").Value;

            var firstDescendant = property.Descendants().FirstOrDefault();

            if (firstDescendant != null)
            {
                foreach (var item in firstDescendant.Descendants())
                {
                    var price = new Price();
                    price.Level      = item.Attribute("level").Value;
                    price.Moq        = item.Attribute("moq").Value;
                    price.Currency   = item.Attribute("currency").Value;
                    price.PriceValue = item.Value;
                    _priceList.Add(price);
                }
            }
            normalPrice.Prices = _priceList;
            var specialOfferPricing = new SpecialOfferPricing();
            var goingPriceInclVat   = new GoingPriceInclVat();

            foreach (var item in property.Descendants())
            {
                if (item.Name.LocalName == "specialOfferPricing")
                {
                    specialOfferPricing.Value = item.Value;
                }
                else
                if (item.Name.LocalName == "goingPriceInclVAT")
                {
                    goingPriceInclVat.Currency = item.Attribute("currency").Value;
                    goingPriceInclVat.Quantity = item.Attribute("quantity").Value;
                    goingPriceInclVat.Value    = item.Value;
                }
            }
            var priceLevel = new PriceLevels();

            priceLevel.GetGoingPriceInclVat = goingPriceInclVat;
            priceLevel.SpecialOfferPricing  = specialOfferPricing;
            priceLevel.NormalPricing        = normalPrice;
            product.PriceLevel = priceLevel;
        }
Ejemplo n.º 5
0
        public override bool IsVisibleOnChart(ChartControl chartControl, ChartScale chartScale, DateTime firstTimeOnChart, DateTime lastTimeOnChart)
        {
            // First check any of the actual anchors are visible, we are immediately done
            foreach (ChartAnchor anchor in Anchors)
            {
                if (anchor.IsEditing || anchor.Time >= firstTimeOnChart && anchor.Time <= lastTimeOnChart)
                {
                    return(true);
                }
            }

            // Calculate extensions and see if they extend into our visible times
            ChartPanel chartPanel           = chartControl.ChartPanels[PanelIndex];
            Point      anchorStartPoint     = StartAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      anchorEndPoint       = EndAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      anchorExtensionPoint = ExtensionAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      midPointExtension    = new Point((anchorExtensionPoint.X + anchorEndPoint.X) / 2, (anchorExtensionPoint.Y + anchorEndPoint.Y) / 2);

            if (CalculationMethod == AndrewsPitchforkCalculationMethod.Schiff)
            {
                anchorStartPoint = new Point(anchorStartPoint.X, (anchorStartPoint.Y + anchorEndPoint.Y) / 2);
            }
            else if (CalculationMethod == AndrewsPitchforkCalculationMethod.ModifiedSchiff)
            {
                anchorStartPoint = new Point((anchorEndPoint.X + anchorStartPoint.X) / 2, (anchorEndPoint.Y + anchorStartPoint.Y) / 2);
            }

            double totalPriceRange = EndAnchor.Price - ExtensionAnchor.Price;
            double startPrice      = ExtensionAnchor.Price;

            foreach (PriceLevel priceLevel in PriceLevels.Where(pl => pl.IsVisible && pl.Stroke != null))
            {
                double levelPrice = (startPrice + ((priceLevel.Value / 100) * totalPriceRange));
                float  pixelY     = chartScale.GetYByValue(levelPrice);
                float  pixelX     = anchorExtensionPoint.X > anchorEndPoint.X ?
                                    (float)(anchorExtensionPoint.X - (Math.Abs((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100)))) :
                                    (float)(anchorExtensionPoint.X + ((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100)));

                Point startPoint    = new Point(pixelX, pixelY);
                Point endPoint      = new Point(startPoint.X + (midPointExtension.X - anchorStartPoint.X), startPoint.Y + (midPointExtension.Y - anchorStartPoint.Y));
                Point maxLevelPoint = GetExtendedPoint(startPoint, endPoint);

                double padding = 5d;
                foreach (Point chkPoint in new[] { startPoint, maxLevelPoint, endPoint })
                {
                    if (chkPoint.X >= chartPanel.X - padding && chkPoint.X <= chartPanel.W + chartPanel.X + padding &&
                        chkPoint.Y >= chartPanel.Y - padding && chkPoint.Y <= chartPanel.Y + chartPanel.H + padding)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 6
0
 public static void AddPriceLevel(PriceLevels aPriceLevels)
 {
     if (Helper.Instance.con.State == ConnectionState.Closed)
     {
         try
         {
             Helper.Instance.con.Open();
             SqlCommand cmd = new SqlCommand("INSERT INTO PriceLevels (Name,Description) VALUES (@Name,@Description)", Helper.Instance.con);
             cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value        = aPriceLevels.Price_Level_Name;
             cmd.Parameters.Add("@Description", SqlDbType.NVarChar).Value = aPriceLevels.Price_Level_Description;
             cmd.ExecuteNonQuery();
             Helper.Instance.con.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show("ERROR IN *PriceLevels* MGMT (AddPriceLevel FUNCTION) EX=" + ex.Message.ToString());
         }
     }
 }
Ejemplo n.º 7
0
 public static void UpdatePriceLevel(PriceLevels aPriceLevels)
 {
     if (Helper.Instance.con.State == ConnectionState.Closed)
     {
         try
         {
             Helper.Instance.con.Open();
             SqlCommand cmd = new SqlCommand("UPDATE PriceLevels SET Name=@Name,Description=@Description,Discount=@Discount WHERE ID=@ID", Helper.Instance.con);
             cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value        = aPriceLevels.Price_Level_Name;
             cmd.Parameters.Add("@Description", SqlDbType.NVarChar).Value = aPriceLevels.Price_Level_Description;
             cmd.Parameters.Add("@Discount", SqlDbType.Float).Value       = aPriceLevels.Price_Level_Discount;
             cmd.ExecuteNonQuery();
             Helper.Instance.con.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show("ERROR IN *PriceLevels* MGMT (UpdatePriceLevel FUNCTION) EX=" + ex.Message.ToString());
         }
     }
 }
Ejemplo n.º 8
0
        protected override void OnStateChange()
        {
            base.OnStateChange();
            switch (State)
            {
            case State.SetDefaults:
                AnchorLineStroke      = new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1f, 50);
                RetracementLineStroke = new Stroke(Brushes.SeaGreen, DashStyleHelper.Solid, 2f);
                Description           = Custom.Resource.NinjaScriptDrawingToolAndrewsPitchforkDescription;
                Name        = Custom.Resource.NinjaScriptDrawingToolAndrewsPitchfork;
                StartAnchor = new ChartAnchor {
                    IsEditing = true, DrawingTool = this
                };
                ExtensionAnchor = new ChartAnchor {
                    IsEditing = true, DrawingTool = this
                };
                EndAnchor = new ChartAnchor {
                    IsEditing = true, DrawingTool = this
                };
                StartAnchor.DisplayName     = Custom.Resource.NinjaScriptDrawingToolAnchorStart;
                EndAnchor.DisplayName       = Custom.Resource.NinjaScriptDrawingToolAnchorEnd;
                ExtensionAnchor.DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchorExtension;
                PriceLevelOpacity           = 5;
                IsTextDisplayed             = true;
                break;

            case State.Configure:
                if (PriceLevels.Count == 0)
                {
                    PriceLevels.Add(new PriceLevel(0, Brushes.SeaGreen));
                    PriceLevels.Add(new PriceLevel(50, Brushes.SeaGreen));
                    PriceLevels.Add(new PriceLevel(100, Brushes.SeaGreen));
                }
                break;

            case State.Terminated:
                Dispose();
                break;
            }
        }
Ejemplo n.º 9
0
        private IEnumerable <Tuple <Point, Point> > GetAndrewsEndPoints(ChartControl chartControl, ChartScale chartScale)
        {
            ChartPanel panel                = chartControl.ChartPanels[PanelIndex];
            double     totalPriceRange      = EndAnchor.Price - ExtensionAnchor.Price;
            double     startPrice           = ExtensionAnchor.Price;
            Point      anchorExtensionPoint = ExtensionAnchor.GetPoint(chartControl, panel, chartScale);
            Point      anchorStartPoint     = StartAnchor.GetPoint(chartControl, panel, chartScale);
            Point      anchorEndPoint       = EndAnchor.GetPoint(chartControl, panel, chartScale);
            Point      midPointExtension    = new Point((anchorExtensionPoint.X + anchorEndPoint.X) / 2, (anchorExtensionPoint.Y + anchorEndPoint.Y) / 2);

            foreach (PriceLevel pl in PriceLevels.Where(pl => pl.IsVisible))
            {
                double levelPrice = (startPrice + ((pl.Value / 100) * totalPriceRange));
                float  pixelY     = chartScale.GetYByValue(levelPrice);
                float  pixelX     = anchorExtensionPoint.X > anchorEndPoint.X ?
                                    (float)(anchorExtensionPoint.X - (Math.Abs((anchorEndPoint.X - anchorExtensionPoint.X) * (pl.Value / 100)))) :
                                    (float)(anchorExtensionPoint.X + ((anchorEndPoint.X - anchorExtensionPoint.X) * (pl.Value / 100)));

                Point startPoint    = new Point(pixelX, pixelY);
                Point endPoint      = new Point(startPoint.X + (midPointExtension.X - anchorStartPoint.X), startPoint.Y + (midPointExtension.Y - anchorStartPoint.Y));
                Point maxLevelPoint = GetExtendedPoint(startPoint, endPoint);
                yield return(new Tuple <Point, Point>(new Point(Math.Max(maxLevelPoint.X, 1), Math.Max(maxLevelPoint.Y, 1)), startPoint));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// To calculate the value area.
        /// </summary>
        public void Calculate()
        {
            // Основная суть:
            // Есть POC Vol от него выше и ниже берется по два значения(объемы)
            // Суммируются и сравниваются, те что в сумме больше, складываются в общий объем, в котором изначально лежит POC Vol.
            // На следующей итерации берутся следующие два объема суммируются и сравниваются, и опять большая сумма ложится в общий объем
            // И так до тех пор пока общий объем не превысит порог, который устанавливается в процентном отношении к всему объему.
            // После превышения порога, самый верхний и самый нижний объем, из которых складывался общий объем будут VAH и VAL.
            // Возможные траблы:
            // Если POC Vol находится на границе ценового диапазона, то сверху/снизу брать нечего, то "набор" объемов только в одну сторону.
            // Если POC Vol находится на один шаг ниже/выше ценового диапазона, то сверху/снизу можно взять только одно значение для сравнения с двумя другими значениями.
            // Теоретически в ценовом диапазоне может быть несколько POC Vol, если будет несколько ценовых уровней с одинаковыми объемом,
            //   в таком случае должен браться POC Vol который ближе к центру. Теоретически они могут быть равно удалены от центра.)))
            // Если сумма сравниваемых объемов равна, х.з. какие брать.

            var maxVolume  = Math.Round(PriceLevels.Sum(p => p.BuyVolume + p.SellVolume) * VolumePercent / 100, 0);
            var currVolume = PriceLevels.Select(p => (p.BuyVolume + p.SellVolume)).Max();

            POC = PriceLevels.FirstOrDefault(p => p.BuyVolume + p.SellVolume == currVolume);

            var abovePoc  = Combine(PriceLevels.Where(p => p.Price > POC.Price).OrderBy(p => p.Price));
            var belowePoc = Combine(PriceLevels.Where(p => p.Price < POC.Price).OrderByDescending(p => p.Price));

            if (abovePoc.Count == 0)
            {
                LinkedListNode <PriceLevel> node;

                for (node = belowePoc.First; node != null; node = node.Next)
                {
                    var vol = node.Value.BuyVolume + node.Value.SellVolume;

                    if (currVolume + vol > maxVolume)
                    {
                        VAH = POC;
                        VAL = node.Value;
                    }
                    else
                    {
                        currVolume += vol;
                    }
                }
            }
            else if (belowePoc.Count == 0)
            {
                LinkedListNode <PriceLevel> node;

                for (node = abovePoc.First; node != null; node = node.Next)
                {
                    var vol = node.Value.BuyVolume + node.Value.SellVolume;

                    if (currVolume + vol > maxVolume)
                    {
                        VAH = node.Value;
                        VAL = POC;
                    }
                    else
                    {
                        currVolume += vol;
                    }
                }
            }
            else
            {
                var abovePocNode = abovePoc.First;
                var belowPocNode = belowePoc.First;

                while (true)
                {
                    var aboveVol = abovePocNode.Value.BuyVolume + abovePocNode.Value.SellVolume;
                    var belowVol = belowPocNode.Value.BuyVolume + belowPocNode.Value.SellVolume;

                    if (aboveVol > belowVol)
                    {
                        if (currVolume + aboveVol > maxVolume)
                        {
                            VAH = abovePocNode.Value;
                            VAL = belowPocNode.Value;
                            break;
                        }

                        currVolume  += aboveVol;
                        abovePocNode = abovePocNode.Next;
                    }
                    else
                    {
                        if (currVolume + belowVol > maxVolume)
                        {
                            VAH = abovePocNode.Value;
                            VAL = belowPocNode.Value;
                            break;
                        }

                        currVolume  += belowVol;
                        belowPocNode = belowPocNode.Next;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (Anchors.All(a => a.IsEditing))
            {
                return;
            }

            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;

            ChartPanel chartPanel           = chartControl.ChartPanels[PanelIndex];
            Point      anchorStartPoint     = StartAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      anchorEndPoint       = EndAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      anchorExtensionPoint = ExtensionAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point      midPointExtension    = new Point((anchorExtensionPoint.X + anchorEndPoint.X) / 2, (anchorExtensionPoint.Y + anchorEndPoint.Y) / 2);

            if (CalculationMethod == AndrewsPitchforkCalculationMethod.Schiff)
            {
                anchorStartPoint = new Point(anchorStartPoint.X, (anchorStartPoint.Y + anchorEndPoint.Y) / 2);
            }
            else if (CalculationMethod == AndrewsPitchforkCalculationMethod.ModifiedSchiff)
            {
                anchorStartPoint = new Point((anchorEndPoint.X + anchorStartPoint.X) / 2, (anchorEndPoint.Y + anchorStartPoint.Y) / 2);
            }

            AnchorLineStroke.RenderTarget      = RenderTarget;
            RetracementLineStroke.RenderTarget = RenderTarget;

            // Align to full pixel to avoid unneeded aliasing
            double strokePixAdj   = AnchorLineStroke.Width % 2 == 0 ? 0.5d : 0d;
            Vector pixelAdjustVec = new Vector(strokePixAdj, strokePixAdj);

            SharpDX.Vector2         startVec = (anchorStartPoint + pixelAdjustVec).ToVector2();
            SharpDX.Vector2         endVec   = (anchorEndPoint + pixelAdjustVec).ToVector2();
            SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : AnchorLineStroke.BrushDX;

            SharpDX.Vector2 startOriginVec = (StartAnchor.GetPoint(chartControl, chartPanel, chartScale) + pixelAdjustVec).ToVector2();

            RenderTarget.DrawLine(startOriginVec, endVec, tmpBrush, AnchorLineStroke.Width, AnchorLineStroke.StrokeStyle);

            // Is second anchor set yet? Check both so we correctly re-draw during extension anchor editing
            if (ExtensionAnchor.IsEditing && EndAnchor.IsEditing)
            {
                return;
            }

            SharpDX.Vector2 extVector = anchorExtensionPoint.ToVector2();
            tmpBrush = IsInHitTest ? chartControl.SelectionBrush : RetracementLineStroke.BrushDX;
            RenderTarget.DrawLine(endVec, extVector, tmpBrush, RetracementLineStroke.Width, RetracementLineStroke.StrokeStyle);

            // If we're doing a hit test pass, don't draw price levels at all, we dont want those to count for
            // hit testing
            if (IsInHitTest || PriceLevels == null || !PriceLevels.Any())
            {
                return;
            }

            SetAllPriceLevelsRenderTarget();

            // Calculate total y range for % calculation on each level
            double totalPriceRange = EndAnchor.Price - ExtensionAnchor.Price;
            double startPrice      = ExtensionAnchor.Price;
            float  minLevelY       = float.MaxValue;
            float  maxLevelY       = float.MinValue;

            // Store values to use in correct render order
            Point  lastEndPoint   = new Point(0, 0);
            Point  lastStartPoint = new Point(0, 0);
            Stroke lastStroke     = null;
            List <Tuple <PriceLevel, Point> > textPoints = new List <Tuple <PriceLevel, Point> >();

            foreach (PriceLevel priceLevel in PriceLevels.Where(pl => pl.IsVisible && pl.Stroke != null).OrderBy(pl => pl.Value))
            {
                double levelPrice = (startPrice + ((priceLevel.Value / 100) * totalPriceRange));
                float  pixelY     = chartScale.GetYByValue(levelPrice);
                float  pixelX     = anchorExtensionPoint.X > anchorEndPoint.X ?
                                    priceLevel.Value >= 0 ? (float)(anchorExtensionPoint.X - (Math.Abs((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100)))) : (float)(anchorExtensionPoint.X + ((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100))):
                                    priceLevel.Value >= 0 ? (float)(anchorExtensionPoint.X + ((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100))) : (float)(anchorExtensionPoint.X - (Math.Abs((anchorEndPoint.X - anchorExtensionPoint.X) * (priceLevel.Value / 100))));
                Point startPoint    = new Point(pixelX, pixelY);
                Point endPoint      = new Point(startPoint.X + (midPointExtension.X - anchorStartPoint.X), startPoint.Y + (midPointExtension.Y - anchorStartPoint.Y));
                Point maxLevelPoint = GetExtendedPoint(startPoint, endPoint);
                if (priceLevel.Value == 50)
                {
                    RenderTarget.DrawLine(startVec, maxLevelPoint.ToVector2(), priceLevel.Stroke.BrushDX, priceLevel.Stroke.Width, priceLevel.Stroke.StrokeStyle);
                }
                else
                {
                    RenderTarget.DrawLine(startPoint.ToVector2(), maxLevelPoint.ToVector2(), priceLevel.Stroke.BrushDX, priceLevel.Stroke.Width, priceLevel.Stroke.StrokeStyle);
                }

                if (lastStroke == null)
                {
                    lastStroke = new Stroke();
                }
                else
                {
                    SharpDX.Direct2D1.PathGeometry lineGeometry = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFactory);
                    SharpDX.Direct2D1.GeometrySink sink         = lineGeometry.Open();
                    sink.BeginFigure(lastEndPoint.ToVector2(), SharpDX.Direct2D1.FigureBegin.Filled);
                    // Does the fill color need to fill a corner?  Check and add a point
                    if (lastEndPoint.Y != maxLevelPoint.Y && lastEndPoint.X != maxLevelPoint.X)
                    {
                        double boundaryX;
                        double boundaryY;

                        if (lastEndPoint.Y <= ChartPanel.Y || lastEndPoint.Y >= ChartPanel.Y + ChartPanel.H)
                        {
                            boundaryY = lastEndPoint.Y;
                            boundaryX = maxLevelPoint.X;
                        }
                        else
                        {
                            boundaryY = maxLevelPoint.Y;
                            boundaryX = lastEndPoint.X;
                        }
                        sink.AddLine(new SharpDX.Vector2((float)boundaryX, (float)boundaryY));
                    }
                    sink.AddLine(maxLevelPoint.ToVector2());
                    sink.AddLine(startPoint.ToVector2());
                    sink.AddLine(lastStartPoint.ToVector2());
                    sink.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed);
                    sink.Close();
                    RenderTarget.FillGeometry(lineGeometry, lastStroke.BrushDX);
                    lineGeometry.Dispose();
                }

                if (IsTextDisplayed)
                {
                    textPoints.Add(new Tuple <PriceLevel, Point>(priceLevel, maxLevelPoint));
                }

                priceLevel.Stroke.CopyTo(lastStroke);
                lastStroke.Opacity = PriceLevelOpacity;
                lastStartPoint     = startPoint;
                lastEndPoint       = maxLevelPoint;
                minLevelY          = Math.Min(pixelY, minLevelY);
                maxLevelY          = Math.Max(pixelY, maxLevelY);
            }

            // Render text last so it's on top of the price level colors
            if (IsTextDisplayed)
            {
                foreach (Tuple <PriceLevel, Point> textPoint in textPoints)
                {
                    DrawPriceLevelText(0, 0, textPoint.Item2, textPoint.Item1, chartPanel);
                }
            }
        }
Ejemplo n.º 12
0
        private void AddNewPriceLevelBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validators.TxtBoxNotEmpty(NameTxtBox.Text) && Validators.TxtBoxNotEmpty(DescriptionTxtBox.Text))
                {
                    Nullable <int> Check = PriceLevelsMgmt.IsPriceLevelUsed(NameTxtBox.Text);
                    if (Check == 10)
                    {
                        PriceLevels aPriceLevel = new PriceLevels();
                        aPriceLevel.Price_Level_Name        = NameTxtBox.Text;
                        aPriceLevel.Price_Level_Description = DescriptionTxtBox.Text;

                        try
                        {
                            PriceLevelsMgmt.AddPriceLevel(aPriceLevel);
                            MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Close();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else if (Check == 5)
                    {
                        MessageBox.Show(MsgTxt.PriceLevelsTxt + "[" + NameTxtBox.Text + "]" + MsgTxt.AlreadyUsedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else if (Check == null)
                    {
                        MessageBox.Show(MsgTxt.UnexpectedError + " \n[DataBase Error]:IN [AddNewPriceLevelBtn_Click]" + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (!Validators.TxtBoxNotEmpty(DescriptionTxtBox.Text))
                    {
                        DescriptionTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                        DescriptionTxtBox.Focus();
                    }
                    else
                    {
                        DescriptionTxtBox.BackColor = DescriptionBGColor;
                    }

                    if (!Validators.TxtBoxNotEmpty(NameTxtBox.Text))
                    {
                        NameTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                        NameTxtBox.Focus();
                    }
                    else
                    {
                        NameTxtBox.BackColor = NameBGColor;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + " \n[Exception]:IN [AddNewPriceLevelBtn_Click]" + "\n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }