Skip to content
Wildflower
Join free
Coding strategies in Pine Script

Free Trading School · Level 7 · Course 7.4

Built-in indicators

Lesson 6 of 16 in Coding strategies in Pine ScriptModule 2: Indicators and conditions

Advanced · Coding strategies in Pine Script

Built-in indicators

Wildflower Trading School · Lesson 7.4.2.1

Wildflower

In Level 2 you learned how moving averages, RSI and the average true range are worked out, step by step. In Pine Script, you don't have to write those steps yourself. By the end of this lesson, you'll know how to call four common indicators in one line each, and what the numbers in brackets mean. You'll also turn the average true range into ticks and dollars.

1 of 7

What you'll learn

  • Call indicators in one line. The ta. toolbox has averages, RSI and ATR ready made.
  • Set the source and length. Give the price first, then the length in candles.
  • Open the reference. Ctrl-click a name in the editor to see how it works.
  • Put each line in the right pane. Keep RSI in its own pane, apart from price lines.
  • Turn ATR into ticks and dollars. ATR is in points. Divide or multiply to convert it.

Exercise

  1. On a 5-minute MES1! chart, add the Two averages script and the RSI 14 script.
  2. Then write a third script that plots ta.atr(14) / syminfo.mintick in its own pane, and read the ATR in ticks on the last candle.

Next: If statements and conditions.

Quick check

  1. 1. In ta.ema(close, 9), what is 9?

  2. 2. Why does RSI go in its own pane?

  3. 3. ta.atr(14) is 8 points on the Micro S&P 500. What is that per contract?

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 “If statements and conditions” is waiting next time.

Read the full notes

Pine Script's ta. toolbox calls common indicators in one line, such as ta.sma(close, 20), ta.ema(close, 9), ta.rsi(close, 14) and ta.atr(14): a source to work on and a length in candles.

  • ta. is TradingView's toolbox of ready-made indicators. One line each: ta.sma(close, 20) (), ta.ema(close, 9) (), ta.rsi(close, 14) () and ta.atr(14) ().
  • The first detail is the source (which price), the second the length in . ATR takes only a length, because it always uses the high, low and close. The lengths here are examples; see Choosing a length.
  • The sums are the ones from Level 2: Simple moving average, RSI: how it is calculated and Average true range. In the Pine Editor, Ctrl-click (Cmd-click on a Mac) a name to open its reference.
  • Keep price-scale lines in an overlay script, and RSI (0 to 100) in a script with its own pane. hline(70) draws a flat guide line.
  • ATR is in points. Divide by syminfo.mintick for ; multiply by syminfo.pointvalue (the , $5 on the ) for dollars per contract. See Stop placement by volatility.

Worked example

Made-up numbers

ATR in ticks and dollars

Made-up numbers · Micro S&P 500 · ta.atr(14) = 6.5 points · tick 0.25 · point value $5

  1. atrTicks = 6.5 ÷ 0.25 = 26 ticks
  2. atrDollars = 6.5 × $5 = $32.50 per contract

syminfo.mintick and syminfo.pointvalue come from TradingView, so the same lines work on other markets.

Your turn

Drill

Made-up example · ta.atr(14) = 4.75 points · Micro S&P 500 · tick size 0.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.