Skip to main content
On this page

Add Your Own Indicator in TradingView: A Pine Script Guide

· 4 min read
Pineify Team
Pine Script and AI trading workflow research team

Add your own indicator by opening TradingView's Pine Editor, saving a complete script and selecting Add to chart. Start with a calculation whose output you can inspect manually before adding more conditions.

How to Add Your Own Indicator in TradingView: A Step-by-Step Guide

Open the Editor​

The current Pine Editor guide places the Pine icon in the right toolbar. Older screenshots may show a bottom tab. Create a new indicator and keep a copy of any existing script before replacing its contents.

Pine supports chart calculations within documented runtime and data limits. It does not run arbitrary external applications or provide a secure place to store broker credentials. Do not put secrets in source code or ordinary input fields.

A Complete Moving-Average Example​

This teaching example plots two simple moving averages and marks crossovers only after the chart bar closes. The lengths are examples, not optimized settings or a profitable strategy.

//@version=6
indicator("Custom MA Crossover", overlay=true)
shortLen = input.int(9, "Short MA Length", minval=1)
longLen = input.int(21, "Long MA Length", minval=1)
shortMA = ta.sma(close, shortLen)
longMA = ta.sma(close, longLen)
bullCross = ta.crossover(shortMA, longMA)
bearCross = ta.crossunder(shortMA, longMA)
confirmedBull = bullCross and barstate.isconfirmed
confirmedBear = bearCross and barstate.isconfirmed
plot(shortMA, "Short MA", color.blue)
plot(longMA, "Long MA", color.red)
plotshape(confirmedBull, "Bullish crossover", shape.triangleup, location.belowbar, color.green)
plotshape(confirmedBear, "Bearish crossover", shape.triangledown, location.abovebar, color.red)
alertcondition(confirmedBull, "Bullish Crossover", "Short MA crossed above Long MA")
alertcondition(confirmedBear, "Bearish Crossover", "Short MA crossed below Long MA")

Save, add it to a chart and open the indicator's own settings to change the lengths. Do not confuse those settings with the overall chart settings dialog. If an error appears, use its location and message to diagnose the source before testing signals.

Pineify Website

Pineify can help generate custom scripts. Apply the same source and chart checks to generated code as to code you write yourself.

Verify Plots and Alerts​

Compare both averages with equivalent built-in studies using the same source and lengths. Inspect a few crossover bars manually. On an open bar, the underlying averages can still move; this example delays the markers until confirmation.

An alert condition exposes an option in TradingView's Create Alert dialog. It does not activate a notification by itself. Create the alert, choose the intended condition and review the notification settings. See the official alert documentation for execution and snapshot behavior.

Indicators and Strategies Have Different Jobs​

This script plots information; it does not simulate trades. Backtest statistics require a strategy with explicit entries, exits, sizing and costs. Merely renaming the declaration leaves those decisions unspecified. Use a separate version for strategy testing and retain the indicator for comparison.

Limits and Sharing​

Check the current Pine limitations rather than an invented character-count rule. Indicator slots also depend on your TradingView plan.

Saving a script is different from publishing it. Before publishing, review source visibility, access controls and the current publishing rules. An input field does not make sensitive information secure. Test symbols with different sessions or missing volume rather than assuming the same behavior everywhere.

Why is the indicator not visible?

Check compilation, Add to chart, visibility and plot values. An overlay setting controls pane placement; it cannot fix a calculation that returns no values.

Does bar-close confirmation solve every repainting problem?

No. It addresses changes on the chart's open bar. Higher-timeframe data, future leakage and other sources require separate review.

Can I backtest this indicator directly?

No trade simulation is defined here. Create a strategy with explicit orders and assumptions to evaluate hypothetical trades.