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
- Add the Strong closes script to a 5-minute MES1! chart.
- Pick five triangles and check each one by hand with the OHLC numbers at the top left.
- Then change shape.triangleup to shape.circle and color.green to color.orange, and save.
Quick check
1. Where does plotshape() draw a shape?
2. Why give each plot a plain title?
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
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 One bar on a price chart. It shows where price opened and closed, and the highest and lowest it reached, in one stretch of time.More in the glossary 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 Open, high, low and close: the four prices a candle or bar shows for its stretch of time.More in the glossary numbers: an exact rule can reject a candle that looks strong by eye. See Reading price data.
Worked example
Made-up numbersChecking the triangles by hand
Made-up candles · rule: close > open and close > high[1] · 10:00 high 5,022.00
- 10:05: opens 5,021.50, closes 5,023.25 > 5,022.00: triangle
- 10:10: closes 5,022.75 below its open of 5,023.25: no triangle
- 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
DrillMade-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.