/// <summary>
/// Рендерер для <see cref="Ichimoku"/>.
/// </summary>
public class IchimokuPainter : BaseChartIndicatorPainter<Ichimoku>
{
private Color _tenkanColor = Colors.Red;
/// <summary>
/// Цвет Tenkan линии.
/// </summary>
[DisplayName("Цвет Tenkan")]
[Description("Цвет Tenkan линии.")]
public Color TenkanColor
{
get { return _tenkanColor; }
set { _tenkanColor = value; }
}
private Color _kijunColor = Colors.Blue;
/// <summary>
/// Цвет Kijun линии.
/// </summary>
[DisplayName("Цвет Kijun")]
[Description("Цвет Kijun линии.")]
public Color KijunColor
{
get { return _kijunColor; }
set { _kijunColor = value; }
}
private Color _senkouAColor = Colors.SandyBrown;
/// <summary>
/// Цвет SenkouA линии.
/// </summary>
[DisplayName("Цвет SenkouA")]
[Description("Цвет SenkouA линии.")]
public Color SenkouAColor
{
get { return _senkouAColor; }
set { _senkouAColor = value; }
}
private Color _senkouBColor = Colors.Thistle;
/// <summary>
/// Цвет SenkouA линии.
/// </summary>
[DisplayName("Цвет SenkouB")]
[Description("Цвет SenkouB линии.")]
public Color SenkouBColor
{
get { return _senkouBColor; }
set { _senkouBColor = value; }
}
private Color _chinkouColor = Colors.Green;
/// <summary>
/// Цвет Chinkou линии.
/// </summary>
[DisplayName("Цвет Chinkou")]
[Description("Цвет Chinkou линии.")]
public Color ChinkouColor
{
get { return _chinkouColor; }
set { _chinkouColor = value; }
}
/// <summary>
/// Инициализировать рендерер.
/// </summary>
/// <param name="areaName">Название области.</param>
/// <param name="isIndexed">Индексирована ли область.</param>
/// <returns>Графические данные.</returns>
public override IDictionary<IIndicator, ChartIndicatorElement> Init(String areaName, bool isIndexed)
{
IndicatorSeries.Clear();
IndicatorSeries.Add(Indicator.Tenkan, new ChartIndicatorElement
{
Indicator = Indicator.Tenkan,
DrawStyle = ChartIndicatorDrawStyles.Line,
Color = TenkanColor,
StrokeThickness = BaseElement.StrokeThickness,
Title = "Tenkan"
});
IndicatorSeries.Add(Indicator.Kijun, new ChartIndicatorElement
{
Indicator = Indicator.Kijun,
DrawStyle = ChartIndicatorDrawStyles.Line,
Color = KijunColor,
StrokeThickness = BaseElement.StrokeThickness,
Title = "Kijun"
});
IndicatorSeries.Add(Indicator.SenkouA, new ChartIndicatorElement
{
Indicator = Indicator.SenkouA,
DrawStyle = ChartIndicatorDrawStyles.Band,
Color = SenkouAColor,
AdditionalColor = SenkouBColor,
StrokeThickness = BaseElement.StrokeThickness,
Title = "SenkouA(B)"
});
IndicatorSeries.Add(Indicator.Chinkou, new ChartIndicatorElement
{
Indicator = Indicator.Chinkou,
DrawStyle = ChartIndicatorDrawStyles.Line,
Color = ChinkouColor,
StrokeThickness = BaseElement.StrokeThickness,
Title = "Chinkou"
});
return IndicatorSeries;
}
/// <summary>
/// Обработать новые значения.
/// </summary>
/// <param name="time">Временная отметка формирования новых данных.</param>
/// <param name="value">Значения индикатора.</param>
/// <param name="draw">Метод отрисовки значения на графике.</param>
/// <returns>Новые значения для отображения на графике.</returns>
public override IEnumerable<decimal> ProcessValues(DateTime time, ChartIndicatorValue value, DrawHandler draw)
{
var newYValues = new List<decimal>();
if (!value.IsFormed)
{
draw(Indicator.Tenkan, 0, double.NaN);
draw(Indicator.Kijun, 0, double.NaN);
draw(Indicator.SenkouA, 0, double.NaN, double.NaN);
draw(Indicator.Chinkou, 0, double.NaN);
}
else
{
var values = value.GetSimpleValues();
var tenkanY = values[Indicator.Tenkan].GetValue<decimal>();
var kijunY = values[Indicator.Kijun].GetValue<decimal>();
var senkouaY = values[Indicator.SenkouA].GetValue<decimal>();
var senkoubY = values[Indicator.SenkouB].GetValue<decimal>();
var chinkouY = values[Indicator.Chinkou].GetValue<decimal>();
draw(Indicator.Tenkan, 0, (double)tenkanY);
newYValues.Add(tenkanY);
draw(Indicator.Kijun, 0, (double)kijunY);
newYValues.Add(kijunY);
draw(Indicator.SenkouA, 0, (double)senkouaY, (double)senkoubY);
newYValues.Add(senkouaY);
newYValues.Add(senkoubY);
draw(Indicator.Chinkou, 0, double.NaN);
draw(Indicator.Chinkou, Indicator.Kijun.Length, (double)chinkouY);
newYValues.Add(chinkouY);
}
return newYValues;
}
}