

Kotak
Stockshaala
Chapter 3 | 2 min read
Hands-On: Create Your First Indicator
It’s one thing to understand Pine Scripts™ basics. It’s another way to build something real with it.
In this chapter, you’ll create your first working indicator using everything you’ve learned - variables, conditions, and plots. By the end, you’ll be able to:
- Code your own RSI + Moving Average signal indicator
- See it on the chart
- Use it to track oversold opportunities
What You’ll Build
Goal:
Plot a moving average and show buy signals when RSI is below 30 and price is above the MA.
You’ll learn how to:
- Combine conditions
- Add signal markers on the chart
- Customize your display
Step-by-Step Code (With Explanation)
//@version=6
indicator("RSI Buy Signal with 50 MA", overlay=true)
// 1. Define Inputs
rsiPeriod = input.int(14, title="RSI Period")
maPeriod = input.int(50, title="MA Period")
// 2. Calculate Values
rsi = ta.rsi(close, rsiPeriod)
ma = ta.sma(close, maPeriod)
// 3. Define Signal Condition
buySignal = (rsi < 30) and (close > ma)
// 4. Plot MA
plot(ma, title="50-period MA", color=color.blue, linewidth=2)
// 5. Plot Buy Signal Marker
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
Explanation of Each Part
indicator(...) | Names the script and allows overlay on chart |
input.int(...) | Lets users change RSI and MA periods |
ta.rsi, ta.sma | Calculates RSI and Moving Average |
buySignal = ... | Checks if RSI < 30 and price > MA |
plot(ma) | Displays the moving average as a line |
plotshape(buySignal) | Marks buy signals on the chart |
You can now see green triangles below the candles whenever the RSI is low, and the price is holding above the moving average.
How to Add It to Your Chart
- Open any chart on TradingView
- Click the “Pine Editor” tab in the right toolbar
- Paste the full code above
- Click “Add to Chart”
- Your custom indicator appears on the chart instantly
You can also save it and access it from your Indicators panel under “My Scripts.”
Customize It Further (Optional)
Try editing:
- rsi < 30 → rsi < 40 for more signals
- Add a second shape for sell signals (e.g., RSI > 70 & price < MA)
- Change MA from SMA to EMA: ta.ema(close, maPeriod)
This is how real strategies are built. So, start simple and improve gradually.
To Sum Up
You’ve just created your first custom indicator. You now know how to:
- Use Pine Scripts™ to bring an idea to life
- Plot lines and markers
- Deploy it on real charts
Recommended Courses for you
Beyond Stockshaala
Discover our extensive knowledge center
Learn, Invest, and Grow with Kotak Videos
Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.














