Back to Blog
5 min read

Pine Script for Options Trading: Strategy Alerts to IBKR via TradingView

How to use Pine Script for options trading strategies on TradingView — write custom option signal scripts, create strategy alerts, and send option orders to IBKR through webhooks or chart-native execution.

Posted by

Quick Answer

Pine Script is TradingView's built-in scripting language for custom indicators and strategies. While Pine Script cannot directly execute options orders, you can use it to generate options trading signals that trigger either webhook-based execution (via PickMyTrade/TradersPost) or visual chart signals for manual execution with chart-native tools like OptionTrigger. This guide covers both approaches, their limitations, and realistic workflows.


Part 1: What Pine Script Can (and Can't) Do for Options

What It CAN Do

  • Generate buy/sell signals based on technical conditions
  • Plot custom indicators, levels, and zones
  • Send webhook alerts with JSON payloads
  • Reference built-in indicators (RSI, MACD, Bollinger Bands, etc.)
  • Access price, volume, and time data
  • Use multiple timeframes in a single script

What It CANNOT Do

  • Access options chain data (strikes, bid/ask, IV, Greeks)
  • Place orders directly through any broker
  • Backtest options strategies with accurate options P&L
  • Track options positions or portfolio metrics
  • Calculate options-specific Greeks or pricing models

Bottom line: Pine Script is a signal generator, not an options execution engine. Combine it with execution tools for a complete workflow.


Part 2: Writing Options Signal Scripts

Example 1: IV Rank-Based Signal Filter

If you want to buy premium only when IV is low or sell premium only when IV is high, you need IV data. Pine Script doesn't have built-in options IV, but you can import it:

//@version=5
indicator("IV Rank Filter (External)", overlay=true)

// IV Rank would come from an external source
// https://www.tradingview.com/pine-script-docs/en/v5/concepts/Alternative_data.html
iv_rank = input.float(50, "IV Rank Threshold")

// Your signal logic
buy_signal = ta.crossover(ta.rsi(close, 14), 30) // and iv_rank < 30
sell_signal = ta.crossunder(ta.rsi(close, 14), 70) // and iv_rank > 70

plotshape(buy_signal, title="Buy", location=location.belowbar, color=color.green, style=shape.triangleup)
plotshape(sell_signal, title="Sell", location=location.abovebar, color=color.red, style=shape.triangledown)

// Webhook alert
alertcondition(buy_signal, title="Options Buy Signal", message='{"action":"buy","symbol":"{{ticker}}","price":"{{close}}"}')

Example 2: Range Breakout Strategy

//@version=5
strategy("Options Range Breakout", overlay=true)

// Define the range (first 30 minutes)
is_range_period = time(timeframe.period, "0930-1000:1234567")
range_high = ta.highest(high, 1)
range_low = ta.lowest(low, 1)

// Breakout signals
long_signal = ta.crossover(close, range_high)
short_signal = ta.crossunder(close, range_low)

if long_signal
    strategy.entry("Long Call", strategy.long)
    alert("Bullish breakout — consider ATM call", alert.freq_once_per_bar_close)
    
if short_signal
    strategy.entry("Long Put", strategy.short)
    alert("Bearish breakdown — consider ATM put", alert.freq_once_per_bar_close)

Example 3: Multi-Timeframe Confluence

//@version=5
indicator("Options Confluence Signal", overlay=true)

// Higher timeframe trend
htf_trend = request.security(syminfo.tickerid, "60", close > ta.sma(close, 20))

// Lower timeframe entry
entry_trigger = ta.crossover(ta.rsi(close, 14), 30) and htf_trend

plotshape(entry_trigger, title="Confluence Buy", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)

alertcondition(entry_trigger, title="Confluence Options Signal", message='{"symbol":"{{ticker}}","price":"{{close}}","time":"{{time}}","timeframe":"{{interval}}"}')

Part 3: Webhook Execution Path

Step 1: Create the Alert

In TradingView, create an alert on your Pine Script indicator:

  1. Click the alarm clock icon
  2. Set condition to your alertcondition
  3. Check "Webhook URL"
  4. Enter your relay service's webhook URL
  5. Customize the JSON message

Step 2: Configure the Relay

PickMyTrade example:

{
  "action": "buy",
  "symbol": "{{ticker}}",
  "price": "{{close}}",
  "quantity": 1,
  "orderType": "OPT",
  "expiry": "2026-06-09",
  "strike": 520,
  "right": "CALL"
}

TradersPost example:

{
  "ticker": "{{ticker}}",
  "action": "buy",
  "price": "{{close}}",
  "sentBy": "PineScript_Strategy_v1"
}

Step 3: Test with Paper Trading

Always test webhook alerts in paper trading first:

  1. Small position size (1 contract)
  2. Verify the alert fires correctly
  3. Check that the order reaches your broker
  4. Confirm fills are at expected prices
  5. Monitor for alert misfires

Webhook Limitations

  • Cooldown: 15-30 seconds between alert firings (depending on TradingView plan)
  • Latency: Alert → Webhook → Broker = 1-3 seconds total
  • Static messages: Can't dynamically reference option chain data
  • No fill confirmation: Alert fires blind — no feedback on whether order actually filled

Part 4: Chart-Native Execution Path

For traders who prefer visual execution over coded alerts, OptionTrigger takes a different approach:

Workflow

  1. Pine Script provides the signal — Visual indicator on your chart shows buy/sell zones
  2. You validate the signal — Confirm against other timeframes, IV, market context
  3. You click to execute — Click the strike level on the chart overlay
  4. Bracket order fires instantly — Entry + TP + SL sent to IBKR TWS in <100ms

Why This Works Better for Options

  • Options need IV, bid/ask, and strike context — not just "buy at this price"
  • The human validates the signal against the full options context
  • Instant execution with bracket orders — no webhook delay
  • Visual confirmation — you see the trade on the chart before you click

Combining Both

The most powerful approach:

  1. Pine Script = your research assistant (finds setups)
  2. Your brain = the strategy filter (validates context)
  3. OptionTrigger = the execution engine (fast, reliable, local)

Part 5: Realistic Expectations

What Pine Script + Options Automation Can Realistically Achieve

  • Semi-automated signal generation — Pine Script finds setups based on your rules, you execute
  • Systematic discipline — Remove emotional entries; only trade when script conditions are met
  • Consistent risk rules — Same position size, same exit criteria, every time
  • Alert-based monitoring — Get notified when setups form without staring at charts

What It Cannot Do

  • "Set and forget" options trading — Options need active management (Greeks change, IV changes, expiration approaches)
  • Complex multi-leg strategy execution — Webhooks and chart-native tools handle single-leg primarily
  • True options backtesting — Use dedicated options analysis software for this
  • Replace trading skill — Automation amplifies good process; it doesn't create it from nothing


Pine Script is a tool, not a guarantee. All automated trading carries risk. Test thoroughly in paper trading before using real capital. TradingView plan limits may affect webhook frequency. Options trading involves substantial risk of loss.