diff --git a/project-templates/csharp/index-options-static/Main.cs b/project-templates/csharp/index-options-static/Main.cs index 6661a1d99e..9c7817d22b 100644 --- a/project-templates/csharp/index-options-static/Main.cs +++ b/project-templates/csharp/index-options-static/Main.cs @@ -78,9 +78,14 @@ public override void Initialize() // Warm-up the option contracts as soon as it is added to the algorithm Settings.SeedInitialPrices = true; - // The EMA/price cross will determine we trade ATM contracts + // The EMA/price cross will determine we trade ATM contracts var index = AddIndex("SPX"); - EMA(index.Symbol, 60).Updated += TradeAtTheMoneyContract; + var ema = EMA(index.Symbol, 60); + // To use a manual EMA instead, replace the automatic indicator above with: + // var ema = new ExponentialMovingAverage(60); + // WarmUpIndicator(index.Symbol, ema); + // RegisterIndicator(index.Symbol, ema); + ema.Updated += TradeAtTheMoneyContract; _optionChainSymbol = QuantConnect.Symbol.CreateCanonicalOption(index, "SPXW", Market.USA, "?SPXW"); } @@ -88,14 +93,14 @@ public override void Initialize() public void TradeAtTheMoneyContract(object sender, IndicatorDataPoint current) { // Pace trades every 10 minutes - var lastTrateTime = _lastTicket?.Time ?? DateTime.MinValue; - if ((UtcTime-lastTrateTime).TotalMinutes < 10) return; + var lastTradeTime = _lastTicket?.Time ?? DateTime.MinValue; + if ((UtcTime-lastTradeTime).TotalMinutes < 10) return; var ema = sender as ExponentialMovingAverage; if (!ema.IsReady) return; var spot = Securities[current.Symbol].Price; - + if (spot > current && spot > ema[-1]) { var atmCall = GetAtTheMoneyContract(OptionRight.Call, spot); @@ -129,7 +134,7 @@ private Option GetAtTheMoneyContract(OptionRight right, decimal spot) { return null; } - + return AddOptionContract(atm); } } diff --git a/project-templates/python/index-options-static/main.py b/project-templates/python/index-options-static/main.py index 21b75849ce..60d10333ea 100644 --- a/project-templates/python/index-options-static/main.py +++ b/project-templates/python/index-options-static/main.py @@ -15,9 +15,14 @@ def initialize(self) -> None: # Warm-up the option contracts as soon as it is added to the algorithm self.settings.seed_initial_prices = True - # The EMA/price cross will determine we trade ATM contracts + # The EMA/price cross will determine we trade ATM contracts index = self.add_index("SPX") - self.ema(index, 60).updated += self._trade_at_the_money_contract + ema = self.ema(index, 60) + # To use a manual EMA instead, replace the automatic indicator above with: + # ema = ExponentialMovingAverage(60) + # self.warm_up_indicator(index, ema) + # self.register_indicator(index, ema) + ema.updated += self._trade_at_the_money_contract self._option_chain_symbol = Symbol.create_canonical_option(index, "SPXW", Market.USA, "?SPXW") @@ -29,7 +34,7 @@ def _trade_at_the_money_contract(self, ema: ExponentialMovingAverage, current: I if not ema.is_ready: return spot = self.securities[current.symbol].price - + if spot > current.value and spot > ema[-1].value: atm_call = self._get_at_the_money_contract(OptionRight.CALL, spot) if atm_call and not atm_call.invested: