Skip to content
Docs
Open Portal
Copy manually

Your browser did not allow direct clipboard access. Select and copy the text below.

Make your first Pine Script edit

Open TradingView, create and save your first indicator, then change one number and check the result on your chart.

You will put a blue moving-average line on a TradingView chart, change one number, and see the line change. No coding experience is needed.

Use a desktop or laptop. Keep this lesson open in one browser tab and TradingView in another so you can switch between the instructions and your chart. Sign in to your own TradingView account when asked.

How to follow the pictures: red boxes show where to click in TradingView. Click a screenshot here to enlarge it; the controls inside the picture are not live. When a step says Copy, use the button on the actual code block on this lesson page.

Open TradingView and add your first indicator

Section titled “Open TradingView and add your first indicator”
1

Open TradingView

Open tradingview.com in another tab. Click the person icon at the top right, then Sign in. Sign in to your own account, then return here. If you are already signed in, continue to step 2.

What you should see

You are on TradingView's website. You have not opened the code editor yet.

TradingView website with the profile icon and Sign in option outlined in red.
Enlarge screenshot
On tradingview.com, click the person icon at the top right (1), then Sign in (2).

On tradingview.com, click the person icon at the top right (1), then Sign in (2).

TradingView website with the profile icon and Sign in option outlined in red.
2

Open the full chart

Click this link to open TradingView’s full chart in another tab. This is where you will add your script. You can close the TradingView homepage tab once the chart opens.

What you should see

The screen has a large price chart, a symbol near the top left, and toolbars around the chart.

Still on a news page or a symbol summary? Open the full-chart link above. You need the chart workspace shown here.

Clean TradingView chart with BTCUSD, the 1-minute interval and Candles highlighted
Enlarge screenshot
This is the full chart workspace. The next steps will match the highlighted symbol, interval and chart type.

This is the full chart workspace. The next steps will match the highlighted symbol, interval and chart type.

Clean TradingView chart with BTCUSD, the 1-minute interval and Candles highlighted
3

Choose the example symbol

Click the current symbol at the top left of the chart. Search for BTCUSD, then choose the result from BITSTAMP. We use this same chart throughout the lessons.

What you should see

The chart shows BTCUSD from BITSTAMP. Your live price and candles can differ from the screenshot.

BTCUSD symbol search with the Bitstamp row highlighted
Enlarge screenshot
Type BTCUSD, then choose the Bitcoin / U.S. dollar row with Bitstamp shown at the right.

Type BTCUSD, then choose the Bitcoin / U.S. dollar row with Bitstamp shown at the right.

BTCUSD symbol search with the Bitstamp row highlighted
4

Use 1-minute candles

Open the interval control beside the symbol and choose 1 minute.

What you should see

The chart uses a 1-minute interval and standard candles, as shown in the highlighted controls.

Chart interval menu with 1 minute highlighted
Enlarge screenshot
Click the interval menu, then choose 1 minute.

Click the interval menu, then choose 1 minute.

Chart interval menu with 1 minute highlighted

Next, open the chart-type menu and choose Candles.

Chart-style menu with Candles highlighted
Enlarge screenshot
Choose Candles, rather than Line or Heikin Ashi, for these practice lessons.

Choose Candles, rather than Line or Heikin Ashi, for these practice lessons.

Chart-style menu with Candles highlighted

Seeing a single price line or Heikin Ashi candles? Return to the chart-type menu and choose Candles before continuing.

5

Open Pine Editor

Click Pine in the chart’s right-hand toolbar.

What you should see

A code editor opens beside or beneath the chart. The chart is still available.

Cannot see the control? Check that you are in the full chart from step 2, then look at the right-hand toolbar.

TradingView right-hand toolbar with the Pine Editor icon highlighted
Enlarge screenshot
Click Pine in the far-right toolbar. This opens the code editor; it does not create a trade.

Click Pine in the far-right toolbar. This opens the code editor; it does not create a trade.

TradingView right-hand toolbar with the Pine Editor icon highlighted
My screen looks different

TradingView layouts can differ. If your chart has a Pine Editor tab below the chart, open that tab. The code-editing steps that follow are the same.

6

Create a new indicator

Open the script menu at the top of Pine Editor. Choose Create new, then Indicator.

What you should see

Pine Editor displays a short starter script. You will replace this starter code in the next two steps.

An indicator is a script that calculates or draws something on your chart. This one will draw a moving average. It will not place trades.

Pine Editor script menu with Create new and Indicator highlighted
Enlarge screenshot
Open the script-name menu, choose Create new, then Indicator.

Open the script-name menu, choose Create new, then Indicator.

Pine Editor script menu with Create new and Indicator highlighted

Click Copy on the code block directly below, on this lesson page. This copies the complete script, including the first line, //@version=6.

Copy this complete starting scriptPine v6
TradingView → Pine Editor Pine Script
//@version=6
indicator("Pine practice: EMA", overlay = true)
// Change the number below to adjust the EMA length.
int length = 20
float ema = ta.ema(close, length)
plot(ema, title = "EMA", color = color.blue, linewidth = 2)
7

Select all the starter code

Switch to TradingView. Click inside the code text first. Then press Cmd+A on Mac or Ctrl+A on Windows.

What you should see

All of the starter code is highlighted inside Pine Editor, rather than text elsewhere on the webpage.

The whole webpage is selected instead? Click directly on a line of code, then press the shortcut again.

All starter code highlighted inside Pine Editor
Enlarge screenshot
First click inside the code, then press Cmd+A or Ctrl+A. The selection should be inside Pine Editor.

First click inside the code, then press Cmd+A or Ctrl+A. The selection should be inside Pine Editor.

All starter code highlighted inside Pine Editor
8

Paste the starting script

Press Cmd+V on Mac or Ctrl+V on Windows. This replaces the selected starter code.

What you should see

Your editor matches the eight-line example. It starts with //@version=6 and ends with plot(...).

Old code is still above or below the new code? Click inside the editor, select all again, and paste the complete script. Do not keep two scripts in the same editor.

Complete eight-line EMA practice script pasted into Pine Editor
Enlarge screenshot
Compare your editor with this complete example. There should be one version line at the top and one plot line at the bottom.

Compare your editor with this complete example. There should be one version line at the top and one plot line at the bottom.

Complete eight-line EMA practice script pasted into Pine Editor
9

Save your script

Click the cloud-shaped Save control at the top of Pine Editor. You can also press Cmd+S on Mac or Ctrl+S on Windows while your cursor is inside the editor.

What you should see

TradingView asks you to name the new script.

Pine Editor save control highlighted beside Add to chart
Enlarge screenshot
Click the cloud-shaped Save control, or press Cmd+S / Ctrl+S with focus inside the editor.

Click the cloud-shaped Save control, or press Cmd+S / Ctrl+S with focus inside the editor.

Pine Editor save control highlighted beside Add to chart
10

Give it a name

Enter My EMA practice in the name field, then click Save.

What you should see

The editor shows My EMA practice as the saved script name.

A red error appears instead? Go to If an edit does not work below. Saving and drawing on the chart are separate steps.

Save script dialog with My EMA practice entered and the Save button outlined.
Enlarge screenshot
Type My EMA practice (1), then click Save (2). This saves your own script file.

Type My EMA practice (1), then click Save (2). This saves your own script file.

Save script dialog with My EMA practice entered and the Save button outlined.
11

Add the script to your chart

Click the triangle-shaped Add to chart button beside the script name at the top of Pine Editor.

What you should see

A blue line appears over the candles, and Pine practice: EMA appears in the chart's indicator list.

Saved practice script with the triangle Add to chart control highlighted
Enlarge screenshot
Click the triangle-shaped Add to chart button beside the script name. Saving the file alone does not draw it on the chart.

Click the triangle-shaped Add to chart button beside the script name. Saving the file alone does not draw it on the chart.

Saved practice script with the triangle Add to chart control highlighted

Your chart should resemble this: candles, one blue EMA line, and the label Pine practice: EMA. The exact line shape depends on the prices currently on your chart.

EMA 20 visible on the chart with the indicator name and blue line highlighted
Enlarge screenshot
Check both signs of success: Pine practice: EMA appears in the indicator list, and a smooth blue EMA line runs through the candle chart.

Check both signs of success: Pine practice: EMA appears in the indicator list, and a smooth blue EMA line runs through the candle chart.

EMA 20 visible on the chart with the indicator name and blue line highlighted

No blue line? Check the chart’s indicator list. If Pine practice: EMA is missing, return to Pine Editor and click Add to chart. If the label is present, make sure the indicator has not been hidden.

Why are the two names different? My EMA practice is your saved file’s name. Pine practice: EMA comes from the script’s indicator(...) line and appears on the chart. Neither needs to match the other.

Now change the moving average’s length from 20 to 50. Change the code first, then check the chart.

12

Replace 20 with 50

In Pine Editor, find int length = 20. Select only 20 and type 50.

What you should see

The line now reads int length = 50. The other lines are unchanged.

Pine Editor showing int length = 50 with the changed line highlighted
Enlarge screenshot
Change only 20 to 50 on the length line. Leave the other lines unchanged.

Change only 20 to 50 on the length line. Leave the other lines unchanged.

Pine Editor showing int length = 50 with the changed line highlighted
13

Save and check the changed line

Press Cmd+S or Ctrl+S. If the editor offers Update on chart, click it. If the script is not on the chart, click Add to chart.

What you should see

Your chart uses the new length. The blue line has recalculated over the same price history.

Two copies of Pine practice: EMA? Hover over the extra entry in the chart’s indicator list and use its remove control. Keep one practice indicator so you can tell which line you changed.

The practice chart after saving EMA length 50
Enlarge screenshot
After saving length 50, check that the same indicator remains on the chart and its blue line has recalculated. Live prices will differ.

After saving length 50, check that the same indicator remains on the chart and its blue line has recalculated. Live prices will differ.

The practice chart after saving EMA length 50

Compare this result with the length-20 chart above. A longer EMA gives each new price less weight, so it generally reacts more slowly. A changed line is a successful edit; it does not establish a profitable trading rule.

Try it yourself: change 50 back to 20, save, and check the chart again. You can use the illustration below to compare lengths over exactly the same example prices.

Try the ideaOne setting. The same prices.

Change the EMA length. Watch the blue line while the grey price line stays the same.

Example closeEMA 20
Illustrative price16 sample closes →
Latest example close
107.00
EMA at that close
102.86
Weight on each new close
9.5%

Start with length 20, then choose 50. The prices stay fixed; the longer EMA gives each new close less weight.

Fixed illustrative prices. The EMA starts at the first sample close of 100. This shows the smoothing formula, not a Pine Script runtime or a live TradingView chart.

Read the complete example

The sample closes are 100, 101, 100, 102, 101, 104, 103, 106, 105, 104, 102, 101, 103, 105, 104, 107. The first EMA value is 100. Each following value uses: new EMA = close × weight + previous EMA × (1 − weight), where weight = 2 ÷ (length + 1).

Length 20 gives each new close about 9.5% weight; length 50 gives it about 3.9%; length 100 gives it about 2.0%. A larger length gives each new close less influence. Changing this value does not change the price data.

On these fixed prices, the final EMA values are 20: 102.86; 50: 101.53; 100: 100.86. The price at the final close is 107. A real chart has its own price history, so these illustrative values are not expected TradingView results.

You can add an EMA length field to the indicator’s settings. Then you can change the length without editing the code each time.

14

Replace the length line with an input

Copy the one-line excerpt below. In Pine Editor, select the whole line int length = 20 and replace it with this line. Keep the other lines.

Replacement for the length lineOne-line excerpt. It belongs inside your existing script.
Pine Editor → replace the existing length line Pine Script
int length = input.int(20, "EMA length", minval = 1)
What you should see

There is one length line, beginning int length = input.int(...).

Save with Cmd+S or Ctrl+S, then update the chart if the editor offers that control.

EMA length line changed to input.int with a labelled setting
Enlarge screenshot
Replace the old length line with int length = input.int(20, "EMA length", minval = 1). This creates the labelled setting.

Replace the old length line with int length = input.int(20, "EMA length", minval = 1). This creates the labelled setting.

EMA length line changed to input.int with a labelled setting
15

Open your indicator's settings

Move your pointer over Pine practice: EMA in the chart’s indicator list. Click its Settings gear.

What you should see

The settings dialog belongs to Pine practice: EMA. It is not the chart's general settings dialog.

Indicator legend with the EMA settings gear highlighted
Enlarge screenshot
Move your pointer over Pine practice: EMA, then click its small settings gear. Use the indicator gear, not the chart-wide Settings button.

Move your pointer over Pine practice: EMA, then click its small settings gear. Use the indicator gear, not the chart-wide Settings button.

Indicator legend with the EMA settings gear highlighted
16

Change the EMA length field

Click the Inputs tab. In EMA length, replace 20 with 50, then click Ok.

What you should see

The EMA recalculates with length 50, while your source code can keep 20 as its starting value.

No EMA length field? Check that you opened this indicator’s settings and saved the input.int(…) change from step 14. Opening the chart’s general settings will not show this field.

Indicator Inputs dialog with EMA length set to 50 and Ok highlighted
Enlarge screenshot
In Inputs, enter 50 for EMA length, then click Ok. Change this field to adjust the chart without editing the code.

In Inputs, enter 50 for EMA length, then click Ok. Change this field to adjust the chart without editing the code.

Indicator Inputs dialog with EMA length set to 50 and Ok highlighted

Open the same field again and return it to 20 before lesson 2. The value currently selected in Inputs controls this chart instance. The 20 in the code is its default, not a display of your current setting.

If you need to restore the finished lesson, copy this complete version into Pine Editor, save, and add or update it on the chart.

Complete indicator with an EMA length settingPine v6
TradingView → Pine Editor Pine Script
//@version=6
indicator("Pine practice: EMA", overlay = true)
// Change EMA length in the indicator's Settings / Inputs.
int length = input.int(20, "EMA length", minval = 1)
float ema = ta.ema(close, length)
plot(ema, title = "EMA", color = color.blue, linewidth = 2)

You have already used the code. These are the parts worth recognising now:

What you see What it means here
//@version=6 The Pine Script version. Keep this first line.
// Change the number... A comment for the reader. It does not change the calculation.
int length = 20 The whole-number value you changed.
input.int(...) The whole-number settings field you added.
ta.ema(close, length) The calculation behind the blue line.
plot(...) The instruction that draws the line.

The version line also starts with //, but its @version annotation has a special purpose. Keep it intact. More detail: TradingView’s first steps and input settings.

Start with the last line you changed. Read the editor’s error, then check:

  • Missing or extra code: replace everything with the matching complete example above.
  • A name changed: length and Length are different. Restore the exact spelling.
  • A quote or bracket disappeared: keep both quotes around text and the closing ) after a function call.
  • Only the chart looks wrong: check the indicator’s name, visibility and current EMA length input before changing more code.

Undo your last edit with Cmd+Z or Ctrl+Z if needed. Do not continue to alerts until this indicator draws correctly.