kotak-logo
Products
Platform
Research
Market
Learn
Partner
Support
IPO
TradingView Simplified Logo Light Mode

Kotak

Stockshaala

Module 7
Pine Script – Build & Backtest
Course Index

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

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

//@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)

You can now see green triangles below the candles whenever the RSI is low, and the price is holding above the moving average.

  1. Open any chart on TradingView
  2. Click the “Pine Editor” tab in the right toolbar
  3. Paste the full code above
  4. Click “Add to Chart”
  5. Your custom indicator appears on the chart instantly

You can also save it and access it from your Indicators panel under “My Scripts.”

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.

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
Is this chapter helpful?
Previous
Pine Scripts Basics (Variables, Plots, Conditions)
Next
Strategy Logic Building (Example: RSI + Supertrend)

Discover our extensive knowledge center

Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.

PreviousCourse IndexNext