Hello!
I am new to Quant connect and am having a hard time building a system to detect support and resistance lines. I was thinking of using a the DEMA and MOM indicators for this but I can't seem to figure out how to use the results from the DEMA in the MOM indicator. If anyone can help me put that'd together that'd be great!
Here is my code
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
# Setting up Dates and Intial Cash
self.SetStartDate(2021,1, 1)
self.SetEndDate(2021,12,20)
self.SetCash(100000)
# Add Bitcoin
bit = self.AddCrypto("BTCUSD", Resolution.Daily)
bit.SetDataNormalizationMode(DataNormalizationMode.Raw)
self.bit = bit.Symbol
self.SetBenchmark(self.bit)
self.dema = self.DEMA(self.bit, 20)
self.mom1 = (self.MOM(self.bit, self.dema.Current.Value))
self.mom2 = self.MOM(self.bit, self.mom2.Current.Value)
self.str = self.STR(self.bit, 10, 3, MovingAverageType.Wilders, Resolution.Daily)
close_price = 0
# Plotting
stockPlot = Chart('Trade Plot')
stockPlot.AddSeries(Series('Buy', SeriesType.Scatter, '$',
Color.Green, ScatterMarkerSymbol.Triangle))
stockPlot.AddSeries(Series('Sell', SeriesType.Scatter, '$',
Color.Red, ScatterMarkerSymbol.TriangleDown))
stockPlot.AddSeries(Series('Liquidate', SeriesType.Scatter, '$',
Color.Blue, ScatterMarkerSymbol.Diamond))
self.AddChart(stockPlot)
def OnData(self, data):
global close_price
# Warming up data
if not data.ContainsKey(self.bit) and not self.rsi.IsReady and not self.slow.IsReady and not self.fast.IsReady and not self.str:
return
# Defining price of bitcoin
price = self.Securities[self.bit].Close
# Defining Delta
#delta = self.fast.Current.Value - self.slow.Current.Value
self.Plot("Trade Plot", "Price", price)
self.Plot("Trade Plot", "DEMA", self.dema.Current.Value)
self.Plot("Trade Plot", "MOM1", self.mom1.Current.Value)
self.Plot("Trade Plot", "MOM2", self.mom2.Current.Value)
# Getting into trades
if not self.Portfolio.Invested:
if self.mom2 == 0:
# Buy Long Order
self.SetHoldings(self.bit, 0.9)
self.Plot("Trade Plot", "Buy", price)
close_price = self.str.Current.Value
#self.Debug("Bought 5 shares at -> " + str(self.Securities[self.bit].Close))
#self.Debug("This is the STR Value when buying -> " + str(self.str.Current.Value))
# Stop Loss
if self.Portfolio.Invested:
if price < close_price and self.Portfolio["BTCUSD"].AveragePrice * 0.95:
self.Liquidate(self.bit)
self.Plot("Trade Plot", "Liquidate", price)
close_price = 0
if self.Portfolio.Invested:
if self.Portfolio["BTCUSD"].AveragePrice * 1.1:
self.Liquidate(self.bit)
close_price = 0
self.Plot("Trade Plot", "Liquidate", price)
Vladimir
Antonio Tuminello,
Try this interpretation of your code.
If this is what you are looking for, please accept it.
Antonio Tuminello
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!