Home » Technical Analysis Functions » ta.lowest Function in Pine Script

ta.lowest Function in Pine Script

Photo of author
Published on

One such function that plays a pivotal role in identifying the lowest value over a specific period is ta.lowest. Let’s delve deep into this function and see how you can use it to enhance your trading scripts.

Syntax & Overloads

Before we dive into real-world examples, it’s essential to understand the syntax and the different overloads of the ta.lowest function.

1. Single Argument Version

ta.lowest(length) → series float

When used with a single argument, ta.lowest considers the low of the candlestick bars as the default source series. The argument length specifies the number of bars back from which the lowest value needs to be found.

2. Two Arguments Version

ta.lowest(source, length) → series float

In this version, two arguments are provided: source and length. The source denotes the series from which the lowest value needs to be extracted. The length specifies the number of bars back.

Arguments Explained

  • length (type: simple int): This represents the number of bars back from which the lowest value needs to be identified.
  • source (type: series): This represents the series (like close, open, or any custom series) from which the lowest value should be extracted. This argument is optional in the single argument version, as the default source is the low of the bars.

Key Points to Remember

  1. If the source series contains na values, they are ignored by the ta.lowest function. This ensures that the function always returns a meaningful result.
  2. The single argument version of ta.lowest uses the low of the bars as the default source series.

A Unique Use Case: Identifying a Potential Buy Signal

To demonstrate the power of the ta.lowest function, let’s create a unique scenario. Suppose we want to generate a potential buy signal when the current closing price is the lowest in the past 20 bars. This could indicate a potential reversal point.

Here’s how you can achieve this using Pine Script:

//@version=5
indicator("Lowest Close Indicator", overlay=true)

length = 100
lowestClose = ta.lowest(close, length)

plotshape(series=close == lowestClose, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
ta.lowest Function in Pine Script

Code Breakdown:

  1. //@version=5: This specifies that we are using Pine Script version 5.
  2. indicator("Lowest Close Indicator", overlay=true): We’re defining a new indicator, and overlay=true ensures that it’s overlaid on the price chart.
  3. length = 100: We’re defining a variable length and setting its value to 100, meaning we want to check the past 100 bars.
  4. lowestClose = ta.lowest(close, length): Here, we’re using the ta.lowest function to find the lowest closing price in the past 100 bars.
  5. plotshape(...): This function is used to plot a shape (in this case, a label with the text “Buy”) below the bar whenever the current closing price is the lowest in the past 20 bars.

By implementing the above script, you’ll see a “Buy” label below the bars that have the lowest closing price in the past 20 bars.

Key Takeaway

The ta.lowest function in Pine Script is a powerful tool for traders and script developers to identify the lowest value over a specific period. Whether you’re considering the low of the bars or any other custom series, ta.lowest helps in making accurate and data-driven trading decisions.

Conclusion

Understanding the intricacies of built-in functions like ta.lowest is crucial for anyone keen on developing robust and efficient trading scripts in Pine Script. By mastering this function, you can not only enhance your trading strategies but also gain deeper insights into potential market reversals and opportunities. Happy coding and trading!

Leave a Comment