Home » Drawing On Charts » Understanding shape.labelup in Pine Script

Understanding shape.labelup in Pine Script

Photo of author
Published on

The plotshape function is a versatile tool for this purpose, and one of its parameters allows you to specify the shape style. In this article, we’ll delve into the shape.labelup style, a constant string type, and its application within the plotshape function.

Introduction to shape.labelup

What is shape.labelup?

shape.labelup is a predefined constant in Pine Script that represents a specific shape style used with the plotshape function. This style plots a label pointing upwards, which is particularly useful for marking conditions or signals where an upward movement or action is anticipated. It’s visually distinct, making it easy to identify specific points on a chart.

Syntax and Usage

The shape.labelup constant is used as an argument in the plotshape function. Here’s a simplified syntax to illustrate its usage:

plotshape(series, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small)

Example

Let’s create a basic example to demonstrate the use of shape.labelup. We’ll plot an upward-pointing label every time the closing price of an asset crosses above its 20-period simple moving average (SMA).

Step-by-Step Code

  1. Define the SMA: First, calculate the 20-period SMA.
//@version=5
indicator("My SMA Cross Label", overlay=true)
sma20 = ta.sma(close, 20)
  1. Condition for Label Plotting: Define a condition when the closing price crosses above the SMA.
crossAbove = ta.crossover(close, sma20)
  1. Plot the Shape: Use plotshape with shape.labelup to mark the crossover points.
plotshape(crossAbove, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small, title="SMA Cross Up")
Example

Explanation of Each Line

  • The ta.sma function calculates the simple moving average based on the closing price and the specified period (20 in this case).
  • ta.crossover checks if the closing price has crossed above the SMA, returning true when it does.
  • plotshape plots an upward-pointing label below the bar whenever the crossAbove condition is true. We specify the shape style as shape.labelup, choose a color, and set the size.

Key Features and Takeaways

  • Function Usability: shape.labelup is used with plotshape to visually indicate upward momentum or conditions. It’s useful for highlighting specific chart patterns, signals, or conditions that suggest an upward move.
  • Syntax and Application: The constant is straightforward to apply within the plotshape function, requiring only the specification of the style parameter as shape.labelup. It allows for customization of the visual representation through additional parameters like color, location, and size.
  • Visual Aid in Trading: This shape style serves as an excellent visual cue for traders, making it easier to spot potential trading opportunities based on the criteria set in the script.

Utilizing shape.labelup in Pine Script enhances the visual analysis of charts, making it an invaluable tool for traders and analysts who rely on custom indicators and scripts in TradingView.

Leave a Comment