using System.Collections.Generic;
using PTLRuntime.NETScript;
using PTLRuntime.NETScript.Charts;
namespace ChartHistogramIndicator
public class ChartHistogramIndicator : NETIndicator
public ChartHistogramIndicator()
base.Author = "developer";
base.DateOfCreation = "29.08.2017";
base.Password = "66b4a6416f59370e942d353f08a9ae36";
base.ProjectName = "ChartHistogramIndicator";
base.SeparateWindow = false;
[InputParameter("Drawing Zone Height, %", 0, 1, 99)]
public int zoneHeight = 30;
[InputParameter("Histogram Color", 1)]
get { return histBrush.Color; }
SolidBrush histBrush = new SolidBrush(Color.DarkOrange);
[InputParameter("Font size", 2, 6, 14)]
[InputParameter("Font Color", 3)]
get { return fontBrush.Color; }
SolidBrush fontBrush = new SolidBrush(Color.Black);
StringFormat stringFormat = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
Dictionary<DateTime,double> values;
public override void Init()
font = new Font("Arial", fontSize);
values = new Dictionary<DateTime, double>();
public override void OnQuote()
DateTime timeKey = CurrentData.Time();
var value = CurrentData.Volume();
public override void Complete()
public override void OnPaintChart(object sender, PaintChartEventArgs args)
if (CurrentData.Count < 2 && values.Count == 0)
args.Graphics.SetClip(args.Rectangle);
var barWidth = CurrentChart.GetChartPoint(CurrentData.Time(), 0).X - CurrentChart.GetChartPoint(CurrentData.Time(1), 0).X;
var curValues = values.Where(s => s.Key >= CurrentChart.GetTimePrice(0, 0).Time && s.Key <= CurrentChart.GetTimePrice(args.Rectangle.Width, 0).Time);
if (curValues == null || curValues.Count() == 0)
var h = args.Rectangle.Height * (zoneHeight) / 100;
var k = h / curValues.Max(x => x.Value);
foreach (var v in curValues)
PointF p = CurrentChart.GetChartPoint(v.Key, v.Value);
var height = (float)(v.Value * k);
var width = barWidth * 3 / 4;
args.Graphics.FillRectangle(histBrush, p.X + barWidth / 8, args.Rectangle.Height - height, width, height);
var dispayString = v.Value.ToString();
var size = args.Graphics.MeasureString(dispayString, font);
if (size.Width < width && size.Height < height)
args.Graphics.DrawString(dispayString, font, fontBrush, p.X + barWidth / 2, args.Rectangle.Height - height / 2, stringFormat);