Hi, I am building an algorithm that buys a specific crypto asset when the stochastic value drops below a certain number and to sell when it reaches a percentage of profitability.

I built the framework with interchangability in mind, meaning I can alternate between indicators like the stochastic, RSI, MACD, etc... I also wanted to allow myself to be able to interchange the percentage of profitability and purchase price points. This algorithm is meant to be used as a day trading tool. 

The issues I have encountered so far are as follows (as displayed in backtesting):

1. The trading algorithm is not buying or selling according to the actual crypto asset chart (I.E. some days it only makes 1 if any trades some it makes many).

2. The algorithm is giving me a frequent error message stating that there is enough assets to proceed with a trade even though it proceeds to buy and sell (just not as much as it should be).

3. It delivers the "Price is at a X% gain" message (from the debug method) everytime a limit sell is placed not when it executes. 

4. I have not been able to successfuly add a stop loss or stop market order into the algorithm because when I do, the assets are locked in the limit sell trade and cannot be used to place a market order sell. 

 

Please let me know if and how to solve any of these issues and any imporvements I should make.

Thank you in advanced!

class BasicTemplateAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 2, 15) self.SetEndDate(2021, 2, 19) self.SetCash(100) self.AddCrypto("ETHUSD", Resolution.Minute, Market.GDAX) self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash) self.sto = self.STO("ETHUSD", 14) def OnData(self, data): if not self.sto.IsReady: return if self.sto.Current.Value < 10 and self.Portfolio["ETHUSD"].Invested <= 0: self.Debug("STO is low") #self.MarketOrder("OXTUSD", 4000) self.SetHoldings("ETHUSD", 1) self.Debug("Market order was placed") close = self.Securities["ETHUSD"].Close quantity = self.CalculateOrderQuantity("ETHUSD", 0) self.LimitOrder("ETHUSD", quantity, (1 + 0.01) * close) self.Debug("Price is at a 1% gain")

 

Author