OPEN-SOURCE SCRIPT

Covered Call Strike Optimizer

453
Covered Call Strike Optimizer
A TradingView Pine Script (v6) that projects OTM covered call strike levels at the start of each period and scores each method's historical accuracy by measuring how close the predicted level was to the actual closing price at period end.

What It Does
At the beginning of each period the script snapshots a strike price for every enabled study method. At the end of each period it measures how far each projected level was from where price actually closed, accumulating the error over every period in your chart history. The results table shows which method has historically been the tightest predictor for the specific symbol and timeframe you are analyzing.

This answers the question: "Which strike selection method would have put my covered call closest to where price actually ended up?"

The Math
HV Expected Move (purple) — most rigorous
Uses the Black-Scholes 1-sigma expected move formula:

strike = open × (1 + HV_annualized × sqrt(DTE / 252))
sqrt(DTE / 252) correctly de-annualizes the volatility to the exact period length. This is the same math options market makers use to price contracts. The HV lookback measures the volatility regime and is always kept independent of DTE — it does not need to be auto-scaled because sqrt(DTE/252) already handles time-scaling.

ATR Levels (orange)
strike = period_open + (multiplier × ATR)
ATR measures the average range of one bar. The multiplier asks: how many typical bar-ranges might price travel over this entire period? For short-duration trades (e.g., 3-day or weekly), using ATR(14) measures volatility over a window 3–5× longer than the trade, which may reflect a stale regime. Auto-scaling sets the lookback to max(DTE, 10) so the smoothing window matches the trade horizon. A floor of 10 bars is enforced — fewer bars produces noisy estimates.

Standard Deviation (blue)
strike = period_open + (multiplier × StdDev(close, length))
SD measures the dispersion of closing prices over the lookback window. Same auto-scale logic as ATR — when enabled, length = max(DTE, 10).

Fixed % OTM (red)
strike = period_open × (1 + pct / 100)
No volatility adjustment. A simple directional assumption that price will not rise more than X% during the period.

Previous Period High (yellow)
The highest bar high from the prior completed period. Serves as a natural resistance level and potential OTM target on range-bound or mean-reverting symbols.

Results Table
Located in the top-right corner of the chart.

Column Description
Level Study name and multiplier
Price Current projected strike price
OTM % How far above today's close the strike sits right now
Avg Err% Average absolute % distance from the actual close across all periods
Avg $ Average absolute dollar distance from the actual close across all periods
Lower Avg Err% and Avg $ = the method historically predicted closest to where price actually closed.

Color Coding (Avg Err% and Avg $ columns)
Color Avg Error Interpretation
Lime < 10% Tight predictor — this level consistently landed close to close
Yellow 10–25% Moderate — useful directional guide but not precise
Red ≥ 25% Loose — strike was frequently far from where price closed
The footer row shows how many complete periods were analyzed. More periods = more reliable statistics.

Best-Row Highlight
The row with the lowest Avg Err% is highlighted with a faint white background glow — this is the method that historically placed the strike closest to where price actually closed. The highlight uses a 0.01% epsilon comparison to handle floating-point rounding.

Period Background Shading
Each period's final bar is shaded to show the covered call outcome relative to the HV 1-sigma level:

Green — price closed at or below HV 1σ (covered call likely expired worthless)
Red — price closed above HV 1σ (covered call was breached and likely required management)
Settings
Period
Setting Default Description
Expiration Cycle Monthly (21) Quick-select preset: 3-Day (3), Weekly (5), Monthly (21), Quarterly (63), or Custom
Custom DTE (bars) 21 Active only when Expiration Cycle = Custom
Auto-scale ATR & SD lookback to DTE ON When ON: ATR length = SD length = max(DTE, 10). Matches the smoothing window to your trade horizon. When OFF: use the manual length inputs in each study group. HV is never auto-scaled (already time-scaled via sqrt(DTE/252)).
DTE to bar count mapping (Daily chart):

Expiration Bars
3-Day 3
Weekly 5
Monthly 21
Quarterly 63
On a Weekly chart divide by 5. On an Hourly chart multiply by ~6.5.

ATR Levels (orange)
Setting Default Description
Show ATR Levels ON Toggle lines and table rows for all ATR levels
ATR Length (manual override) 14 Only used when Auto-scale is OFF
Multiplier 1 1.0x Strike = open + 1.0 × ATR
Multiplier 2 1.5x Strike = open + 1.5 × ATR
Multiplier 3 2.0x Strike = open + 2.0 × ATR
Multiplier 4 3.0x Strike = open + 3.0 × ATR
Standard Deviation Levels (blue)
Setting Default Description
Show SD Levels ON Toggle lines and table rows for all SD levels
SD Length (manual override) 20 Only used when Auto-scale is OFF
Multiplier 1 1.0σ Strike = open + 1.0 × SD
Multiplier 2 2.0σ Strike = open + 2.0 × SD
Multiplier 3 3.0σ Strike = open + 3.0 × SD
Historical Volatility / Expected Move (purple)
Setting Default Description
Show HV Expected Move ON Toggle HV lines and table rows
HV Lookback (bars) 30 Bars used to compute realized volatility. Not auto-scaled — HV is already time-adjusted via sqrt(DTE/252).
Fixed % OTM Levels (red)
Setting Default Description
Show % Levels ON Toggle fixed % lines and table rows
Level 1 % 5% Strike = open × 1.05
Level 2 % 10% Strike = open × 1.10
Level 3 % 15% Strike = open × 1.15
Previous Period High (yellow)
Setting Default Description
Show Prev High ON Toggle the prior period high line and table row
Display
Setting Default Description
Show Results Table ON Show/hide the accuracy table
Show Lines on Chart ON Master toggle for all dashed lines and labels. Turn OFF to see just the table without cluttering the chart. Individual study toggles still control their rows in the table.
Shade Period Background ON Green/red background shading at each period's close bar
Label Size Tiny Size of line labels: Tiny, Small, or Normal
How to Use
Step 1 — Select your expiration cycle
Set Expiration Cycle in the Period group to match your options strategy:

Trading 3-day options on a Daily chart → select 3-Day (3)
Trading weekly options on a Daily chart → select Weekly (5)
Trading monthly options on a Daily chart → select Monthly (21)
Trading monthly options on a Weekly chart → set Custom DTE to 4 or 5
Step 2 — Decide on auto-scaling
Leave Auto-scale ATR & SD lookback to DTE ON (recommended). This ensures ATR and SD are measuring volatility over the same number of bars as your trade lasts. For very short DTEs (3 or 5), the floor of 10 bars keeps estimates stable.

Turn it OFF if you prefer consistent, longer-term smoothing regardless of DTE — for example, if you always want ATR(14) as your baseline regardless of whether you're trading weeklies or monthlies.

Step 3 — Read the results table
Look at Avg Err% and Avg $. The rows with the lowest values (lime-colored) are the methods that historically placed the strike closest to where price actually closed. Use those as your primary strike selection candidates.

The Price and OTM % columns show where those same methods are projecting for the current active period.

Step 4 — Reduce chart clutter when needed
Toggle Show Lines on Chart OFF in Display settings to hide all dashed lines while keeping the results table. Individual study toggles (Show ATR Levels, Show SD Levels, etc.) let you focus on specific methods.

Tips
Run on a symbol with at least 50+ complete periods for statistically meaningful Avg Err% values. The footer shows the period count.
Compare cycles: switch between Weekly (5) and Monthly (21) presets to see which methods hold up across different time horizons.
HV Expected Move is the options-theory benchmark — it approximates what implied volatility is pricing in. If another method consistently beats it in Avg Err%, that is a meaningful signal for that symbol.
ATR and SD with auto-scale ON produce different lookback lengths for different cycles. A 3-day trade uses ATR(10) while a monthly trade uses ATR(21), giving each cycle an appropriately sized volatility window.
Prev Period High tends to work best on range-bound or mean-reverting symbols where prior resistance is respected.
Results are historical and backward-looking. Market regime changes (e.g., a volatility spike) can shift which method performs best going forward.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.