Lowest

Returns two values:

  1. The lowest value from a series for a given period
  2. The distance from the current bar to that value.
    0
    if it was found on the current bar,
    1
    if it was found on the previous bar, etc.
Parameter NameTypeDefault ValueNotes
valueSeries<Number>--
periodNumber--

Returns: Series<Number>, Number

Lowest is a built-in function - you can use it directly. Below is an example implementation:

1 function Lowest(value, period):
2 lowest = value
3 distanceToLowest = 0
4
5 for distance from 1 to (period - 1)
6 isNewLow = value[distance] < lowest
7 lowest = value[barIndex] if isNewLow else lowest
8 distanceToLowest = distance if isNewLow else distanceToLowest
9
10 lowest, distanceToLowest