A TradingView alert can say which ticker moved and in which direction. It has no built-in placeholder for a strike or an expiration, so unless the message text names the contract, it can't say which option to trade. The program that receives the alert then has to choose the contract from rules written in advance. Those rules cover the expiration, the strike, the liquidity of the quote and the cases where no order should go out.
Throughout, a bullish alert buys a call and a bearish alert buys a put.
What does a TradingView alert carry?
An alert message is text with placeholders that TradingView fills when the alert fires. {{ticker}} gives the symbol's ticker, with AAPL and BTCUSD as the page's examples. {{close}} and {{time}} give the closing price and the time of the bar that triggered the alert. On a strategy, {{strategy.order.action}} returns buy or sell, and {{strategy.market_position}} returns long, flat or short.
That list has no placeholder for a strike, an expiration or a delta. A script can still send one, because the message is free text and {{plot_0}} to {{plot_19}} carry the values an indicator outputs. TradingView's part ends at delivery, which its webhook guide describes as a POST request to your URL with the message as its body. Unless the message names the contract, the receiver decides it.
What identifies one option contract?
Four facts do. The Options Industry Council's introduction describes a contract as fixing a strike price and carrying an expiration date. The underlying and the choice of call or put complete the set.
Brokers pack all four into one symbol. tastytrade's symbology page lays out the OCC format as a root of "up to 6 alphanumeric characters, right-padded with spaces", a six-digit expiration, C or P, and eight digits holding the "strike multiplied by 1000". It warns, "Note the padding spaces between root and expiration are significant." Alpaca's options page writes its example without padding, as AAPL240119C00100000. Reading the symbol from your broker's own chain avoids building it by hand.
OIC's basics page puts the usual contract size at 100 shares, so a premium quoted at 2.10 costs 210 dollars per contract.
How do you choose the expiration?
Write the rule as a window in days and take the nearest listed expiry inside it. A same-day strategy sets the window to today. A swing strategy might ask for the first expiry at least two weeks out.
The list of real expirations has to come from the broker. OIC notes that standard monthly options usually expire on the third Friday, and that "Many products now offer short-term options with weekly expirations, so investors should know the exact contract terms, including expiration dates, for all contracts they trade." A date computed from the calendar can miss a holiday, or assume weeklies on a ticker that has none.
Two API details bite here. Tradier's chain reference says "The expiration parameter must be a date the underlying symbol actually has options listed for." Pass an unlisted date and there is no error, because "it returns an empty response." Alpaca's contracts route has a short default horizon, listed on its options page as "expiration_date_lte: Next weekend", so a swing rule must send its own date range.
The window matters because of time decay. OIC's page on Theta says "options with the least remaining time until expiration will tend to decay the most."
What if an earnings date falls inside the window?
"Nearest listed expiry" can land on a contract whose life includes a scheduled event, such as an earnings report. That contract is priced for the event. OIC's volatility page defines implied volatility as "a measure of how much the marketplace expects the asset price to move based on the price of the option." A premium that holds an expected event move can't be compared with the same strike in a quiet week.
The alert carries no event calendar, so the rule needs one from another source. Then make the choice explicit. Either refuse the order when an event sits between today and the expiry, or place it and mark the log line so the event premium is visible. Picking such a contract silently is the outcome to avoid.
How do you choose the strike?
Two rules are common. One takes a fixed distance from the underlying price. The other targets a delta. OIC's Delta page says "Delta is a theoretical estimate of how much an option's premium may change given a $1 move in the underlying." It gives the range too, "Call Deltas range from 0.00 to 1.00 while put Delta ranges from 0.00 to -1.00."
A delta rule picks the listed strike closest to the target and then measures the miss. Asking for 0.30 and accepting 0.62 because it was nearest defeats the rule, so set a band and treat anything outside it as a refusal.
Delta comes from the broker's chain. Alpaca's option chain route "provides the latest trade, latest quote, and greeks for each contract symbol of the underlying symbol." Tradier returns greeks when the request sets greeks=true, along with an updated_at field described as "The timestamp indicating when the greeks and implied volatility values were last calculated." Compare that timestamp with the clock before trusting the number.
How do you check liquidity before sending?
Read the quote for the chosen contract and test it. Alpaca's chain returns bp and ap, which the reference calls "The best bid and ask information for a given option." Tradier's chain lists bid, ask, volume and open_interest for each contract.
Run three tests. The bid must be above zero. The gap between bid and ask must stay under a limit you set, in cents or as a fraction of the mid price. Open interest must clear a floor.
Check which feed the quote came from. Alpaca's reference says "indicative is a free indicative feed where trades are delayed and quotes are modified." A spread test on modified quotes tells you little.
Which order type and size should the rule use?
Use a limit order priced from the quote you just checked. Alpaca's orders page says of market orders that "your fill price may slip depending on the available liquidity at each price level". On a wide option quote that slip can be large.
Size in whole contracts. Alpaca's option validations include "Ensuring qty is a whole number" and "time_in_force must be day or gtc". Divide the budget by the limit price times 100 and round down. A result of zero is a refusal.
The side stays the same for both directions under that mapping. Tradier's option order reference lists side as "One of: buy_to_open, buy_to_close, sell_to_open, sell_to_close". A bearish alert opens a put with buy_to_open, the same side a bullish alert uses for a call.
When should the rule refuse to trade?
A rule that always finds a contract will sooner or later find a bad one. Write each refusal to the log beside the alert that caused it.
| Refusal | Condition |
|---|---|
| No expiry in the window | The broker lists no expiration inside it |
| Strike too far from target | The nearest delta falls outside the band |
| Stale greeks | The greeks timestamp is older than your limit |
| Thin or one-sided quote | Zero bid, wide spread or low open interest |
| Event before expiry | An earnings date or similar sits inside the contract's life |
| Market closed | The contract's own session isn't open |
| Budget below one contract | The limit price times 100 exceeds the budget |
| Account not approved | On Alpaca, buying a call or put needs options level 2 |
Don't hard-code one closing time for the market-closed check. Cboe's hours page runs regular hours for equity options on its C1 exchange from 9:30 a.m. until 4:00 p.m. ET. ETF options that trade until 4:15 p.m. stay inside that regular session, and the core session on its BZX, C2 and EDGX exchanges also ends at 4:15 p.m. C1 lists Global Trading Hours for select equity options from 7:30 a.m. to 9:25 a.m. as well.
What happens at the exit and at expiration?
An exit alert built from the same placeholders names the ticker again and no contract. Store the contract symbol chosen at entry and close that exact symbol, with sell_to_close on Tradier.
Don't leave a long option to expire by accident. Alpaca's options page says "By default, Alpaca will automatically exercise in-the-money (ITM) contracts at expiry." When the account can't afford the exercise, "Alpaca will sell-out the position within 1 hour before expiry." Add a rule that closes any open contract before its last session if no exit alert has arrived.
How do you test the rules?
Run them on a paper account and read every refusal. Options trading is on by default in Alpaca's paper environment, per its options page. Its paper trading page warns that a paper order can fill at a size far beyond the liquidity that is really there. Paper fills on thin contracts therefore prove less than the log of what the rule declined.
| Symptom | Likely cause | Where it is documented |
|---|---|---|
| Chain comes back empty | The expiration date isn't listed for that ticker | Tradier chain reference |
| Only this week's contracts appear | Default expiration_date_lte on the contracts route |
Alpaca options page |
| Contract lookup fails | Padding in the OCC root differs by broker | tastytrade symbology page |
| Order rejected | Fractional qty, or a time_in_force other than day or gtc
|
Alpaca options page |
AI tools wrote this article. Its facts were checked against the official docs linked above.
Trading involves risk of loss.
Top comments (2)
One more refusal worth writing down: an earnings date between now and the chosen expiry. "Nearest listed expiry inside the window" can silently pick a contract that carries the event. Example: MSFT reports Wed Oct 28 after the close, and the Oct 30 ATM straddle (strike 532.5, mid about $28.00 on a $532.6 spot) is roughly 5.3% of spot as of the Oct 26 close. That price holds the Thursday reaction session plus the ordinary days around it, so it is not comparable to a non-event week. A rule that checks the earnings calendar and either refuses or tags the order as "event premium included" makes that choice visible instead of accidental.
@signumhq Good catch, worth writing down for anyone building this themselves. Nyria doesn't screen for earnings dates today, so "nearest listed expiry" can land right on an event week with no flag. Until that exists, the fix sits with the alert: keep earnings out of your selection window, or price the event premium in before you size it.