public virtual void CopyTo(PriceLevel other) { other.IsVisible = IsVisible; other.IsValueVisible = IsValueVisible; other.Name = Name; if (Stroke != null) { other.Stroke = new Stroke(); Stroke.CopyTo(other.Stroke); } else { other.Stroke = null; } other.Tag = Tag; other.Value = Value; other.ValueFormatFunc = ValueFormatFunc; }
protected void DrawPriceLevelText(double minX, double maxX, Point endPoint, PriceLevel priceLevel, ChartPanel panel) { Gui.Tools.SimpleFont wpfFont = panel.ChartControl.Properties.LabelFont ?? new Gui.Tools.SimpleFont(); SharpDX.DirectWrite.TextFormat dxTextFormat = wpfFont.ToDirectWriteTextFormat(); string str = string.Format("{0}", (priceLevel.Value / 100).ToString("P")); SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, str, dxTextFormat, panel.H, dxTextFormat.FontSize); float usedFontHeight = textLayout.Metrics.Height; float usedFontWidth = textLayout.Metrics.Width; Point textEndPoint = endPoint; double maxWidth = panel.X + panel.W; double maxHeight = panel.Y + panel.H; double minWidth = panel.X; double minHeight = panel.Y; if (textEndPoint.Y + usedFontHeight >= maxHeight) { textEndPoint.Y = maxHeight - usedFontHeight; // Set to bottom } if (textEndPoint.Y < minHeight) // Set to top { textEndPoint.Y = minHeight; } if (textEndPoint.X + usedFontWidth >= maxWidth) { textEndPoint.X = maxWidth - usedFontWidth; //Set to right side; } if (textEndPoint.X < minWidth) { textEndPoint.X = minWidth; // Set to left side; } RenderTarget.DrawTextLayout(new SharpDX.Vector2((float)(textEndPoint.X), (float)(textEndPoint.Y)), textLayout, priceLevel.Stroke.BrushDX, SharpDX.Direct2D1.DrawTextOptions.NoSnap); dxTextFormat.Dispose(); textLayout.Dispose(); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs) { PriceLevel priceLevel = component as PriceLevel; PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context) ? base.GetProperties(context, component, attrs) : TypeDescriptor.GetProperties(component, attrs); if (priceLevel == null || propertyDescriptorCollection == null) { return(null); } PropertyDescriptorCollection filtered = new PropertyDescriptorCollection(null); foreach (PropertyDescriptor property in propertyDescriptorCollection) { if ((property.Name != "Value" || priceLevel.IsValueVisible) && property.IsBrowsable) { filtered.Add(property); } } return(filtered); }
public override bool IsAlertConditionTrue(AlertConditionItem conditionItem, Condition condition, ChartAlertValue[] values, ChartControl chartControl, ChartScale chartScale) { PriceLevel priceLevel = conditionItem.Tag as PriceLevel; if (priceLevel == null) { return(false); } 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; 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 alertStartPoint = new Point(pixelX, pixelY); Point endPoint = new Point(alertStartPoint.X + (midPointExtension.X - anchorStartPoint.X), alertStartPoint.Y + (midPointExtension.Y - anchorStartPoint.Y)); Point alertEndPoint = GetExtendedPoint(alertStartPoint, endPoint); double firstBarX = values[0].ValueType == ChartAlertValueType.StaticValue ? pixelX : chartControl.GetXByTime(values[0].Time); double firstBarY = chartScale.GetYByValue(values[0].Value); Point barPoint = new Point(firstBarX, firstBarY); // Check bars are not yet to our drawing tool if (firstBarX < alertStartPoint.X || firstBarX > alertEndPoint.X) { return(false); } // NOTE: 'left / right' is relative to if line was vertical. It can end up backwards too MathHelper.PointLineLocation pointLocation = MathHelper.GetPointLineLocation(alertStartPoint, alertEndPoint, barPoint); // For vertical things, think of a vertical line rotated 90 degrees to lay flat, where it's normal vector is 'up' switch (condition) { case Condition.Greater: return(pointLocation == MathHelper.PointLineLocation.LeftOrAbove); case Condition.GreaterEqual: return(pointLocation == MathHelper.PointLineLocation.LeftOrAbove || pointLocation == MathHelper.PointLineLocation.DirectlyOnLine); case Condition.Less: return(pointLocation == MathHelper.PointLineLocation.RightOrBelow); case Condition.LessEqual: return(pointLocation == MathHelper.PointLineLocation.RightOrBelow || pointLocation == MathHelper.PointLineLocation.DirectlyOnLine); case Condition.Equals: return(pointLocation == MathHelper.PointLineLocation.DirectlyOnLine); case Condition.NotEqual: return(pointLocation != MathHelper.PointLineLocation.DirectlyOnLine); case Condition.CrossAbove: case Condition.CrossBelow: Predicate <ChartAlertValue> predicate = v => { double barX = chartControl.GetXByTime(v.Time); double barY = chartScale.GetYByValue(v.Value); Point stepBarPoint = new Point(barX, barY); // NOTE: 'left / right' is relative to if line was vertical. It can end up backwards too MathHelper.PointLineLocation ptLocation = MathHelper.GetPointLineLocation(alertStartPoint, alertEndPoint, stepBarPoint); if (condition == Condition.CrossAbove) { return(ptLocation == MathHelper.PointLineLocation.LeftOrAbove); } return(ptLocation == MathHelper.PointLineLocation.RightOrBelow); }; return(MathHelper.DidPredicateCross(values, predicate)); } return(false); }