How to Create Custom Indicators in TradingView
Table of Contents
Why Create Custom Indicators?
While TradingView offers hundreds of built-in indicators, custom indicators give you unique advantages:
- Unique edge: Indicators tailored to your specific trading strategy
- Combine multiple signals: Merge different indicators into one view
- Custom visualizations: Display data exactly how you want it
- Automation ready: Use with alerts and automated trading
- Share or sell: Build tools for others in the trading community
Indicator Basics: Structure & Settings
Basic Indicator Template
Every indicator starts with this structure:
//@version=5
indicator("My Custom Indicator", overlay=false)
// Your indicator code here
myValue = close
// Plot the result
plot(myValue)
Key Parameters
overlay=true- Draws on the price chartoverlay=false- Draws in separate pane below chartshorttitle- Abbreviated name for chart legendprecision- Number of decimal places to display
Building a Custom RSI Indicator
Let's create an enhanced RSI with custom overbought/oversold levels and divergence detection:
//@version=5
indicator("Enhanced RSI", overlay=false)
// Inputs - Allow customization
rsiLength = input.int(14, "RSI Length", minval=1)
overbought = input.int(70, "Overbought Level", minval=50, maxval=100)
oversold = input.int(30, "Oversold Level", minval=0, maxval=50)
// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)
// Plot RSI line
plot(rsiValue, "RSI", color=color.blue, linewidth=2)
// Plot overbought/oversold levels
hline(overbought, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(50, "Midline", color=color.gray)
hline(oversold, "Oversold", color=color.green, linestyle=hline.style_dashed)
// Background coloring
bgcolor(rsiValue > overbought ? color.new(color.red, 90) : na)
bgcolor(rsiValue < oversold ? color.new(color.green, 90) : na)
What this does:
- Creates customizable RSI length and levels
- Plots horizontal lines for overbought/oversold zones
- Adds background color when RSI enters extreme zones
- Users can adjust all parameters via indicator settings
Multiple Moving Averages Indicator
Create an indicator that displays multiple moving averages with crossover detection:
//@version=5
indicator("Triple MA Crossover", overlay=true)
// Input parameters
fastLength = input.int(9, "Fast MA Length")
mediumLength = input.int(21, "Medium MA Length")
slowLength = input.int(50, "Slow MA Length")
maType = input.string("EMA", "MA Type", options=["SMA", "EMA"])
// Calculate moving averages
fastMA = maType == "EMA" ? ta.ema(close, fastLength) : ta.sma(close, fastLength)
mediumMA = maType == "EMA" ? ta.ema(close, mediumLength) : ta.sma(close, mediumLength)
slowMA = maType == "EMA" ? ta.ema(close, slowLength) : ta.sma(close, slowLength)
// Plot moving averages
plot(fastMA, "Fast MA", color=color.green, linewidth=1)
plot(mediumMA, "Medium MA", color=color.orange, linewidth=2)
plot(slowMA, "Slow MA", color=color.red, linewidth=3)
// Detect crossovers
bullishCross = ta.crossover(fastMA, slowMA)
bearishCross = ta.crossunder(fastMA, slowMA)
// Plot signals
plotshape(bullishCross, "Buy Signal", shape.triangleup,
location.belowbar, color.green, size=size.small)
plotshape(bearishCross, "Sell Signal", shape.triangledown,
location.abovebar, color.red, size=size.small)
Features:
- Three customizable moving averages
- Choice between SMA and EMA
- Automatic crossover detection
- Visual buy/sell signals on chart
- Different colors and line widths for clarity
Multi-Timeframe Indicators
One of Pine Script's most powerful features is accessing data from different timeframes:
//@version=5
indicator("Multi-Timeframe RSI", overlay=false)
// Input for higher timeframe
htfInput = input.timeframe("D", "Higher Timeframe")
rsiLength = input.int(14, "RSI Length")
// Current timeframe RSI
currentRSI = ta.rsi(close, rsiLength)
// Higher timeframe RSI
htfRSI = request.security(syminfo.tickerid, htfInput, ta.rsi(close, rsiLength))
// Plot both
plot(currentRSI, "Current TF RSI", color=color.blue, linewidth=2)
plot(htfRSI, "HTF RSI", color=color.orange, linewidth=2, style=plot.style_stepline)
// Reference lines
hline(70, "Overbought", color=color.red)
hline(30, "Oversold", color=color.green)
Use cases:
- Compare trend strength across timeframes
- Only trade when both timeframes align
- Spot divergences between timeframes
- See bigger picture while trading lower timeframes
Advanced Styling & Colors
Dynamic Colors
Change colors based on conditions:
// Color changes based on trend
maValue = ta.sma(close, 20)
trendColor = close > maValue ? color.green : color.red
plot(maValue, "MA", color=trendColor, linewidth=2)
// Gradient colors based on strength
rsi = ta.rsi(close, 14)
rsiColor = rsi > 70 ? color.red :
rsi > 50 ? color.orange :
rsi > 30 ? color.yellow : color.green
plot(rsi, "RSI", color=rsiColor)
Fill Areas
// Fill area between two lines
upperBand = ta.sma(high, 20)
lowerBand = ta.sma(low, 20)
p1 = plot(upperBand, "Upper", color=color.blue)
p2 = plot(lowerBand, "Lower", color=color.blue)
fill(p1, p2, color=color.new(color.blue, 90))
Best Practices for Custom Indicators
1. User Inputs
Always provide customizable inputs for key parameters:
- Lengths/periods for calculations
- Threshold levels (overbought/oversold)
- Colors and line styles
- Enable/disable specific features
2. Clear Labels
Give everything descriptive names:
// Good: Clear labels
plot(rsiValue, "RSI(14)", color=color.blue)
hline(70, "Overbought Zone", color=color.red)
// Bad: No context
plot(r, "R", color=color.blue)
hline(70, "Line", color=color.red)
3. Performance
- Avoid complex calculations in loops
- Use built-in functions when possible
- Limit the number of plots (max 64 per script)
- Test on different timeframes and symbols
4. Documentation
Add comments explaining:
- What the indicator measures
- How to interpret signals
- Suggested parameter ranges
- Any limitations or assumptions
Need a Professional Custom Indicator?
I create professional custom indicators tailored to your exact specifications. From simple enhancements to complex multi-indicator systems, I deliver clean, optimized code.
Get Your Custom Indicator BuiltAbout the Author
Professional Pine Script developer with 5+ years of experience. Specialized in creating custom indicators, strategies, and alerts for traders worldwide. Completed 50+ projects with 100% satisfaction rate.
Related Articles
📚 Related Articles
Complete Guide to Pine Script v5 for Beginners
Master Pine Script v5 fundamentals before diving into custom indicator development. Essential syntax and concepts.
Trading Strategy Development: Best Practices
Turn your custom indicators into complete trading strategies with entry/exit logic and risk management.
Pine Script Alerts and Trading Automation
Add alert conditions to your custom indicators for real-time notifications and trading automation.