Home » Box Functions » Understanding the box.get_bottom() Function in Pine Script

Understanding the box.get_bottom() Function in Pine Script

Photo of author
Published on

This article will delve into the syntax, usage, and application of the box.get_bottom() function, providing you with practical examples and insights to enhance your Pine Script programming skills.

Syntax and Arguments

The syntax for the box.get_bottom() function is straightforward:

box.get_bottom(id) → series float

Arguments:

  • id (series box): This is the identifier of the box object from which you want to retrieve the bottom border’s price value. It’s essential to have created a box object earlier in your script to use this function effectively.

Returns:

  • The function returns a series of float values, representing the price value at the bottom border of the specified box.

Example

Let’s look at a practical example to see how the box.get_bottom() function can be used in a Pine Script:

//@version=5
indicator("Box Bottom Example", overlay=true)
int lookbackPeriod = 20 
var box highlightArea = na
float highestHigh = ta.highest(high, lookbackPeriod)
float lowestLow = ta.lowest(low, lookbackPeriod)
if (na(highlightArea))
    highlightArea := box.new(left=bar_index[lookbackPeriod], right=bar_index, top=highestHigh, bottom=lowestLow, border_color=color.red, bgcolor=color.new(color.red, 90))
else
    box.set_left(highlightArea, bar_index[lookbackPeriod])
    box.set_right(highlightArea, bar_index)
    box.set_top(highlightArea, highestHigh)
    box.set_bottom(highlightArea, lowestLow)
float bottomPrice = box.get_bottom(highlightArea)
plot(series=bottomPrice, title="Bottom Price", color=color.red)
Example

Explanation:

  1. Indicator Declaration: indicator("Box Bottom Example", overlay=true) declares a new indicator named “Box Bottom Example” that will be drawn over the price chart (overlay=true).
  2. Variables Initialization:
    • lookbackPeriod = 20: Sets the lookback period to 20 bars/candles.
    • box highlightArea = na: Initializes a variable to store the box object. Initially, it’s set to “na” (not available).
    • highestHigh and lowestLow: Calculate the highest and lowest prices within the lookback period, respectively.
  3. Box Creation or Update:
    • If highlightArea is not available (na), a new box is created using box.new() with the left and right borders set to the current bar index minus the lookback period and the current bar index, respectively. The top and bottom are set to the highest and lowest prices within the lookback period. The box’s border and background colors are set to red, with the background having 90% transparency.
    • If highlightArea already exists, its dimensions are updated with new values for left, right, top, and bottom edges using the box.set_left(), box.set_right(), box.set_top(), and box.set_bottom() functions.
  4. Plotting Bottom Price:
    • bottomPrice = box.get_bottom(highlightArea): Retrieves the bottom edge price of the current highlightArea box.
    • plot(series=bottomPrice, title="Bottom Price", color=color.red): Plots the bottom price as a red line on the chart, providing a visual reference for the lowest price within the highlighted area for the lookback period.

Key Features and Takeaways

  • Function Usability: The box.get_bottom() function is specifically designed for extracting the bottom price value of a box object in Pine Script. This feature is particularly useful for visual analysis and automated trading strategies that require precise information about price ranges marked by boxes on the chart.
  • Syntax and Application: Understanding the syntax is crucial. The function requires a box object identifier as an argument and returns a series of float values representing the bottom price value of the box.
  • Practical Use Cases: This function can be utilized in various trading strategies and analytical tasks. For instance, traders might use boxes to highlight specific price ranges of interest (like support or resistance levels) and use the box.get_bottom() function to programmatically monitor or react when the price approaches these levels.

Leave a Comment