Codenamespace StockSharp.Xaml.Charting.IndicatorPainters
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
using Ecng.Serialization;
using Ecng.Xaml;
using StockSharp.Algo.Indicators;
using StockSharp.Localization;
/// <summary>
/// The renderer for <see cref="Ichimoku"/>.
/// </summary>
[Indicator(typeof(Ichimoku))]
public class IchimokuPainter : BaseChartIndicatorPainter
{
private ChartIndicatorElement _tenkan;
private ChartIndicatorElement _kijun;
private ChartIndicatorElement _senkouA;
private ChartIndicatorElement _chinkou;
/// <summary>
/// <see cref="Ichimoku.Tenkan"/> line color.
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.Str2039Key,
Description = LocalizedStrings.Str2040Key)]
public Color TenkanColor { get; set; } = Colors.Red;
/// <summary>
/// <see cref="Ichimoku.Kijun"/> line color.
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.Str2041Key,
Description = LocalizedStrings.Str2042Key)]
public Color KijunColor { get; set; } = Colors.Blue;
/// <summary>
/// <see cref="Ichimoku.SenkouA"/> line color.
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.Str2043Key,
Description = LocalizedStrings.Str2044Key)]
public Color SenkouAColor { get; set; } = Colors.SandyBrown;
/// <summary>
/// <see cref="Ichimoku.SenkouB"/> line color.
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.Str2045Key,
Description = LocalizedStrings.Str2046Key)]
public Color SenkouBColor { get; set; } = Colors.Thistle;
/// <summary>
/// <see cref="Ichimoku.Chinkou"/> line color.
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.Str2047Key,
Description = LocalizedStrings.Str2048Key)]
public Color ChinkouColor { get; set; } = Colors.Green;
/// <summary>
/// To initialize renderer.
/// </summary>
/// <returns>Graphical data.</returns>
public override IEnumerable<ChartIndicatorElement> Init()
{
InnerElements.Clear();
InnerElements.Add(_tenkan = new ChartIndicatorElement
{
DrawStyle = ChartIndicatorDrawStyles.Line,
Color = TenkanColor,
StrokeThickness = BaseElement.StrokeThickness,
Title = LocalizedStrings.Str764
});
InnerElements.Add(_kijun = new ChartIndicatorElement
{
DrawStyle = ChartIndicatorDrawStyles.Line,
Color = KijunColor,
StrokeThickness = BaseElement.StrokeThickness,
Title = LocalizedStrings.Str765
});
InnerElements.Add(_senkouA = new ChartIndicatorElement
{
DrawStyle = ChartIndicatorDrawStyles.Band,
Color = SenkouAColor,
AdditionalColor = SenkouBColor,
StrokeThickness = BaseElement.StrokeThickness,
Title = LocalizedStrings.Str767
});
InnerElements.Add(_chinkou = new ChartIndicatorElement
{
DrawStyle = ChartIndicatorDrawStyles.Line,
Color = ChinkouColor,
StrokeThickness = BaseElement.StrokeThickness,
Title = LocalizedStrings.Str768
});
return InnerElements;
}
/// <summary>
/// To process new values.
/// </summary>
/// <param name="time">The time stamp of the new data generation.</param>
/// <param name="value">Indicator values.</param>
/// <param name="draw">The method of value drawing on the chart.</param>
public override void ProcessValues(DateTimeOffset time, IIndicatorValue value, DrawHandler draw)
{
if (!value.IsFormed)
{
draw(_tenkan, 0, double.NaN);
draw(_kijun, 0, double.NaN);
draw(_senkouA, 0, double.NaN, double.NaN);
draw(_chinkou, 0, double.NaN);
}
else
{
var values = value.GetSimpleValues();
var ind = (Ichimoku)value.Indicator;
draw.TryDraw(_tenkan, 0, values[ind.Tenkan]);
draw.TryDraw(_kijun, 0, values[ind.Kijun]);
draw.TryDraw(_senkouA, 0, values[ind.SenkouA], values[ind.SenkouB]);
draw(_chinkou, 0, double.NaN);
draw.TryDraw(_chinkou, ind.Kijun.Length, values[ind.Chinkou]);
}
}
#region IPersistable
/// <summary>
/// Load settings.
/// </summary>
/// <param name="storage">Settings storage.</param>
public override void Load(SettingsStorage storage)
{
TenkanColor = storage.GetValue<SettingsStorage>(nameof(TenkanColor)).ToColor();
KijunColor = storage.GetValue<SettingsStorage>(nameof(KijunColor)).ToColor();
SenkouAColor = storage.GetValue<SettingsStorage>(nameof(SenkouAColor)).ToColor();
SenkouBColor = storage.GetValue<SettingsStorage>(nameof(SenkouBColor)).ToColor();
ChinkouColor = storage.GetValue<SettingsStorage>(nameof(ChinkouColor)).ToColor();
}
/// <summary>
/// Save settings.
/// </summary>
/// <param name="storage">Settings storage.</param>
public override void Save(SettingsStorage storage)
{
storage.SetValue(nameof(TenkanColor), TenkanColor.ToStorage());
storage.SetValue(nameof(KijunColor), KijunColor.ToStorage());
storage.SetValue(nameof(SenkouAColor), SenkouAColor.ToStorage());
storage.SetValue(nameof(SenkouBColor), SenkouBColor.ToStorage());
storage.SetValue(nameof(ChinkouColor), ChinkouColor.ToStorage());
}
#endregion
}
}