Page 1 of 1

Drawing challenge

Posted: Sep 23 2014
by Antny
I have been working with the custom drawing method and so far no luck. I am trying to render a simple filled polygon (specifically a trapezoid). I show no errors in the code, but it still will not render anything on the chart. So, here is my challenge. Can anyone show me why this code is not working correctly?

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);
}
}
}

Re: Drawing challenge

Posted: Sep 23 2014
by Antny
6 views so far and still nobody knows how to use the custom drawing interface.

Re: Drawing challenge

Posted: Sep 24 2014
by Antny
Still nothing. Hmmm. I admit, I am a bit surprised. I figured at least one of the moderators would have addressed this issue. Why? Because this would solve pretty much every problem dealing with any non-standard drawings on a chart. If the DrawPolygon() and FillPolygon() methods can be utilized, then people can draw anything.

Re: Drawing challenge

Posted: Sep 25 2014
by Andrew MultiCharts
Hello Antny,

Please try not to check the following condition and see how it works:

Code: Select all

context.DrawRect == context.FullRect)

Re: Drawing challenge

Posted: Sep 25 2014
by Antny
Hello Antny,

Please try not to check the following condition and see how it works:

Code: Select all

context.DrawRect == context.FullRect)

No errors, and no drawing.

Re: Drawing challenge  [SOLVED]

Posted: Sep 26 2014
by Andrew MultiCharts
Please try the attached file.

Re: Drawing challenge

Posted: Sep 26 2014
by Antny
Please try the attached file.
It works! Awesome! Thanks Andrew. This is quite helpful.