I am doing my best in following Docs and code-examples. Please tell me what I need to change such that I find Options above and below current Price. Ideally depending on the Price Change the Options found should also change.I only find Option above the Initial Underlying Price and nothing changes. I am expecting to find Option Below and Above the current Price and that
Log (not visible in attached Backtest)

// In Initialize
var option = AddOption("QQQ", Resolution.Minute);
_optionSymbol = option.Symbol;
// Set our strike/expiry filter for QQQ options
// -3% to +3% of current price, expiring in 0-1 days
option.SetFilter(u => u.Strikes(-3, 3)
.Expiration(0, 1)
.IncludeWeeklys());
// Schedule trading at hourly intervals during market hours
Schedule.On(DateRules.EveryDay("QQQ"),
TimeRules.Every(TimeSpan.FromHours(1)),
EvaluateOptions);
// In EvaluateOptions
// Filter contracts based on all required criteria
var filteredContracts = chain
//.Where(x => x.Right == (isUptrend ? OptionRight.Call : OptionRight.Put))
.Where(x => x.Expiry.Date <= DateTime.Now.Date.AddDays(1)) // Expires in 1 day or less
// Filter for strikes within our percentage range of the current price
// This calculates how far (in percentage terms) each strike is from the current price
// For example, with a 3% setting and a $400 underlying price, we'd include strikes from $388 to $412
.Where(x => Math.Abs(x.Strike / underlyingPrice - 1) <= _maxStrikeDistancePercent)
.OrderByDescending(x => x.Expiry)
.ThenByDescending(x => x.Right)
.ThenByDescending(x => x.Strike)
.ToList();
Mia Alissi
Here are the issues in your C# code that prevent you from consistently finding options both above and below the current underlying price as the underlying moves:
Bug 1: Static Strike Filtering in SetFilter
.Strikes(-3, 3)
inoption.SetFilter
selects fixed strike offsets (typically the 3rd lowest to 3rd highest strikes from the initial underlying price when the filter is first run at algorithm startup).Bug 2: Redundant/Conflicting Strike Filtering
EvaluateOptions
method, you attempt to re-filter the option contracts based on current underlying price, using: However, if the options universe fromSetFilter
no longer contains strikes near the live underlying price (because of a move), this extra filtering will find zero or too few contracts—because the universe itself did not update!How to Fix:
Replace
.Strikes(-3,3)
with a Dynamic Price-Based Filter.Strikes(-3,3)
, use a.Where(...)
clause in your filter that selects strikes within a percentage distance of the underlying price at filter time.Eliminate Double-Filtering
SetFilter
, you can simplify or remove the similar filtering inEvaluateOptions
.SetFilter
.Log to Verify
EvaluateOptions
to show the set of strikes you are receiving each time, confirming that as price changes, contracts above and below the price appear.Summary of What to Change in Your Code: Replace:
with:
Then, optionally remove the strike-based filtering in your
EvaluateOptions
.This will ensure you always see contracts both above and below current price as it moves, not “stuck” to the initial offsets.
Let me know if you'd like a ready-to-paste code section for your
Initialize
method or a minimal working code snippet!Sources: Universes - QuantConnect.com, Opening Range Breakout for Stocks in Play, Automating the Wheel Strategy, Options Universes - QuantConnect.com, Basic Template Options Filter Universe Algorithm
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Pranav Shah
Using your suggestion of adding the Where in SetFilter I get the following error in Build
'OptionUniverse' does not contain a definition for 'Strike' and no accessible extension method 'Strike' accepting a first argument of type 'OptionUniverse' could be found (are you missing a using directive or an assembly reference?)
Pranav Shah
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!