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