> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Plotting

> Putting a series on the chart with plot and its styles, marking bars with plotshape, plotchar and plotarrow, drawing your own bars with plotbar and plotcandle, and the display argument.

`plot` draws one value per bar. Its relatives mark bars (`plotshape`, `plotchar`, `plotarrow`), draw candles or bars of your own
(`plotcandle`, `plotbar`) or draw a level (`hline`). For anything that is not one value on every bar, see
[Plots or drawings](https://gocharting.com/docs/scripting/chart-output/plots-or-drawings.md).

## Top level only

Every one of these calls, and `fill`, `bgcolor`, `barcolor` and `alertcondition`, must stand at the top level of the script: not in
an `if`, a loop, a `switch` or a function of yours. The editor refuses it:

```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Conditional plot")
if close > open {
    plot(close)
}
```

The compiler says: `plot()` must be called in the global scope.

Put the condition in the arguments instead. A plotted `na` leaves a gap, and a `na` color draws nothing:

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Up closes", overlay=true)
plot(close > open ? close : na, title="Up closes", style=plotStyle.cross)
```

## plot

`plot(series, title, color, linewidth, style, trackprice, histbase, offset, force_overlay, display, format)`. Only `series` is
required.

| Argument | Rule |
| - | - |
| `title` | `const string`: a literal or a constant expression, never text built from data |
| `color` | any `color`, may change on every bar; `na` draws nothing |
| `linewidth`, `style`, `histbase`, `offset` | `input` qualifier: fixed for the run, not computed per bar |
| `style` | `plotStyle.line`, `linebr`, `area`, `areabr`, `smoothedArea`, `stepLine`, `stepLinebr`, `stepArea`, `stepAreabr`, `bar`, `histogram`, `scatter`, `triangular`, `cross` |
| `force_overlay` | `const bool`: draw this plot on the price pane although the script is not an overlay |
| `trackprice` | accepted and has no effect |

A computed `linewidth` is refused (`An argument of `series int`type was used but a`input int` is expected.`). To vary a plot's look by bar, vary its `color`, or plot twice with different arguments.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Close and average", overlay=true)
avg = talib.sma(close, 20)
plot(close, title="Close", color=color.gray)
plot(avg, title="Average", color=close > avg ? color.green : color.red, linewidth=2)
```

`plot` returns a plot value that [`fill`](https://gocharting.com/docs/scripting/chart-output/fills-and-levels) accepts.

## Where a plot is shown: display and format

`display` takes `display.none`, `pane`, `data_window`, `price_scale`, `status_line` or `all` (the default); add constants with `+`:
`display=display.pane + display.price_scale`. It is an argument of every call on this page and of `fill`, `bgcolor`, `barcolor` and
the inputs; the terminal decides what each place shows. `fill`, `barcolor` and `bgcolor` take only `display.none` and `display.all`
(see [Fills and levels](https://gocharting.com/docs/scripting/chart-output/fills-and-levels.md)).

`format` on `plot`, `plotshape`, `plotchar`, `plotarrow` and `hline` takes `format.price`, `format.percent` or `format.volume`. The
editor accepts `format.mintick` and `format.inherit`; adding the script to the chart refuses them:

```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Format")
plot(close, format=format.mintick)
```

The compiler says (when added to the chart): The `format` argument only accepts format.price, format.percent, or format.volume. Got `format.mintick`.

## Marks on bars

* `plotshape(series, title, shape, location, color, offset, text, textcolor, size, force_overlay, display, format)` draws a shape on
  each bar where the `bool` series is true. `shape` is `shape.xcross`, `cross`, `triangleup`, `triangledown`, `flag`, `circle`,
  `arrowup`, `arrowdown`, `labelup`, `labeldown`, `square` or `diamond`; `location` is `location.abovebar`, `belowbar`, `top`,
  `bottom` or `absolute`; `size` is `size.auto`, `tiny`, `small`, `normal`, `large` or `huge`. Given a `float` series instead, it
  draws at that price, and a `na` draws nothing.
* `plotchar` is the same with `char`, one character (`const string`) instead of `shape`; a longer string is cut to its first
  character.
* `plotarrow(series, title, colorup, colordown, offset, minheight, maxheight, force_overlay, display, format)` draws an arrow up for a
  positive value and down for a negative one, sized by the value.
* `text` is a `const string`; see [Text and markers](https://gocharting.com/docs/scripting/chart-output/text-and-markers.md).

```lipi wrap theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Marks", overlay=true)
plotshape(close > open and volume > talib.sma(volume, 20), title="Strong up", shape=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotarrow(close - open, colorup=color.green, colordown=color.red)
```

## Your own bars and a level

`plotcandle(open, high, low, close, title, color, wickcolor, bordercolor, force_overlay, display)` and `plotbar(open, high, low,
close, title, color, display, force_overlay)` draw bars from four series; all four are required. `hline(price, title, color,
linewidth, style, display, format)` draws a horizontal line; `price` is an `input` value (see
[Fills and levels](https://gocharting.com/docs/scripting/chart-output/fills-and-levels.md)): `plotcandle(talib.sma(open, 3), talib.sma(high, 3), talib.sma(low, 3), talib.sma(close, 3))`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.