Код: Выделить всё
// TA.Script.XSeries
using System;
using System.Collections.Generic;
using System.Drawing;
using AD.Common.DataStructures;
using TA.Script;
public class XSeries
{
   public string Name;
   public DrawAs Style;
   public Color Color;
   public LineStyles LineStyle;
   public int LineWidth = 1;
   public SortedList<long, double> Points;
   public AxesKindList _PriceStudy;
   private bool _NewArea = true;
   private int _AxisSize = 100;
   private ScriptedCode _Owner;
   public double LastValue;
   public const int DefaultAlpha = 50;
   public const int DefaultAlphaFigure = 100;
   public bool Visible { get; set; }
   public bool PriceStudy => GetPriceStudy();
   public bool ZeroBased { get; set; }
   public bool NeedToCorrect { get; set; }
   public bool NewArea
   {
      get
      {
         return _NewArea;
      }
      set
      {
         _NewArea = value;
      }
   }
   public int AxisSize
   {
      get
      {
         return _AxisSize;
      }
      set
      {
         if (value >= 10 && value <= 100)
         {
            _AxisSize = value;
            return;
         }
         throw new ArgumentOutOfRangeException("AxisSize", "Parameter should be in the range [10, 100]!");
      }
   }
   public ScriptedCode Owner
   {
      get
      {
         return _Owner;
      }
      set
      {
         SetOwner(value);
      }
   }
   public double this[int index]
   {
      get
      {
         return GetValue(index);
      }
      set
      {
         SetValue(index, value);
      }
   }
   public double this[AdsFuncParameter index]
   {
      get
      {
         return GetValue((int)(double)index);
      }
      set
      {
         SetValue((int)(double)index, value);
      }
   }
   private bool GetPriceStudy()
   {
      if (Owner is ScriptedIndicator)
      {
         if (_PriceStudy != 0)
         {
            return _PriceStudy == AxesKindList.Parent;
         }
         return (Owner as ScriptedIndicator).PriceStudy;
      }
      return _PriceStudy == AxesKindList.Parent;
   }
   private void SetOwner(ScriptedCode value)
   {
      _Owner = value;
   }
   public XSeries()
   {
      Init();
   }
   public void Init()
   {
      Points = new SortedList<long, double>();
   }
   public static implicit operator double(XSeries value)
   {
      return value[0];
   }
   public static implicit operator XSeries(double value)
   {
      return new XSeries
      {
         LastValue = value
      };
   }
   public static implicit operator XSeries(AdsInputStream value)
   {
      return new XSeries
      {
         LastValue = value[0]
      };
   }
   public static implicit operator XSeries(AdsFuncParameter value)
   {
      return new XSeries
      {
         LastValue = value
      };
   }
   private void SetValue(int index, double value)
   {
      if (Owner.TryGetTime(index, out var time))
      {
         long key = DataPoint.SecondsFromDateTime(time);
         if (Points.ContainsKey(key))
         {
            Points[key] = value;
         }
         else
         {
            Points.Add(key, value);
         }
      }
   }
   private double GetValue(int index)
   {
      double value = double.NaN;
      if (Owner.TryGetTime(index, out var time))
      {
         long key = DataPoint.SecondsFromDateTime(time);
         Points.TryGetValue(key, out value);
      }
      return value;
   }
   private double GetValueByTime(long time)
   {
      return Points[time];
   }
   private void SetValueByTime(long time, double value)
   {
      if (Points.ContainsKey(time))
      {
         Points[time] = value;
      }
      else
      {
         Points.Add(time, value);
      }
   }
   public void Clear()
   {
      if (Points != null)
      {
         Points.Clear();
      }
   }
   public string Prepare4Compiler()
   {
      return "XSeries __" + Name + " = new XSeries() {" + $" Name = \"{Name}\", Style = DrawAs.{Style.ToString()}, Color = Color.{Color.ToKnownColor().ToString()}, Visible = {Visible.ToString().ToLower()} " + "};\npublic XSeries " + Name + "\n{ get { return __" + Name + "; } set { " + $"SetSeries(__{Name}, value);" + "}}";
   }
   public void Hide()
   {
      Owner.CustomDrawPoint(this, DrawPointAs.Hidden);
   }
   public void DrawLine(Color color, LineStyles style, int width)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.Line, color, style, width, true);
   }
   public void DrawLine()
   {
      DrawLine(Color.Empty, LineStyle, LineWidth);
   }
   public void DrawDash(Color color, LineStyles style, int width, int delta = 0)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.HorizontalLine, color, style, width, delta, true);
   }
   public void DrawDash(int delta = 0)
   {
      DrawDash(Color.Empty, LineStyle, LineWidth, delta);
   }
   public void DrawVertical(XSeries series)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.VerticalLine, Color.Empty, LineStyle, LineWidth, (series != null) ? series.Name : string.Empty, true);
   }
   public void DrawVertical(XSeries series, Color color, LineStyles style = LineStyles.Solid, int width = 1)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.VerticalLine, color, style, width, (series != null) ? series.Name : string.Empty, true);
   }
   public void DrawVertical(Color color, LineStyles style, int width)
   {
      DrawVertical(null, color, style, width);
   }
   public void DrawVertical()
   {
      DrawVertical(Color.Empty, LineStyle, LineWidth);
   }
   public void DrawFigure(PointFigure figure, Color color, LineStyles style, int width, Color fill, int alpha = 100)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.Point, figure, true, color, style, width, fill, alpha);
   }
   public void DrawCircle(Color color, LineStyles style, int width, Color fill, int alpha = 100)
   {
      DrawFigure(PointFigure.Circle, color, style, width, fill, alpha);
   }
   public void DrawCircle()
   {
      DrawCircle(Color.Empty, LineStyles.Solid, 1, Color.Empty);
   }
   public void DrawSquare(Color color, LineStyles style, int width, Color fill, int alpha = 100)
   {
      DrawFigure(PointFigure.Square, color, style, width, fill, alpha);
   }
   public void DrawSquare()
   {
      DrawSquare(Color.Empty, LineStyles.Solid, 1, Color.Empty);
   }
   public void DrawArrowUp(Color color, LineStyles style, int width, Color fill, int alpha = 100)
   {
      DrawFigure(PointFigure.Up, color, style, width, fill, alpha);
   }
   public void DrawArrowUp()
   {
      DrawArrowUp(Color.Empty, LineStyles.Solid, 1, Color.Empty);
   }
   public void DrawArrowDown(Color color, LineStyles style, int width, Color fill, int alpha = 100)
   {
      DrawFigure(PointFigure.Down, color, style, width, fill, alpha);
   }
   public void DrawArrowDown()
   {
      DrawArrowDown(Color.Empty, LineStyles.Solid, 1, Color.Empty);
   }
   public void DrawArrowLeft(Color color, LineStyles style, int width, Color fill, int alpha = 100)
   {
      DrawFigure(PointFigure.Left, color, style, width, fill, alpha);
   }
   public void DrawArrowLeft()
   {
      DrawArrowLeft(Color.Empty, LineStyles.Solid, 1, Color.Empty);
   }
   public void DrawArrowRight(Color color, LineStyles style, int width, Color fill, int alpha = 100)
   {
      DrawFigure(PointFigure.Right, color, style, width, fill, alpha);
   }
   public void DrawArrowRight()
   {
      DrawArrowRight(Color.Empty, LineStyles.Solid, 1, Color.Empty);
   }
   public void DrawHistogram(XSeries series, Color color, LineStyles style, int width, Color fill, int alpha = 50)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.Histogram, color, style, width, true, fill, alpha, (series != null) ? series.Name : string.Empty);
   }
   public void DrawHistogram(Color color, LineStyles style, int width, Color fill, int alpha = 50)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.Histogram, color, style, width, true, fill, alpha, string.Empty);
   }
   public void DrawHistogram(Color color, int alpha = 50)
   {
      DrawHistogram(null, color, LineStyles.Solid, 1, color, alpha);
   }
   public void DrawHistogram(Color color, Color fill, int alpha = 50)
   {
      DrawHistogram(null, color, LineStyles.Solid, 1, fill, alpha);
   }
   public void DrawHistogram(XSeries series, Color fill, int alpha = 50)
   {
      DrawHistogram(series, Color.Empty, LineStyles.Solid, 1, fill, alpha);
   }
   public void DrawHistogram(XSeries series)
   {
      DrawHistogram(series, Color.Empty, LineStyles.Solid, 1, Color.Empty);
   }
   public void DrawHistogram()
   {
      DrawHistogram(Color.Empty, LineStyles.Solid, 1, Color.Empty);
   }
   public void DrawArea(Color color, LineStyles style, int width, Color fill, int alpha = 50)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.Area, color, style, width, true, fill, alpha);
   }
   public void DrawArea(Color fill, int alpha)
   {
      DrawArea(Color.Empty, LineStyle, LineWidth, fill, alpha);
   }
   public void DrawArea()
   {
      DrawArea(Color.Empty, 30);
   }
   public void DrawChannel(Color fill, int alpha)
   {
      DrawArea(Color.Empty, LineStyle, LineWidth, fill, alpha);
   }
   public void DrawChannel(XSeries series, Color fill, int alpha)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.Area, Color.Empty, LineStyle, LineWidth, true, fill, alpha, (series != null) ? series.Name : string.Empty);
   }
   public void DrawChannel(XSeries series)
   {
      DrawChannel(series, Color.Empty, 30);
   }
   public void DrawSection(Color color, LineStyles style, int width, int delta)
   {
      Owner.CustomDrawPoint(this, DrawPointAs.TrendLine, color, style, width, delta, true);
   }
   public void DrawSection(int delta)
   {
      DrawSection(Color.Empty, LineStyle, LineWidth, delta);
   }
   public static int PercentToAlpha(int percent)
   {
      int num = percent * 255 / 100;
      if (num < 0 || num > 255)
      {
         num = 120;
      }
      return num;
   }
   public static int AlphaToPercent(int alpha)
   {
      int num = alpha * 100 / 255;
      if (num < 0 || num > 100)
      {
         num = 50;
      }
      return num;
   }
}