text: import numpy as np
  from actions import Action
  from QuantConnect import *
  from QuantConnect.Parameters import *
  from QuantConnect.Benchmarks import *
  from QuantConnect.Brokerages import *
  from QuantConnect.Util import *
  from QuantConnect.Interfaces import *
  from QuantConnect.Algorithm import *
  from QuantConnect.Algorithm.Framework import *
  from QuantConnect.Algorithm.Framework.Selection import *
  from QuantConnect.Algorithm.Framework.Alphas import *
  from QuantConnect.Algorithm.Framework.Portfolio import *
  from QuantConnect.Algorithm.Framework.Execution import *
  from QuantConnect.Algorithm.Framework.Risk import *
  from QuantConnect.Indicators import *
  from QuantConnect.Data import *
  from QuantConnect.Data.Consolidators import *
  from QuantConnect.Data.Custom import *
  from QuantConnect.Data.Fundamental import *
  from QuantConnect.Data.Market import *
  from QuantConnect.Data.UniverseSelection import *
  from QuantConnect.Notifications import *
  from QuantConnect.Orders import *
  from QuantConnect.Orders.Fees import *
  from QuantConnect.Orders.Fills import *
  from QuantConnect.Orders.Slippage import *
  from QuantConnect.Scheduling import *
  from QuantConnect.Securities import *
  from QuantConnect.Securities.Equity import *
  from QuantConnect.Securities.Forex import *
  from QuantConnect.Securities.Interfaces import *
  from datetime import date, datetime, timedelta
  from QuantConnect.Python import *
  from QuantConnect.Storage import *
  QCAlgorithmFramework = QCAlgorithm
  QCAlgorithmFrameworkBridge = QCAlgorithm
  
  class MultidimensionalTransdimensionalSplitter(QCAlgorithm):
      
      def Initialize(self):
          self.SetCash(100000)
  
          self.SetStartDate(2017,9,1)
          self.SetEndDate(2020,9,1)
  
          self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
  
          self.lookback = 20
  
          self.ceiling, self.floor = 30, 10
  
          self.initialStopRisk = 0.98
          self.trailingStopRisk = 0.9
  
          self.Schedule.On(self.DateRules.EveryDay(self.symbol), \
                          self.TimeRules.AfterMarketOpen(self.symbol, 20), \
                          Action(self.EveryMarketOpen))
  
      def OnData (self, data):
          self.Plot("Data Chart", self.symbol, self.Securities[self.symbol].Close)
  
      def EveryMarketOpen(self):
          close = self.History(self.symbol, 31, Resolution.Daily)["close"]
          todayvol = np.std(close[1:31])
          yesterdayvol = np.std(close[0:30])
          deltavol = (todayvol - yesterdayvol) /todayvol
          self.lookback = round(self.lookback * (1 + deltavol))
  
          if self.lookback > self.ceiling:
              self.lookback = self.ceiling
          elif self.lookback < self.floor:
              self.lookback = self.floor
  
          self.high = self.History(
                      self.symbol, self.lookback, Resolution.Daily)["high"]
  
          if not self.Securities[self.symbol].Invested and \
                  self.Securities[self.symbol].Close >= max(self.high[:-1]):
              self.SetHoldings(self.symbol, 1)
              self.breakoutlvl = max(self.high[:-1])
              self.highestPrice = self.breakoutlvl
  
  
          if self.Securities[self.symbol].Invested:
              if not self.Transactions.GetOpenOrders(self.symbol):
                  self.StopMarketTicket = self.StopMarketOrder(self.symbol, \
                                          -self.Portfolio[self.symbol].Quantity, \
                                          self.initialStopRisk * self.breakoutlvl)
  
              if self.Securities[self.symbol].Close > self.highestPrice and \
                      self.initialStopRisk * self.breakoutlvl < self.Securities[self.symbol].Close \
                          * self.trailingStopRisk:
                  self.highestPrice = self.Securities[self.symbol].Close
                  updateFields = UpdateOrderFields()
                  updateFields.StopPrice = self.Securities[self.symbol].Close * self.trailingStopRisk
                  self.StopMarketTicket.Update(updateFields)
  
                  self.Debug(updateFields.StopPrice)
  
              self.Plot("Data Chart", "Stop Price", self.StopMarketTicket.Get(OrderField.StopPrice))
  