Drawing challenge  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Antny
Posts: 13
Joined: 31 Jul 2014
Has thanked: 3 times

Drawing challenge

Postby Antny » 23 Sep 2014

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

Antny
Posts: 13
Joined: 31 Jul 2014
Has thanked: 3 times

Re: Drawing challenge

Postby Antny » 23 Sep 2014

6 views so far and still nobody knows how to use the custom drawing interface.

Antny
Posts: 13
Joined: 31 Jul 2014
Has thanked: 3 times

Re: Drawing challenge

Postby Antny » 24 Sep 2014

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.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Drawing challenge

Postby Andrew MultiCharts » 25 Sep 2014

Hello Antny,

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

Code: Select all

context.DrawRect == context.FullRect)

Antny
Posts: 13
Joined: 31 Jul 2014
Has thanked: 3 times

Re: Drawing challenge

Postby Antny » 25 Sep 2014

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.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Drawing challenge  [SOLVED]

Postby Andrew MultiCharts » 26 Sep 2014

Please try the attached file.
Attachments
NewTest_CustomDraw_Modify.pln
(1.6 KiB) Downloaded 502 times

Antny
Posts: 13
Joined: 31 Jul 2014
Has thanked: 3 times

Re: Drawing challenge

Postby Antny » 26 Sep 2014

Please try the attached file.
It works! Awesome! Thanks Andrew. This is quite helpful.


Return to “MultiCharts .NET”