Skip to content
Wildflower
Join free
Coding strategies in Pine Script

Free Trading School · Level 7 · Course 7.4

Plotting lines and shapes

Lesson 5 of 16 in Coding strategies in Pine ScriptModule 1: Pine Script basics

Advanced · Coding strategies in Pine Script

Plotting lines and shapes

Wildflower Trading School · Lesson 7.4.1.5

Wildflower

So far our scripts have drawn one plain line. Today you'll take control of what appears on the chart. By the end of this lesson, you'll know how to draw a moving average with your own name, colour and thickness. You'll also mark the candles where a rule is true, with a small shape underneath. That's the first step from a rule on paper to a signal you can see.

1 of 7

What you'll learn

  • Draw a line with plot. Give it a title, a colour and a thickness.
  • Mark candles with plotshape. It draws a shape only where your rule is true.
  • Split long lines. Indent the next line by five spaces, never a multiple of four.
  • Change the look in settings. Titles show on the Style tab, where colours can change.
  • Check marks by hand. Compare a few with the candle prices shown on the chart.

Exercise

  1. Add the Strong closes script to a 5-minute MES1! chart.
  2. Pick five triangles and check each one by hand with the OHLC numbers at the top left.
  3. Then change shape.triangleup to shape.circle and color.green to color.orange, and save.

Next: Built-in indicators.

Quick check

  1. 1. Where does plotshape() draw a shape?

  2. 2. Why give each plot a plain title?

  3. 3. An up candle closes 0.25 below the previous high. Does strongClose mark it?

0 of 3 answered.

Finished this lesson?

Tick it off and keep your place

Make a free account and we'll remember where you are, so “Built-in indicators” is waiting next time.

Read the full notes

In Pine Script, plot() draws a line with a title, colour and thickness, and plotshape() draws a shape only on the candles where a rule is true.

  • plot(ma, "SMA 20", color.blue, 2) draws a line with a title, a colour and a thickness. Leave off the later details and TradingView uses defaults. Code uses the American spelling, color.
  • plotshape(rule, title, style, location, colour) draws a shape only on where the rule is true. Example: plotshape(strongClose, "Strong close", shape.triangleup, location.belowbar, color.green).
  • A long line can carry on to the next line, indented by any number of spaces except a multiple of four (five is common).
  • Titles appear in the script's settings, on the Style tab (double-click the script's name on the chart), where anyone can change colours or hide a plot.
  • Check a few marks by hand with the numbers: an exact rule can reject a candle that looks strong by eye. See Reading price data.

Worked example

Made-up numbers

Checking the triangles by hand

Made-up candles · rule: close > open and close > high[1] · 10:00 high 5,022.00

  1. 10:05: opens 5,021.50, closes 5,023.25 > 5,022.00: triangle
  2. 10:10: closes 5,022.75 below its open of 5,023.25: no triangle
  3. 10:15: up, but 5,023.75 is below the 10:10 high of 5,024.00: no triangle

An exact rule can reject a candle that looks strong by eye.

Your turn

Drill

Made-up candles · 10:15 high 5,024.25 · 10:20 opens 5,023.75, closes 5,025.00 · 10:25 opens 5,025.00, high 5,026.00, closes 5,024.50 · 10:30 opens 5,024.50, closes 5,026.25

Trading is risky. You can lose money. Test results are hypothetical, and a good test doesn't mean future profits. This lesson explains how Pine Script works. It isn't advice.