Education only. This is not investment advice and nothing here is a buy or sell recommendation. Trading carries risk of loss, and past results do not predict the future. Practise with TradingView's Paper Trading (fake money) only, never connect broker API keys or place live orders from these lessons. For personal advice, talk to a SEBI-registered Investment Adviser.
By the end of this lesson you will have your first TradingView indicator on a chart, written by AI from exact rules, and you will have checked that it draws the right numbers.
You need: a free TradingView account in a desktop browser, any AI chat or coding agent (for example the Playground) · Time: 9 minutes
An indicator is a formula drawn on a chart. A 20-day average of closing prices, for example, is one number per bar, joined into a line. It describes what price already did. It does not know what price will do next.
Pine Script is TradingView's own small programming language for writing indicators. You don't need to learn it line by line: the AI writes it, and you do the part the AI can't. You decide the exact rule and check that the chart shows what you meant.
Why?People lose money when they treat a line on a chart as a promise. If you remember that an indicator is a description, not a prediction, every lesson in this course stays useful and safe.
CarefulThis course teaches coding and checking skills. It is not investment advice, and no symbol here is a recommendation. Stock names like NIFTY 50 or RELIANCE are only test data for your code. Practise on paper only. For personal advice, talk to a SEBI-registered Investment Adviser.
- Open tradingview.com, log in and open a chart (Products → Supercharts, or search a symbol such as NIFTY).
- At the bottom of the chart, open the Pine Editor tab.
- Every script starts with a version line. Today's version is Pine Script v6, so the first line is
//@version=6. - After you paste code, the button on the right of the editor adds it to the chart (it says "Update on chart" once the script is already there). Save the script with a name you will recognise.

The Pine Editor sits under the chart. The script on line 1 starts with the version line.Source: TradingView · tradingview.com · Screenshot © TradingView, used for education · used for education (image credits) Why?AI models learned from years of old Pine code (v4, v5). If the version line is missing or old, the code may use names that no longer exist. Checking line 1 takes two seconds and prevents half of all compile errors.
Do it now Do it now
In the Prompt Card lesson you learned that the AI fills every gap with a guess. Chart rules are full of gaps: which average, of which price, on which bar, on which chart? Use this five-row card before every indicator prompt:
- Inputs: the numbers the user can change, with default values (EMA length 20).
- Condition: the exact rule in plain words, including when it counts ("on a closed bar").
- Draw: what appears on the chart: a line, a marker, a label, a colour.
- Timeframe: the chart you will test it on: daily (swing) or 15 minutes (intraday).
- Done when: the check you will do by hand on specific bars.
Five rows. If a row is empty, the AI will guess it. Match them Match each row of the Rule Card with an example
Tap an item on the left, then its meaning on the right.
Why?Trading words sound exact but are not. "When the EMA crosses" can mean during the bar or after it closes, and those give different markers. The card forces you to decide before the AI decides for you.
An EMA (exponential moving average) is an average that gives more weight to recent bars. It is the simplest useful first indicator, and TradingView has a built-in one you can compare against.
Prompt · copy it into your AI agentGoal: Write a TradingView indicator in Pine Script v6 that draws one EMA line on the price chart. Context: I am a beginner and cannot code. I will paste your code into the Pine Editor. This is for learning only, tested on the NIFTY 50 daily chart. Details: - Inputs: EMA length, default [20], minimum 1, editable in Settings. - Use the closing price. - Draw the EMA as a blue line, width 2, on top of the candles (overlay). Rules: - Start with //@version=6 and use only Pine Script v6 functions. - Add a short comment in simple English above each line. - No buy or sell signals, no strategy code. Done when: - It compiles with no errors in the Pine Editor. - Tell me how to check, on any bar, that its value equals TradingView's built-in "Moving Average Exponential" with the same length.
A good answer looks like this. Yours may differ in names and comments; the three working lines must be the same idea:
Pine Script//@version=6 indicator("My EMA", overlay = true) // Input: how many bars the EMA averages (change it in Settings) length = input.int(20, "EMA length", minval = 1) // Exponential moving average of the closing price emaValue = ta.ema(close, length) // Draw the EMA as a blue line on the price chart plot(emaValue, "EMA", color = color.blue, linewidth = 2)Why?overlay = trueputs the line on the candles instead of in a separate pane.input.intmakes the length a setting, so you can test 20 and 50 without asking the AI again.Never trust an indicator because it compiled. Compiling only means the grammar is right. Check the numbers:
- Paste the code in the Pine Editor and add it to the chart.
- Also add TradingView's built-in Moving Average Exponential (Indicators button → search "EMA") and set its length to 20 in its settings.
- Hover over three different bars. The values of both indicators show at the top-left of the chart, next to their names. They must be the same on every bar.
- Change your input to 50 and the built-in one to 50. Still the same? Your first indicator is correct.
Why?A built-in indicator is an answer key. When your version matches it on three bars, you know the AI used the right price and the right formula. This "compare with a known answer" habit is how you will check every indicator in this course.
Errors are normal, especially with AI-written Pine. TradingView itself has warned that AI chatbots often mix old and new Pine versions. Don't guess and don't edit randomly. Copy the exact error from the bottom of the Pine Editor and send it back:
Prompt · copy it into your AI agentYour Pine Script v6 code shows this error in the TradingView Pine Editor: [paste the exact error text, including the line number] Here is the full code I pasted: [paste the code] Explain the cause in one simple sentence, then give me the full corrected script. Use only Pine Script v6 functions. Do not change the rule or the inputs.
If the second fix also fails, start a new chat with the Rule Card and the error. Old wrong attempts in the chat confuse the AI (see When it breaks).
Why?"Do not change the rule" matters: a common AI shortcut is to "fix" an error by quietly changing what the indicator does. You want the same rule, working.
- An indicator is a formula drawn on a chart: a description of the past, not a prediction or advice.
- Open the Pine Editor, and make sure line 1 is
//@version=6. - Fill the Indicator Rule Card: Inputs · Condition · Draw · Timeframe · Done when.
- Check every indicator against a known answer (a built-in indicator) on several bars.
- Next: Moving average crossover markers, where when a signal counts becomes the whole game.
Create a free account to save your progress and open every lesson. Create free account