Beispiel #1
0
        private void UpdateFans(ChartTrendLine mainFan, ChartTrendLine handleLine, Dictionary <double, ChartTrendLine> fans)
        {
            var endBarIndex = Chart.Bars.GetBarIndex(mainFan.Time2, Chart.Symbol);

            var barsDelta  = handleLine.GetBarsNumber(Chart.Bars, Chart.Symbol) / 2;
            var priceDelta = handleLine.GetPriceDelta() / 2;

            var slope = handleLine.GetSlope();

            foreach (var fan in fans)
            {
                var fanSettings = SideFanSettings.FirstOrDefault(iSettings => iSettings.Percent == fan.Key);

                if (fanSettings == null)
                {
                    continue;
                }

                var secondBarIndex = slope > 0 ? endBarIndex + barsDelta * fanSettings.Percent : endBarIndex - barsDelta * fanSettings.Percent;

                var secondTime = Chart.Bars.GetOpenTime(secondBarIndex, Chart.Symbol);

                var secondPrice = mainFan.Y2 + priceDelta * fanSettings.Percent;

                var fanLine = fan.Value;

                fanLine.Time1 = mainFan.Time1;
                fanLine.Time2 = secondTime;

                fanLine.Y1 = mainFan.Y1;
                fanLine.Y2 = secondPrice;
            }
        }
Beispiel #2
0
        protected override void UpdateLabels(long id, ChartObject chartObject, ChartText[] labels, ChartObject[] patternObjects)
        {
            var trendLines = patternObjects.Where(iObject => iObject.ObjectType == ChartObjectType.TrendLine).Cast <ChartTrendLine>().ToArray();

            if (trendLines == null)
            {
                return;
            }

            var mainFan = trendLines.FirstOrDefault(iLine => iLine.Name.IndexOf("MainFan", StringComparison.OrdinalIgnoreCase) > -1);

            if (mainFan == null)
            {
                return;
            }

            var sideFans = trendLines.Where(iLine => iLine.Name.IndexOf("SideFan", StringComparison.OrdinalIgnoreCase) > -1).ToDictionary(iLine => double.Parse(iLine.Name.Split('_').Last(), CultureInfo.InvariantCulture));

            if (labels.Length == 0)
            {
                DrawLabels(mainFan, sideFans, id);

                return;
            }

            foreach (var label in labels)
            {
                var labelFanName = label.Name.Split('_').Last();

                ChartTrendLine line;

                if (labelFanName.Equals("1x1", StringComparison.OrdinalIgnoreCase))
                {
                    line = mainFan;
                }
                else
                {
                    var fanSettings = SideFanSettings.FirstOrDefault(iFanSettings => iFanSettings.Name.Equals(labelFanName, StringComparison.OrdinalIgnoreCase));

                    if (fanSettings == null || !sideFans.TryGetValue(fanSettings.Percent, out line))
                    {
                        continue;
                    }
                }

                label.Time = line.Time2;
                label.Y    = line.Y2;
            }
        }