Esempio n. 1
0
        public virtual object Clone()
        {
            GannAngle newAngle = new GannAngle();

            CopyTo(newAngle);
            return(newAngle);
        }
Esempio n. 2
0
 public virtual void CopyTo(GannAngle other)
 {
     other.IsVisible      = IsVisible;
     other.IsValueVisible = IsValueVisible;
     if (Stroke != null)
     {
         other.Stroke = new Stroke();
         Stroke.CopyTo(other.Stroke);
     }
     else
     {
         other.Stroke = null;
     }
     other.Tag    = Tag;
     other.RatioX = RatioX;
     other.RatioY = RatioY;
 }
Esempio n. 3
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
        {
            GannAngle gannAngle = component as GannAngle;
            PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context) ?
                                                                        base.GetProperties(context, component, attrs) : TypeDescriptor.GetProperties(component, attrs);

            if (gannAngle == null || propertyDescriptorCollection == null)
            {
                return(null);
            }

            PropertyDescriptorCollection filtered = new PropertyDescriptorCollection(null);

            foreach (PropertyDescriptor property in propertyDescriptorCollection)
            {
                if ((property.Name != "Value" || gannAngle.IsValueVisible) && property.IsBrowsable)
                {
                    filtered.Add(property);
                }
            }

            return(filtered);
        }
Esempio n. 4
0
        public override bool IsAlertConditionTrue(AlertConditionItem conditionItem, Condition condition, ChartAlertValue[] values, ChartControl chartControl, ChartScale chartScale)
        {
            GannAngle gannAngle = conditionItem.Tag as GannAngle;

            if (gannAngle == null)
            {
                return(false);
            }

            ChartPanel chartPanel  = chartControl.ChartPanels[PanelIndex];
            Point      anchorPoint = Anchor.GetPoint(chartControl, chartPanel, chartScale);

            // dig out the line we're running on
            double dx               = gannAngle.RatioX * chartControl.Properties.BarDistance;
            double dVal             = chartScale.GetPixelsForDistance(gannAngle.RatioY * chartControl.Instrument.MasterInstrument.TickSize);
            Point  stepPoint        = GetGannStepPoint(chartScale, anchorPoint.X, Anchor.Price, dx, dVal);
            Point  extendedEndPoint = GetExtendedPoint(anchorPoint, stepPoint);

            if (values[0].ValueType == ChartAlertValueType.StaticTime)
            {
                int checkX = chartControl.GetXByTime(values[0].Time);
                return(stepPoint.X >= checkX || stepPoint.X >= checkX);
            }

            double barX     = chartControl.GetXByTime(values[0].Time);
            double barY     = chartScale.GetYByValue(values[0].Value);
            Point  barPoint = new Point(barX, barY);

            // bars passed our drawing tool line
            if (extendedEndPoint.X < barX)
            {
                return(false);
            }

            // bars not yet to our drawing tool line
            if (stepPoint.X > barY)
            {
                return(false);
            }

            if (condition == Condition.CrossAbove || condition == Condition.CrossBelow)
            {
                Predicate <ChartAlertValue> predicate = v =>
                {
                    // bar x/y
                    double bX           = chartControl.GetXByTime(v.Time);
                    double bY           = chartScale.GetYByValue(v.Value);
                    Point  stepBarPoint = new Point(bX, bY);
                    // NOTE: 'left / right' is relative to if line was vertical. it can end up backwards too
                    MathHelper.PointLineLocation ptLocation = MathHelper.GetPointLineLocation(anchorPoint, extendedEndPoint, stepBarPoint);
                    if (condition == Condition.CrossAbove)
                    {
                        return(ptLocation == MathHelper.PointLineLocation.LeftOrAbove);
                    }
                    return(ptLocation == MathHelper.PointLineLocation.RightOrBelow);
                };
                return(MathHelper.DidPredicateCross(values, predicate));
            }


            MathHelper.PointLineLocation pointLocation = MathHelper.GetPointLineLocation(anchorPoint, extendedEndPoint, barPoint);
            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);

            default:                                                return(false);
            }
        }