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
- On a 5-minute MES1! chart, add the Two averages script and the RSI 14 script.
- 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.
Quick check
1. In ta.ema(close, 9), what is 9?
2. Why does RSI go in its own pane?
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
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) (A moving average where every close in the window counts the same: add them up and divide by how many there are.More in the glossary), ta.ema(close, 9) (A moving average that gives the newest closes more weight, so it reacts sooner than a simple one of the same length.More in the glossary), ta.rsi(close, 14) (An indicator from 0 to 100 that compares the size of recent gains with recent losses.More in the glossary) and ta.atr(14) (An indicator that averages recent candles’ true ranges, so it shows how far price has been moving in each candle, in the same units as price.More in the glossary).
- The first detail is the source (which price), the second the length in 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. 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 The smallest step a price can move. On many stock index futures that’s 0.25 of a point.More in the glossary; multiply by syminfo.pointvalue (the What a move of one whole point is worth for one futures contract. Tick value is the tick size times the point value.More in the glossary, $5 on the A small futures contract on the S&P 500, traded at CME Group. Each point is worth $5, and its smallest step of 0.25 is worth $1.25.More in the glossary) for dollars per contract. See Stop placement by volatility.
Worked example
Made-up numbersATR in ticks and dollars
Made-up numbers · Micro S&P 500 · ta.atr(14) = 6.5 points · tick 0.25 · point value $5
- atrTicks = 6.5 ÷ 0.25 = 26 ticks
- 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
DrillMade-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.