In this tutorial, we will delve into the parameters of the plot()
function in Pine Script Version 5, ensuring a comprehensive understanding of its features and applications.
Overview of plot()
Parameters
Mandatory Parameter: series
- Description: The
series
parameter is the only compulsory one in theplot()
function. - Type: Must be of “series int/float” type.
- Auto-casting Rules: Pine Script follows a casting hierarchy: int → float → bool. Thus, a “bool” type variable must be converted to an “int” or a “float” to be used in
plot()
. - Example: If
isNewDay
is a “bool” type, useisNewDay ? 1 : 0
to plot 1 when true and 0 when false.
Optional Parameters
1. title
- Type: “const string”
- Usage: Appears in various UI elements like the script’s scale, Data Window, and “Settings/Style” tab.
- Compile Time: Must be known at compile time.
2. color
- Type: “series color”
- Flexibility: Can be calculated dynamically, bar by bar.
3. linewidth
- Application: Refers to the size of the plotted element, primarily in pixels for line styles.
4. style
- Variants: Includes
plot.style_line
,plot.style_linebr
,plot.style_stepline
,plot.style_area
,plot.style_areabr
,plot.style_columns
,plot.style_histogram
,plot.style_circles
, andplot.style_cross
. - Purpose: Determines the visual representation style of the plot.
5. trackprice
- Default:
false
- Functionality: When
true
, plots a dotted line across the script’s visual space.
6. histbase
- Role: Serves as a reference point in certain plot styles.
- Type: “input int/float”
7. offset
- Purpose: Shifts the plot in time (past/future).
- Type: Integer representing the offset in bars.
8. join
- Applicability: Only for
plot.style_circles
orplot.style_cross
. - Function: Joins shapes with a line when set to
true
.
9. editable
- Default:
true
- Control: Allows editing of plot properties in the “Settings/Style” tab.
10. show_last
- Usage: Controls the visibility of the last bars in the plotted values.
- Type: “input int”
11. display
- Default:
display.all
- Options: Includes
display.none
, useful for invisible plots used as external inputs or inalertcondition()
calls.
Key Features and Takeaways
- Mandatory vs Optional:
series
is the only mandatory parameter, makingplot()
highly customizable with optional parameters. - Type Specificity: Each parameter has a specific type requirement, ensuring precision in plotting.
- Styling Flexibility: Multiple style options cater to different visual preferences and data representation needs.
- Dynamic Calculations: Parameters like
color
can be dynamically calculated, offering flexibility in plotting different conditions. - Visibility Control: Features like
show_last
anddisplay
provide control over the plot’s visibility and impact on the script’s visual space.
By understanding these parameters and their applications, you can effectively utilize the plot()
function in Pine Script to create insightful and visually appealing indicators and strategies on TradingView.