Exemplo n.º 1
0
        public override bool IsAlertConditionTrue(AlertConditionItem conditionItem, Condition condition, ChartAlertValue[] values,
                                                  ChartControl chartControl, ChartScale chartScale)
        {
            double   minPrice = Anchors.Min(a => a.Price);
            double   maxPrice = Anchors.Max(a => a.Price);
            DateTime minTime  = Anchors.Min(a => a.Time);
            DateTime maxTime  = Anchors.Max(a => a.Time);

            // note, time region higlight x will always be a cross from moving linearly. until someone builds a time machine anyway
            // no need for lookback/cross check so just check first (most recent) value
            if (Mode == RegionHighlightMode.Time)
            {
                DateTime vt = values[0].Time;
                return(condition == Condition.CrossInside ? vt > minTime && vt <= maxTime : vt > minTime && vt < maxTime);
            }

            Predicate <ChartAlertValue> predicate = v =>
            {
                bool isInside = Mode == RegionHighlightMode.Time ? v.Time >= minTime && v.Time <= maxTime : v.Value >= minPrice && v.Value <= maxPrice;
                return(condition == Condition.CrossInside ? isInside : !isInside);
            };

            return(MathHelper.DidPredicateCross(values, predicate));
        }