Learn

Create a TradingView Indicator with AI: Pine Script, Alerts and Checks

At a glance

To create a TradingView indicator with AI, write the rule down first, then have the assistant generate Pine Script v6 and check the result on a chart. Our example plots an EMA and marks confirmed upward price crossings when RSI is above a chosen threshold. We compiled it in TradingView, checked positive and negative cases, compared a historical signal after reload and recorded a realtime alert with a separate test input profile. It does not place trades.

On this page
The RoboXpert robot paints a curved blue line across a board of candlestick blocks. Headline: “Pine Script with AI”
AI-generated illustration with a headline added by RoboXpert. Actual TradingView chart captures appear in the worked example below.

AI can help turn an indicator idea into Pine Script. The harder part is specifying what should appear on the chart, when it should appear and which similar-looking situations should produce no signal.

We will build a small Pine Script v6 indicator: an EMA line and a marker when price crosses above it on a confirmed bar, provided RSI exceeds a threshold. Then we will compare the rule with values from TradingView’s Data Window. The source and our observed checks are downloadable.

This is an original educational example developed with AI assistance (Codex/GPT-6, as recorded in the download’s README). It is not a strategy backtest or an automated order system. Its default values demonstrate the workflow; they are not recommended trading settings.

Specify the indicator before asking AI for code

“Add a bullish signal with RSI confirmation” is ambiguous. Does the price need to cross the EMA on this bar, or merely be above it? Is equality at the RSI threshold accepted? Can a marker appear before the bar closes?

Our specification answers those questions:

Scroll horizontally if needed

PartRule for this example
DataStandard candles on the chart’s own symbol and timeframe
EMAEMA of closing price, length 20 by default
RSIRSI of closing price, length 14 by default
CrossingCurrent close above current EMA, previous close at or below previous EMA
RSI filterRSI strictly greater than the chosen threshold, default 50
TimingSignal requires a confirmed bar
DisplayBlue EMA line and an RX triangle below qualifying bars
InspectionEMA, RSI, crossing, confirmation and final signal visible in the Data Window
Alert eventOne named condition using the same final signal as the marker
ExclusionsNo other timeframes, strategy orders, webhooks or external execution code

The distinction between crossing and remaining above matters. If price stays above the EMA for five bars, the rule does not ask for five new signals. The additional Data Window fields make that difference inspectable without guessing from pixels.

Use a precise Pine Script prompt

Give the assistant the rule and the current Pine version. You do not need to select a “best trading AI” to begin; you need generated code that can be reviewed and tested.

Write a small original TradingView indicator in Pine Script v6.
Use indicator(), overlay=true, on the chart's current symbol/timeframe.
Plot EMA(close, length), default length 20. Calculate RSI(close, length),
default length 14. Use a configurable RSI threshold, default 50.

Signal only when close crosses above its EMA, RSI is strictly above the
threshold and barstate.isconfirmed is true. Calculate ta.crossover on
every bar before combining the conditions. Plot an RX triangle below
qualifying bars and expose one alertcondition using the identical signal.

Show RSI, crossover, bar confirmation and final signal in the Data Window.
Do not add request.security, offsets into earlier bars, strategy orders,
webhooks, external libraries or additional filters.

Explain what can change on the open bar. Provide a positive case, an RSI
rejection case and a price-above-EMA-without-crossing case. Do not claim
compilation or real-time testing unless those checks were actually run.

Keep the first version small. If the result unexpectedly introduces higher-timeframe data, pivot confirmation or a strategy declaration, review that change before accepting it. Each changes the meaning or timing of the output.

Add the source to TradingView

Open a chart and its Pine Editor, then create a new Indicator. In the interface checked on 26 September 2026, Pine was available from the chart’s right-hand toolbar, and the editor’s script-name menu offered Create new → Indicator. TradingView can change panel placement; the official first-indicator guide is the reference for the editor workflow.

Use a new script and a separate test layout so you can compare changes cleanly. Replace the template with the downloaded source, save it under an identifiable version name and choose Add to chart. Read any compiler errors instead of assuming that a visible editor tab means the script is running.

Here is the complete version used for our checks:

// Original educational example v1.00, 26 September 2026. MIT licence.
//@version=6
indicator("RoboXpert EMA RSI Lab v1.00", overlay = true)
emaLength = input.int(20, "EMA length", minval = 1)
rsiLength = input.int(14, "RSI length", minval = 1)
rsiThreshold = input.float(50, "Minimum RSI (strictly above)", minval = 0, maxval = 100)
emaValue = ta.ema(close, emaLength)
rsiValue = ta.rsi(close, rsiLength)
crossUp = ta.crossover(close, emaValue)
signal = barstate.isconfirmed and crossUp and rsiValue > rsiThreshold
plot(emaValue, "EMA", color = color.rgb(40, 95, 199), linewidth = 2)
plotshape(signal, title = "Confirmed signal", style = shape.triangleup,
     location = location.belowbar, color = color.rgb(40, 95, 199), size = size.small, text = "RX")
plot(rsiValue, "RSI (data window)", display = display.data_window)
plot(crossUp ? 1 : 0, "Cross up (1=yes)", display = display.data_window)
plot(signal ? 1 : 0, "Confirmed signal (1=yes)", display = display.data_window)
plot(barstate.isconfirmed ? 1 : 0, "Bar confirmed (1=yes)", display = display.data_window)
alertcondition(signal, "RX confirmed cross", "RX educational signal: {{ticker}} {{interval}} close={{close}}. Not an order.")

The script compiled and appeared on our chart. That establishes a usable indicator instance, not a trading edge. Our check used BINANCE:BTCUSDT, standard one-minute candles, EMA 20, RSI 14, on 26 September 2026. Chart time was UTC+2. This continuously traded market supplied a Saturday observation window; its selection is not a recommendation to trade it.

Check a positive and a negative case

Open TradingView’s Data Window and select the bar being inspected. Use the fields from the script rather than inferring an exact EMA or RSI value from the drawing.

We inspected the bar opening at 13:13 UTC+2 on 26 September 2026 after it had closed. The displayed values were close 84,183.43, EMA 84,161.82 and RSI 58.64. The crossing, confirmed-bar and final-signal fields all showed 1 with threshold 50. Values below are the rounded interface readings, not a separately reconstructed exchange dataset.

Scroll horizontally if needed

CheckRSI thresholdCross upBar confirmedFinal signal
13:13 closed bar, original inputs50111
Same bar, rejection test100110
13:14 closed bar, rejection-test inputs100010
13:13 after restoring inputs and reloading50111

For the controlled negative test, we changed only the threshold to 100. Because the rule requires RSI to be strictly above it, the marker disappeared even though the crossing was still true. This is deliberately an unreachable filter condition, not a candidate trading configuration.

Original TradingView chart with the blue EMA and RX markers using lengths 20 and 14 and RSI threshold 50.
Original TradingView export, 26 September 2026 at 13:31 UTC+2. Parameters 20 / 14 / 50 produce historical RX markers. The chart is an indicator-function example, not a trading record.
The same TradingView teaching indicator with RSI threshold 100: the EMA remains and RX markers are absent.
Controlled negative test at 13:33 UTC+2: threshold 100 blocks every RX marker while preserving the EMA. These are separate time-stamped exports; the rightmost live bar and chart scaling can differ.

Also check a case where price is above the EMA but did not cross on that bar. At 13:14, the displayed close was 84,171.85, EMA 84,162.78 and RSI 54.06, while Cross up was 0. Being above the line is not itself a new crossing. This observation was taken with threshold 100; it isolates the crossing field rather than claiming another threshold-50 signal test.

Separate the open bar from the closed bar

An indicator recalculates as realtime prices update. In this code, the EMA and RSI can move on the open bar, but the final signal also requires barstate.isconfirmed. TradingView documents that condition as true on historical bars and on the closing update of a realtime bar. Source: bar states.

During our observation at 13:30:53 UTC+2, the current 13:30 bar showed confirmation 0 and signal 0, with RSI 43.72. After it closed, we inspected the same bar at 13:37:03: confirmation was 1, RSI displayed 43.71, and the signal remained 0. This observes a no-signal bar across the boundary; it does not demonstrate a qualifying realtime crossing or delivered alert.

After restoring threshold 50 and reloading the saved layout, the historical 13:13 signal and its displayed EMA/RSI values matched the earlier reading. That is a limited reproducibility check on one historical signal, not proof that the script can never change its historical output under every data or configuration change.

TradingView’s repainting documentation distinguishes several causes of differences between historical and realtime behavior. Confirming the chart bar addresses one timing issue here. It does not justify a universal “non-repainting” guarantee for a later version that adds other timeframes, different data or backward placement of markers. Use our practical repainting test to examine those timing differences on an existing indicator.

Create the Pine Script alert and check the alert log

alertcondition() exposes a selectable event. It does not create a running alert by itself. Choose the indicator and RX confirmed cross, then Same as chart: 1 minute and Once per bar close. Our initial default-input check stopped at this dialog. We subsequently ran the following separate realtime experiment.

Observed realtime alert: a separate input profile

On 26 September 2026 we used the unchanged v1.00 source on BINANCE:BTCUSDT, standard 1-minute candles, with EMA 2 / RSI 2 / threshold 0. These deliberately short fixture inputs increase the opportunities to observe the event; they are not trading recommendations or a test of the default 20 / 14 / 50 setup.

We created the alert at 15:29:07 UTC+2, with the bar-close trigger and all notification destinations disabled. The TradingView Log recorded an event at 15:30:01 with the resolved message RX educational signal: BTCUSDT 1 close=83932.00. Not an order. We captured that entry and subsequently paused the test alert. This establishes a realtime server-side condition event recorded by TradingView; it does not establish email, push, webhook delivery or order execution.

Original TradingView alert log showing the educational BTCUSDT one-minute event at 15:30:01 with close 83932.00.
Original TradingView capture, 26 September 2026. Inputs 2 / 2 / 0 and Once per bar close. The Log contains the triggered event; external notification destinations were disabled.

To create your own alert, choose that condition, confirm the interval and bar-close trigger, review the message and notification destination, then create it. Check the resulting alert in the Alerts panel. An old marker on the chart will not retroactively trigger it: alerts operate on realtime events.

TradingView runs a saved snapshot of the script, its inputs, symbol and timeframe for an alert. Changing the chart or code later does not update an existing alert automatically; recreate it when those changes should affect its behavior. Source: TradingView alerts.

If an expected event is missing or uses old inputs, follow our TradingView alert troubleshooting guide. Its separate A/B probe demonstrates the saved-copy mismatch and distinguishes a missing condition event from missing notification delivery.

Use the same signal variable for the marker and the alert condition, as this example does. Duplicating the logic in two places makes it easier to change one and forget the other. Even shared logic does not prove notification delivery; observe an actual qualifying realtime event and its alert log separately.

An indicator is not an automated trading system

This script declares indicator(). It draws information and exposes an alert event. It has no position sizing, stop loss, exit logic, order submission or account reconciliation.

A Pine strategy() adds simulated trading through TradingView’s broker emulator, which is a different kind of program. It does not by itself automate orders through the connected trading-panel broker. External execution requires additional infrastructure and separate tests of the entire chain. Sources: strategies and automatic trading limitations. Our TradingView indicator vs strategy comparison runs the same confirmed signal as an indicator and as a strategy: the marker appears on one candle, the simulated market-order fill on the next.

That distinction matters before asking AI to “turn this into a bot.” A marker can match its rule perfectly while the rule has no useful trading advantage. A correct strategy simulation can still omit operational problems outside the emulator. Use our backtest versus live comparison when assessing the next stage of evidence.

Download, reproduce and change one thing

Download the Pine project (ZIP). Original Pine v6 source, observed chart values, a reproduction checklist and MIT license. A teaching indicator, not a trading strategy.

Start by reproducing the default indicator and the threshold-100 rejection test. Record the script version, full symbol including exchange, candle type, timeframe, timezone and inputs. Preserve screenshots and the values you compared.

Then change one behavior, such as the RSI boundary from strictly above to at least the threshold, and add a corresponding equality case. An AI assistant can help write that change; your test should show whether it implements the intended difference.

Friendly robot illustration representing the RoboXpert pen name.
AI-generated avatar

About the author

RoboXpert

Pen name

The person behind RoboXpert writes about expert advisors, trading evidence and programming, and develops their own trading software. They report 10 years of experience in these areas; this is self-reported, not an independently verified qualification or performance record.

Sources & further reading

Your next question

Continue reading

TradingView & indicators

TradingView Indicator vs Strategy: What Can Actually Trade?

A TradingView indicator shows signals; a strategy adds simulated orders. Neither sends Pine orders to a broker directly. Tested with two matched scripts.

Read the guide →
TradingView & indicators

TradingView Alerts Not Working? A Tested Troubleshooting Guide

Find where a TradingView alert fails: signal, saved alert or notification. In our test, an existing alert kept its saved inputs after a chart change.

Read the guide →