ITextObject question  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
fx1
Posts: 26
Joined: 20 Mar 2013

ITextObject question

Postby fx1 » 11 Jul 2013

I am trying to put a status line like textobject to chart. I do this on LastBarOnChart and draw it like seen here:

Code: Select all

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

namespace PowerLanguage.Indicator{

public class TextLine
{
private Dictionary<string,string> DATA = new Dictionary<string,string>();

public TextLine() {}

public void Line(string Key,string Value)
{
DATA[Key]=Value;
}


public override string ToString()
{
string o="";
foreach(var x in DATA.Values) o+=x+"\r\n";
return(o);
}
}

[RecoverDrawings(true)]
public class TextObject_Example1 : IndicatorObject {
public TextObject_Example1(object _ctx):base(_ctx){}

private ITextObject TXT1;
private TextLine TL = new TextLine();
protected override void Create() { }
protected override void StartCalc() {}

protected override void CalcBar(){
// indicator logic
if (Bars.LastBarOnChart)
{
TL.Line("First","First Line");
TL.Line("Second","Second Line");

TXT1 = DrwText.Create(new ChartPoint(Bars.TimeValue.AddMinutes(10)
,Bars.HighValue),TL.ToString());
}
}
}
}
Now i am in a dillemma. MC.NEt seems to put the TXTOBJ per chart new. So if Bar changes i get new object on chart and i need to

a) either detect that bar has been changed
b) or must know to which bar the text object belongs to

a kind of .Tag would be great to have like in c# on all objects. This way i could Tag the object.

The code

foreach(var x in DrwText.GetTextObjects()) x.Delete();

deletes all objects and creates new one but i figured that this command does delete objects from all studies, so if i have 2 different study then they will write objects from eachother. This problem appears because i am trying to put the statustext to a fixed area in Chart and i have no clue which TXTOBJ belongs to previous bar (so i can delete it).

Every idea to solve this problem is welcome. Attached the code and how it looks on chart.

thank you
Attachments
to.png
(98.93 KiB) Downloaded 984 times

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

Re: ITextObject question  [SOLVED]

Postby Henry MultiСharts » 17 Jul 2013

Hello fx1,

That is possible to declare the drawing once and then just replace it.
Try this code:

Code: Select all

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

namespace PowerLanguage.Indicator{

public class TextLine
{
private Dictionary<string,string> DATA = new Dictionary<string,string>();

public TextLine() {}

public void Line(string Key,string Value)
{
DATA[Key]=Value;
}


public override string ToString()
{
string o="";
foreach(var x in DATA.Values) o+=x+"\r\n";
return(o);
}
}

[RecoverDrawings(true)]
public class TextLine : IndicatorObject {
public TextLine(object _ctx):base(_ctx){}

private ITextObject TXT1;
private TextLine TL = new TextLine();
protected override void Create() { }
protected override void StartCalc() {}

protected override void CalcBar(){
// indicator logic

if (Bars.CurrentBar==1)
{
TL.Line("First","First Line");
TL.Line("Second","Second Line");

TXT1 = DrwText.Create(new ChartPoint(Bars.TimeValue.AddMinutes(10)
,Bars.HighValue),TL.ToString());

TXT1.HStyle = ETextStyleH.Right;

}

if (Bars.LastBarOnChart)
{
ChartPoint cp = new ChartPoint(Bars.TimeValue, Bars.CloseValue);
TXT1.Location = cp;
}
}
}
}

User avatar
fx1
Posts: 26
Joined: 20 Mar 2013

Re: ITextObject question

Postby fx1 » 17 Jul 2013

I appreciate your reply, helped me a lot


Return to “MultiCharts .NET”