Code: Select all
using System;
using System.Drawing;
using PowerLanguage.Function;
using System.Drawing.Drawing2D;
namespace PowerLanguage.Indicator
{
public class NewTest_CustomDraw : IndicatorObject, IChartCustomDrawer
{
public NewTest_CustomDraw( object _ctx ) : base(_ctx)
{
}
protected override void Create()
{
ChartCustomDraw.Register( this );
}
protected override void StartCalc()
{
}
protected override void CalcBar()
{
ChartCustomDraw.ReDraw();
}
protected override void Destroy()
{
ChartCustomDraw.Unregister( this );
}
void IChartCustomDrawer.Draw( DrawContext context, EDrawPhases phase )
{
if (Bars.LastBarOnChart)
{
if (phase == EDrawPhases.BeforeFGShapes && context.DrawRect == context.FullRect)
{
Diamond g = new Diamond();
PointF one = context.Environment.ChartPoint2Point(new ChartPoint { Price = Bars.Low[0], Time = Bars.Time[0] });
PointF two = context.Environment.ChartPoint2Point(new ChartPoint { Price = Bars.High[10], Time = Bars.Time[10] });
PointF three = context.Environment.ChartPoint2Point(new ChartPoint { Price = Bars.Low[27], Time = Bars.Time[27] });
PointF four = context.Environment.ChartPoint2Point(new ChartPoint { Price = Bars.High[49], Time = Bars.Time[49] });
g.RenderPoly(context.graphics, one, two, three, four);
}
}
}
}
public class Diamond
{
public Diamond()
{
}
public void RenderPoly(Graphics g, PointF x, PointF a, PointF b, PointF c)
{
PointF[] setPoints = new PointF[] {x, a, b, c};
g.FillPolygon(Brushes.AliceBlue, setPoints);
}
}
}