slope (int Type, vars Data, int TimePeriod) : var

Connects the two highest maxima or lowest minima of the Data series within the given TimePeriod, and returns the slope of the connecting line. This function can be used to calculate traditional divergence or convergence (triangle) patterns.


Type PEAK for a line through the maxima, VALLEY for a line through the minima.
Data Time series.
TimePeriod Period to be examined.


Slope (movement per bar, positive for a rising, negative for a falling line), or 0 if the series is flat or no minima/maxima are found.


rMin, rMinIdx - value and bar offset of the lower connecting point.
rMax, rMaxIdx - value and bar offset of the higher connecting point.

line (int Offset) : var

Returns the value of a straight line at the bar with the given Offset (0 = current bar). The line is defined as connecting the rMin, rMinIdx, rMax, rMaxIdx coordinates which can be either set directly, or generated with slope or with Min/Max/MinIndex/MaxIndex


Offset Bar offset


Value of the line at the given Offset.



var HighsDn[10] = { 1,1,1,2,1,1,1,3,1,1 }; // mind the reverse order
var LowsUp[10] = { 1,1,1,0.7,1,1,1,0.5,1,1 };

function main()
  printf("\nSlope dn %.3f",slope(PEAK,HighsDn,10));
  printf("\nSlope up %.3f",slope(VALLEY,LowsUp,10));

See also:

crossOver, crossUnder, rising, falling, peak, valley, peakF, valleyF, predict

► latest version online