I will give a simple example which will draw a trendline on every high. If 10 highs are drawn, the code should delete the first one and draw a new one when a new bar appears.
The problem is I cannot find a way to specify which trendline to delete.
Code: Select all
using System;
using System.Drawing;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class ST_Lines : IndicatorObject
{
public ST_Lines(object _ctx)
: base(_ctx)
{}
private int count_lines = 1;
private VariableSeries<ITrendLineObject> high_trendline;
protected override void Create()
{
high_trendline = new VariableSeries<ITrendLineObject>(this);
}
protected override void StartCalc()
{
high_trendline.DefaultValue = null;
}
protected override void CalcBar()
{
if (Bars.Status == EBarState.Close)
{
if (count_lines <= 10)
{
high_trendline.Value = DrwTrendLine.Create(new ChartPoint(Bars.Time[1], Bars.High[1]), new ChartPoint(Bars.Time[0], Bars.High[1]));
high_trendline.Value.ExtRight = true;
high_trendline.Value.Color = Color.Cyan;
count_lines++;
}
else
{
if (high_trendline.Value.ID == 1)
{
high_trendline.Value.Delete();
}
}
}
}
}
}