AddLine()

View as Markdown

Definition

Adds line objects on a chart.

Lines are ONLY visible from the UI property grid when AddLine() is called from State.SetDefaults. If your indicator or strategy dynamically adds lines during State.Configure, you will NOT have an opportunity to select the line or to set the line configuration via the UI. Alternatively, you may use custom public Brush, Stroke or value properties which are accessible in the State.SetDefaults and pass those values to AddLine() during State.Configure. Calling AddLine() in this manner should be reserved for special cases. Please see the examples below.

Methods and Properties

PropertyDescription
AreLinesConfigurableDetermines if the line(s) used in an indicator are configurable from within the indicator dialog window.
Line ClassObjects derived from the Line class are used to characterize how an oscillator line is visually displayed (plotted) on a chart.
LinesA collection holding all of the Line objects that define the visualization characteristics oscillator lines of the indicator.

Syntax

AddLine(Brush brush, double value, string name)

AddLine(Stroke stroke, double value, string name)

This method should ONLY be called within the OnStateChange() method during State.SetDefaults or State.Configure

Parameters

ParameterDescription
brushA Brush object used to construct the line
nameA string value representing the name of the line
strokeA Stroke object used to construct the line
valueA double value representing the value the line will be drawn at

Examples

Defining a single UI configurable static line

1protected override void OnStateChange()
2{
3 if (State == State.SetDefaults)
4 {
5 Name = "Examples Indicator";
6 // Adds an oscillator line at a value of 30
7 AddLine(Brushes.Gray, 30, "Lower");
8 }
9}

Indicator which dynamically adds a line in State.Configure

1protected override void OnStateChange()
2{
3 if (State == State.SetDefaults)
4 {
5 Name = "Examples Indicator";
6
7 // logical property which user can set
8 UseSpecialMode = false;
9 // Default brush selection pushed to the UI
10 MyBrush = Brushes.Red;
11 }
12 else if (State == State.Configure)
13 {
14 // if user enables logical property
15 if (UseSpecialMode)
16 {
17 // add line using default selected brush and special line name
18 AddLine(MyBrush, 40, "My Special Line");
19 }
20 else
21 {
22 // otherwise use default selected brush and regular line name
23 AddLine(MyBrush, 60, "My Regular Line");
24 }
25 }
26}
27
28[XmlIgnore]
29public Brush MyBrush { get; set; }
30
31public bool UseSpecialMode { get; set; }