1. Home
2. Functions
3. thinkScript plot() Function (With Examples)

# thinkScript plot() Function (With Examples)

The plot() function in thinkScript is the most repeatedly used function to render and display data on your chart.

In fact, the template that you start with when creating a new custom ThinkorSwim indicator begins with plot Data = close;

That shows how important the plot() function is in thinkScript.

In today’s guide, I will explain how the plot function works and share a few coding examples with you.

Contents

## thinkScript Plot()

When you want to output data from your indicator or backtesting strategy, you employ the plot() function.

Exampl #1: Plot a simple moving average

```input price = close;
input length = 9;
plot SMA = Average(price, length);
```

This script simply plots a 9-period simple moving average on your chart.

Example #2: Plot implied volatility

```declare lower;
plot ImpVol = IMP_VOLATILITY();
```

If you want to show the implied volatility of the stock, you can start with `plot` and insert the `IMP_VOLATILITY()` function.

Example #3: Plot highest high and lowest low

```plot highestHigh = highest(high, 22);
plot lowestLow = lowest(low, 22);
```

The code above plots the highest highs and lowest lows of the last 22 candles.

It’s really that easy! You only need two main components.

Start by writing the required `series` argument and then use the `plot()` function to render the specified data on the chart.

Sometimes, you may not like how thinkScript presents the data on your chart. Certain values require a different set of styles.

By default, the plot function is always displayed as a regular line.

In order to change the style of your plot, you will need to use the SetPaintingStrategy constant.

### Histogram plot

Indicators like volume, which shows the distribution of values, might be better suited to be shown as a histogram rather than a line.

Without changing anything from your plot function, you can utilize the SetPaintingStrategy constant to change the style from a line to a histogram.

```declare lower;
plot Vol = volume;
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
```

### Arrows plot

In some indicators, you will need to use a particular plotting style.

In the following script, I plot arrows on my chart to quickly identify when a 3-consecutive green bars pattern occurs.

```def IsUp = close > open;
plot greenBars = if IsUp and IsUp and IsUp then low else double.nan;
greenBars.SetPaintingStrategy(paintingStrategy.ARROW_UP);
```

## Conclusion

The plot() function is thinkScript is very flexible.

You can declare the plot first and then define its value afterward or vice versa.

To top it off, you can use different colors and styling options to make the plot more visible on your chart.

## Unlock the Power of ThinkorSwim

Get the latest news and updates on TD Ameritrade, ThinkorSwim indicators, thinkScript tutorials, and trading strategies delivered straight to your inbox every week.

We don’t spam! Unsubscribe at anytime.

## 2 thoughts on “thinkScript plot() Function (With Examples)”

1. Chaz Frank says:

I took a shot in the dark with the email address since I could not find one on your website. Needless to say it bounced, so thought I’d try this.

I used your vertical line example as a template, but cannot seem to get it to work. My code below… The intent is to post event markers on charts when various markets open, close, lunch break/return

### cfMktMarkers: FOREX Market Markers
# Template: AddVerticalLine(secondstilltime(1345)==0, “title”, color.red, curve.firm);

AddVerticalLine(secondstilltime(1800)==0, “Forex open; NZX open”, color.green, curve.short_dash);
AddVerticalLine(secondstilltime(2000)==0, “ASX JPX open”, color.green, curve.short_dash);
AddVerticalLine(secondstilltime(2130)==0, “HKEX SSE open”, color.green, curve.short_dash);
AddVerticalLine(secondstilltime(0200)==1, “ASX JPX close”, color.red, curve.short_dash);
AddVerticalLine(secondstilltime(0300)==0, “STG JSE MOEX FWB SIX LSE open”, color.green, curve.short_dash);
AddVerticalLine(secondstilltime(0930)==0, “USA TSE open”, color.green, curve.short_dash);
2. Eli Elgaza says: