Trendline Class
Draws a trendline on a chart through two points. The points may be time-based (DTPoint) or bar number-based (BNPoint). Appearance may altered and an alert enabled using appropriate properties. Trendlines are often used to track market direction and identify breakouts. To use this in an analysis technique, be sure that it is setup as described in About Drawing Objects.
A trendline may be created and drawn from the Close of 20 bars ago to the Close of the last bar on the chart as follows:
using elsystem.drawingobjects;
using elsystem.drawing;
vars: CurrBarNum(0), TrendLine myTrendLine1(null), BNPoint myBNPoint1(null), BNPoint myBNPoint2(null);
once( LastBarOnChartEx )
begin
CurrBarNum = CurrentBar + MaxBarsBack - 1;



// create a bar number for the current bar
myBNPoint1 = BNPoint.Create( CurrBarNum - 20, Close[20] );



// create a starting point 20 bars to the left
myBNPoint2 = BNPoint.Create( CurrBarNum, Close );










// create an ending point at current bar
myTrendLine1 = TrendLine.create(myBNPoint1,myBNPoint2);
// create an instance of a trendline object based on two bar number points
myTrendLine1.Persist = True;













// trendline remains on screen after tick refreshes
myTrendLine1.Color = Color.Red;











// trendline color will be default color if not set by code
myTrendLine1.Style = 2;
















// trendline will be drawn as a dotted line
DrawingObjects.Add(myTrendLine1);









// plot the trendline on the chart
end;
Note that the Persist property in the above example, as well as additional properties, methods, and events not listed below, are inherited from DrawingObject.
You can also create the above trendline without needing to define BNPoint objects by directly specifying the BNPoint values when creating the trendline instance)
myTrendLine1 = TrendLine.Create(BNPoint.Create(barnumber-20,close[20]),BNPoint.Create(barnumber,close));
Namespace: elsystem.drawingobjects
| |
Name |
Description |
|
Create() |
Initializes a new instance of the class. |
|
Create(DTPoint, DTPoint) |
Initializes a new instance of the Trendline class. The first parameter is a DTPoint object representing the start point of the line; the second parameter is a DTPoint object representing the end point of the line. |
|
Create(DTPoint, DTPoint, int) |
Initializes a new instance of the Trendline class. The first parameter is a DTPoint object representing the start point of the line; the second parameter is a DTPoint object representing the end point of the line, and the third parameter is an integer representing the data number (data1 - 50). |
|
Create(BNPoint, BNPoint) |
Initializes a new instance of the Trendline class. The first parameter is a BNPoint object representing the start point of the line; the second parameter is a BNPoint object representing the end point of the line. |
|
Create(BNPoint, BNPoint, int) |
Initializes a new instance of the Trendline class. The first parameter is a BNPoint representing the start point of the line; the second parameter is a BNPoint object representing the end point of the line, and the third parameter is an integer representing the data number (data1 - 50). |
|
GetValue(DateTime) |
Returns the value of the TrendLine as of the specified DateTime. The value is scaled by PriceScale if in a subgraph other than the subgraph of the data stream on which the study is based. |
|
GetValue(BarNumber) |
Returns the value of the TrendLine as of the specified bar number. The value is scaled by PriceScale if in a subgraph other than the subgraph of the data stream on which the study is based. |
|
GetValueUnscaled( DateTime DateTime ) |
Returns the value of the TrendLine at the specified DateTime. |
|
GetValueUnscaled( int BarNumber ) |
Returns the value of the TrendLine as of the specified bar number. |
|
SetEndPoint(DTPoint) |
Sets the TrendLine end point using a DTPoint object. |
|
SetEndPoint(BNPoint) |
Sets the TrendLine end point using a BNPoint object. |
|
SetStartPoint(DTPoint) |
Sets the TrendLine start point using a DTPoint object. |
|
SetStartPoint(BNPoint) |
Sets the TrendLine start point using a BNPoint object. |