Quick answer
Pine Script is TradingView’s language for indicators and strategies. It runs on chart data and has no access to option chains or brokers, so it cannot place an options order. What it does well is find stock-price levels and signals. An options trader turns those into trades in one of two ways: send alerts to a webhook relay, or use the levels to plan and execute the option trade yourself.
What Pine Script can and cannot do for options
| Can | Cannot |
|---|---|
| Compute signals from price, volume and time | Read option chains, bid/ask or Greeks |
| Plot levels, zones and labels on the chart | Place orders with a broker |
| Combine timeframes with request.security() | Backtest option P&L with real spreads |
| Fire alerts, including webhook messages | Track your option positions |
Treat Pine as the signal and level layer. The option decisions, meaning contract, size and order price, live elsewhere.
Example 1: prior-high breakout with ta.highest(high[1], n)
The classic breakout level is the highest high of the previous N bars. Writing ta.highest(high[1], len) offsets the series by one bar, so the level excludes the current bar and does not move up with the bar that breaks it. ta.highest(high, len)[1] gives the same value.
//@version=6
indicator("Prior-high breakout", overlay = true)
len = input.int(20, "Lookback bars", minval = 2)
// [1] excludes the current bar from the window.
priorHigh = ta.highest(high[1], len)
priorLow = ta.lowest(low[1], len)
breakUp = ta.crossover(close, priorHigh)
breakDown = ta.crossunder(close, priorLow)
plot(priorHigh, "Prior high", color.green, style = plot.style_stepline)
plot(priorLow, "Prior low", color.red, style = plot.style_stepline)
plotshape(breakUp, "Breakout", shape.triangleup, location.belowbar, color.green)
plotshape(breakDown, "Breakdown", shape.triangledown, location.abovebar, color.red)
alertcondition(breakUp, "Breakout", "{{ticker}} crossed above the prior high at {{close}}")
alertcondition(breakDown, "Breakdown", "{{ticker}} crossed below the prior low at {{close}}")For an options trade the plotted lines matter as much as the signal: the prior high is a natural entry trigger for a call, the prior low a stop or a put trigger.
Example 2: opening-range levels
Many 0DTE and intraday traders work from the first 30 minutes’ range. This script records the high and low inside the session window and plots them once the range is complete.
//@version=6
indicator("Opening range", overlay = true)
session = input.session("0930-1000", "Opening range (exchange time)")
inRange = not na(time(timeframe.period, session))
var float orHigh = na
var float orLow = na
if inRange and not inRange[1]
orHigh := high
orLow := low
else if inRange
orHigh := math.max(orHigh, high)
orLow := math.min(orLow, low)
plot(inRange ? na : orHigh, "OR high", color.green, style = plot.style_linebr)
plot(inRange ? na : orLow, "OR low", color.red, style = plot.style_linebr)Use an intraday chart timeframe that divides the window evenly, such as 1, 5 or 15 minutes.
Example 3: a non-repainting higher-timeframe filter
A lower-timeframe trigger filtered by the hourly trend. Requesting the previous hourly value with lookahead_on is the standard way to avoid a filter that changes after the fact.
//@version=6
indicator("Hourly trend + RSI trigger", overlay = true)
hourlyUp = request.security(syminfo.tickerid, "60", (close > ta.sma(close, 20))[1], lookahead = barmerge.lookahead_on)
trigger = ta.crossover(ta.rsi(close, 14), 30) and hourlyUp
plotshape(trigger, "Long setup", shape.triangleup, location.belowbar, color.green, size = size.small)
alertcondition(trigger, "Long setup", "{{ticker}} long setup at {{close}} on {{interval}}")Turning a Pine signal into an option trade
Path 1: webhook relay
Create an alert on the script, enable the webhook URL of a relay service and put a JSON payload in the message. The relay maps it to an order with your broker. You must decide in the payload or the relay which contract to trade, and test duplicates, delays and rejections. Webhook alerts need a paid TradingView plan and two-factor authentication. See TradingView webhook automation.
Path 2: use the levels, execute on the chart
Keep the script as a visual guide. When it marks a breakout, draw an OptionTrigger plan on the same stock levels: entry near the prior high, targets above, stop below the level that invalidates the trade. Choose the call or put, review the AutoSize suggestion and click Buy. The local engine then sells the filled option position when the stock reaches your levels.
OptionTrigger does not read Pine alerts or webhooks; every entry is your click. That is a deliberate trade-off: no alert plumbing, and no automatic entries.
Realistic expectations
- A stock-price backtest says nothing about option fills, spreads or time decay.
- Short-dated options react to small moves; a signal that is fine for shares can be too slow for 0DTE.
- Repainting scripts look better in history than live. Check signals on bar close.
- Practice the execution in paper trading before risking capital.
Frequently asked questions
Can Pine Script trade options directly?
No. Pine Script runs inside TradingView with no broker access and no option chain data. It produces signals and alerts; a separate tool or your own action places the option order.
What does ta.highest(high[1], 20) do?
It returns the highest high of the 20 bars before the current one. The [1] shifts the series back a bar, so the current bar is excluded, which makes it a stable breakout level.
Can I backtest options strategies in Pine Script?
Only approximately. The strategy tester simulates trades on the chart symbol, usually the stock, without option spreads, Greeks or real fills. Use it to test the signal, then paper trade the option execution.
How do I send a Pine Script options signal to IBKR?
Either send a webhook alert to a relay service that supports IBKR, or use the script’s levels to plan the trade on the chart and execute through a tool connected to TWS or IB Gateway, such as OptionTrigger.