This algo was working just fine before, but I made an edit that I didn't like and changed it back to how it was. Now it takes trades out of order, Clearly I want it to exit whatever it is holding before it tries to enter the new trade. I think it has to do with the api not registering my accounts holdings. I don't know how to report an api bug. anything would help thanks.
class CalmAsparagusJackal(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2016, 10, 21)
self.SetCash(202)
self.SetBenchmark(SecurityType.Crypto, "BTCUSD")
self.AddCrypto("BTCUSD", Resolution.Daily)
self.AddCrypto("ETHUSD", Resolution.Daily)
self.btcma = self.EMA("BTCUSD", 2, Resolution.Daily)
self.mama = self.EMA("ETHUSD", 2, Resolution.Daily)
self.baseline = self.ALMA("BTCUSD", 50, Resolution.Daily)
self.btcma.Updated += self.btcmaUpdated
self.btcWin = RollingWindow[IndicatorDataPoint](20)
self.mama.Updated += self.mamaUpdated
self.mamaWin = RollingWindow[IndicatorDataPoint](20)
self.action = False
self.SetWarmUp(200, Resolution.Daily)
def btcmaUpdated(self, sender, updated):
self.btcWin.Add(updated)
def mamaUpdated(self, sender, updated):
self.mamaWin.Add(updated)
def OnData(self, data):
if not self.baseline.IsReady:
return
bp1 = self.btcWin[19].Value
bp2 = self.btcWin[0].Value
mp1 = self.mamaWin[19].Value
mp2 = self.mamaWin[0].Value
btc_pct = ((bp2 - bp1)/bp1)
eth_pct = ((mp2 - mp1)/mp1)
dif_1 = eth_pct - btc_pct
dif_2 = btc_pct - eth_pct
if self.Portfolio["BTCUSD"].Quantity == 0 and self.Portfolio["ETHUSD"].Quantity == 0:
if self.Securities["BTCUSD"].Close > self.baseline.Current.Value*1.01:
if dif_1 >= .01:
self.SetHoldings("ETHUSD", 1)
elif dif_2 >= .01:
self.SetHoldings("BTCUSD", 1)
else: return
else: return
else:
if self.Securities["BTCUSD"].Close > self.baseline.Current.Value:
if dif_1 >= .05:
limitPrice = round(self.Securities["BTCUSD"].Price * 1.01, 2)
quantity = self.Portfolio.CashBook["BTC"].Amount
self.MarketOrder("BTCUSD", -quantity)
elif dif_2 >= .05:
limitPrice = round(self.Securities["ETHUSD"].Price * 1.01, 2)
quantity = self.Portfolio.CashBook["ETH"].Amount
self.MarketOrder("ETHUSD", -quantity)
else: return
else:
quantitye = self.Portfolio.CashBook["ETH"].Amount
self.MarketOrder("ETHUSD", -quantitye)
quantityb = self.Portfolio.CashBook["BTC"].Amount
self.MarketOrder("BTCUSD", -quantityb)
Louis Szeto
Hi Joshua
Please attached the original and new backtests, as well as telling us their corresponding LEAN version (could be found at the beginning of the backtest Log), for further assistance. Thanks!
Best
Louis Szeto
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.
Joshua Hughes
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!