C# - Remove Drawing from previous bar  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

C# - Remove Drawing from previous bar

Postby Jobauma » 20 May 2013

I have read that the "Delete()" method should be used, but how do you make it work?

Code: Select all

if ( curClose > prevOpen) [Remove down arrow at top from previous bar.]
Any help is appreciated. Thanks. :)

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: C# - Remove Drawing from previous bar  [SOLVED]

Postby Henry MultiСharts » 21 May 2013

Hello Jobauma,

This indicator will create three drawings on bar #10, then on bar #15 it will delete the arrow drawing.

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
public class my_drawing : IndicatorObject {
public my_drawing(object _ctx):base(_ctx){}
private VariableObject<IArrowObject> m_arrw;

protected override void Create() {

m_arrw = new VariableObject<IArrowObject>(this);
}
protected override void StartCalc() {}
protected override void CalcBar()
{
if (Bars.CurrentBar == 10)
{
ChartPoint top = new ChartPoint(Bars.TimeValue, Bars.HighValue);
ChartPoint bottom = new ChartPoint(Bars.TimeValue, Bars.LowValue);

DrwTrendLine.Create(bottom, top);
m_arrw.Value = DrwArrow.Create(bottom, false);
ITextObject textObj = DrwText.Create(top, "1");
textObj.VStyle = ETextStyleV.Above;
}
if (Bars.CurrentBar == 15) m_arrw.Value.Delete();
}
}
}

Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Re: C# - Remove Drawing from previous bar

Postby Jobauma » 22 May 2013

Many thanks. :)

Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Re: C# - Remove Drawing from previous bar

Postby Jobauma » 22 May 2013

One more question though. How can I make something happen only if an arrow gets deleted?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: C# - Remove Drawing from previous bar

Postby Henry MultiСharts » 24 May 2013

There is no built-in event "drawing deleted". You can create your own event and call it it right after calling Drawing Delete method.

AntiMatter
Posts: 60
Joined: 03 Mar 2011
Has thanked: 9 times
Been thanked: 2 times

Re: C# - Remove Drawing from previous bar

Postby AntiMatter » 10 Sep 2013

Noob Question, but how would I check that m_arrw has a value before deleting it, e.g. something like....

if (m_arrw.Value.Exist) m_arrw.Value.Delete();

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: C# - Remove Drawing from previous bar

Postby Henry MultiСharts » 12 Sep 2013

Noob Question, but how would I check that m_arrw has a value before deleting it, e.g. something like....

if (m_arrw.Value.Exist) m_arrw.Value.Delete();
Example code you have provided is correct. Are you unable to make it work?

AntiMatter
Posts: 60
Joined: 03 Mar 2011
Has thanked: 9 times
Been thanked: 2 times

Re: C# - Remove Drawing from previous bar

Postby AntiMatter » 12 Sep 2013

Oh yes, seems to work, but if I don't do some sanity checks myself, it throws this:
Attachments
Untitled.jpg
(36.06 KiB) Downloaded 3128 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: C# - Remove Drawing from previous bar

Postby Henry MultiСharts » 13 Sep 2013

Oh yes, seems to work, but if I don't do some sanity checks myself, it throws this:
AntiMatter, you are working with a variable that has not been initialized.

AntiMatter
Posts: 60
Joined: 03 Mar 2011
Has thanked: 9 times
Been thanked: 2 times

Re: C# - Remove Drawing from previous bar

Postby AntiMatter » 13 Sep 2013

Ah yes - now I am starting to get this - thanks.

jojo

Re: C# - Remove Drawing from previous bar

Postby jojo » 04 Nov 2015

Does not compile in 9.1

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: C# - Remove Drawing from previous bar

Postby Henry MultiСharts » 10 Nov 2015

Does not compile in 9.1
No problem with it on our end.


Return to “MultiCharts .NET”