If you’ve ever used TradingView and thought, “I wish I could build my own indicator”, then Pine Script is your answer. Pine Script v5 is TradingView’s programming language designed specifically for traders—making it easy to create custom indicators, strategies, and alerts even if you have little to no coding experience.
This Pine Script tutorial will walk you through writing your first TradingView indicator in under 30 minutes. By the end, you’ll not only have a working script but also the confidence to keep experimenting with your own ideas.
Why Pine Script v5?
Unlike other coding languages, Pine Script is made for charting and trading. That means:
- You can build custom indicators tailored to your strategy.
- Combine popular tools like RSI, MACD, and moving averages in one script.
- Create automated alerts that signal entries and exits.
- Backtest strategies directly inside TradingView.
And the best part? It’s all built into TradingView, so you don’t need any extra software.
Step 1: Define Your Indicator Idea
Every indicator starts with a concept. Ask yourself:
- Am I trying to confirm a trend?
- Do I want to catch reversals early?
- Should I combine multiple signals into one tool?
For this TradingView indicator guide, we’ll use a simple moving average (SMA) crossover strategy:
- When the short SMA crosses above the long SMA → Buy signal.
- When the short SMA crosses below the long SMA → Sell signal.
Step 2: Open the Pine Editor
- Log into TradingView.
- Open any chart.
- Click Pine Editor at the bottom of the screen.
- You’ll see a blank code editor where you can start typing your first script.
Step 3: Write the Basics
Every script begins with a declaration:
//@version=5
indicator("My First Indicator", overlay=true)
@version=5
ensures you’re using the latest Pine Script v5.indicator()
gives your script a title.overlay=true
means it will plot directly on the price chart.
Step 4: Add the Moving Averages
fastLength = input.int(9, "Fast SMA Length")
slowLength = input.int(21, "Slow SMA Length")
fastSMA = ta.sma(close, fastLength)
slowSMA = ta.sma(close, slowLength)
plot(fastSMA, color=color.orange, title="Fast SMA")
plot(slowSMA, color=color.blue, title="Slow SMA")
Here, we’ve created two adjustable moving averages and plotted them.
Step 5: Add Buy & Sell Signals
bullish = ta.crossover(fastSMA, slowSMA)
bearish = ta.crossunder(fastSMA, slowSMA)
plotshape(bullish, title="Buy Signal", location=location.belowbar,
color=color.green, style=shape.labelup, text="BUY")
plotshape(bearish, title="Sell Signal", location=location.abovebar,
color=color.red, style=shape.labeldown, text="SELL")
Now, your indicator automatically prints BUY and SELL labels when crossovers happen.
Step 6: Test & Adjust
Click Add to Chart. You’ll see:
- Two moving averages
- Green “BUY” labels on bullish crossovers
- Red “SELL” labels on bearish crossovers
Experiment with different timeframes or add filters (like RSI or volume) to refine signals.
Step 7: Save & Reuse
Once happy with your results:
- Click Save and give your script a name.
- Find it anytime under Indicators & Strategies.
- Share it privately or publish to the TradingView community.
Pro Tips for Beginners
- Start with simple logic (like SMA or RSI).
- Use the Strategy Tester in TradingView to backtest your ideas.
- Gradually add complexity—don’t try to build a pro-level algo on day one.
- Join TradingView’s script library to learn from other traders’ code.
Final Thoughts
With Pine Script v5, building a custom TradingView indicator is easier than ever. In less than 30 minutes, you can go from a simple idea in your head to a working tool on your chart.
Each script you create sharpens your trading strategy and saves you time. Whether you’re backtesting ideas or creating alerts, Pine Script gives you the flexibility to trade smarter.
👉 Ready to start coding your own indicator? Sign up on TradingView today and bring your trading ideas to life.