Parent: Object
The TrendLine class represents a line defined by two index/value coordinates. TrendLine instances are commonly generated by PeakTroughCalculator methods such as GetLowerTrendLine and GetUpperTrendLine, but you can also create one directly from two arbitrary points. When constructed from a collection of PeakTrough instances, the TrendLine represents the best-fit linear regression line through those points rather than simply connecting the first and last PeakTrough.
The first constructor creates a TrendLine from a collection of PeakTrough instances. The PeakTroughs are first sorted by XIndex. WealthLab then calculates a best-fit regression line through the points. If semiLog is false, a standard linear best-fit calculation is used. If semiLog is true, a logarithmic Y-axis best-fit calculation is used. The resulting TrendLine's Index1 and Index2 correspond to the X indices of the first and last PeakTroughs. Value1 and Value2 contain the regression line's values at those two indices. The constructor also calculates Deviation, which measures how closely the supplied PeakTroughs fit the regression line. The second constructor creates a TrendLine directly from the two supplied coordinates. In this case, Deviation remains at its default value of 0.
Returns the average percentage distance between the PeakTrough points used to construct the TrendLine and the calculated best-fit regression line. For each PeakTrough, WealthLab calculates:
Abs(PeakTroughValue - RegressionValue) * 100 / PeakTroughValue
Deviation is the average of these percentage differences. A lower Deviation indicates that the PeakTroughs lie more closely along the calculated TrendLine. When the TrendLine is created directly from two index/value coordinates, Deviation defaults to 0.
Extends the TrendLine to an arbitrary X-axis index and returns the corresponding Y-axis value.
Set useLog to true to extend the line using logarithmic Y-axis calculations.
Normally, useLog should correspond to the type of TrendLine being represented. For example, if the TrendLine was constructed using semiLog: true, use logarithmic extension as well.
The X-axis index of the TrendLine's first, or left, point. For a TrendLine created from PeakTroughs, this corresponds to the XIndex of the earliest supplied PeakTrough.
The X-axis index of the TrendLine's second, or right, point. For a TrendLine created from PeakTroughs, this corresponds to the XIndex of the latest supplied PeakTrough.
Returns true if the TrendLine is falling from left to right. Equivalent to:
Value1 > Value2
Returns false for a flat or rising TrendLine.
Returns true if the TrendLine is rising from left to right. Equivalent to:
Value2 > Value1
Returns false for a flat or falling TrendLine.
Returns the slope of the TrendLine. For a normal linear TrendLine, the slope is calculated as:
(Value2 - Value1) / (Index2 - Index1)
If useLog is true, the logarithmic slope is calculated as:
Log10(Value2 / Value1) / (Index2 - Index1)
The logarithmic form is useful when working with semi-logarithmic price charts or TrendLines constructed with semiLog: true.
Returns a string representation of the TrendLine containing its two coordinates. The format is:
[Index1;Value1][Index2;Value2]
The values are formatted to eight decimal places.
The Y-axis value of the TrendLine's first, or left, point. When the TrendLine is constructed from PeakTroughs, this is the best-fit regression value at Index1, not necessarily the actual value of the first PeakTrough.
The Y-axis value of the TrendLine's second, or right, point. When the TrendLine is constructed from PeakTroughs, this is the best-fit regression value at Index2, not necessarily the actual value of the final PeakTrough.