I'm trying to figure if there is a way to create TRIX indicator by passing in both the period and signal length. From what I can see, the one that comes with LEAN only allows one parameter - the period. Is there a way to pass in both the period and signal length?
Here's a snippet
from AlgorithmImports import *
### <summary>
### EMA cross with SP500 E-mini futures
class Test(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2022, 1, 1)
self.SetEndDate(2023, 8, 18)
self.SetCash(1000000)
slowPeriod = 200
self.SetWarmUp(slowPeriod)
# Adds the future that will be traded
self.future = self.AddFuture(Futures.Indices.MicroNASDAQ100EMini)
self.future.SetFilter(lambda x : x.FrontMonth())
self._slow = ExponentialMovingAverage(slowPeriod)
self.trix1 = TripleExponentialMovingAverage(17)
# Pointer to track front month contract
self.frontmonthContract = None
def OnData(self, slice):
if self.IsWarmingUp: return
for chain in slice.FuturesChains:
# Trades bars for contracts in chain
tradebars = chain.Value.TradeBars
contracts = [contract for contract in chain.Value]
# If front month contract is updated
if self.frontmonthContract == None or contracts[0].Symbol != self.frontmonthContract.Symbol:
# contracts has only 1 element, the front month contract
self.frontmonthContract = contracts[0]
symbol = self.frontmonthContract.Symbol
# Update SMA with tradebar data
price = 0
if symbol in tradebars.Keys:
tradebar = tradebars[symbol]
price = tradebar.Close
self._slow.Update(tradebar.EndTime, tradebar.Close)
self.trix1.Update(tradebar.EndTime, tradebar.Close)
if self._slow.IsReady and self.trix1.IsReady:
if not self.Portfolio.Invested:
if price != 0 and price > self._slow.Current.Value:
self.MarketOrder(self.frontmonthContract.Symbol, 1)
self.Debug(f"Symbol: {symbol}, Expiry: {self.frontmonthContract.Expiry}, SMA: {self._slow.Current.Value}")
def OnEndOfDay(self, symbol):
self.Plot("Slow", self._slow)
self.Plot("trix", self.trix1)
def OnOrderEvent(self, orderEvent):
self.Log(str(orderEvent))
Yardley
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!