Cryptocurrency Algorithmic Trading Strategies

A collection of Algorithmic Trading Strategies with easy to understand explanations of how they work and how you can begin using them today. This library will get bigger and bigger over-time.

Crypto Risk Management Tabs with Sticky Sidebar

Building Blocks Of Creating an Algo Trading Strategy

Algo Trading Strategy

The building blocks of a successful Algorithmic Trading Strategy are:

  • Universe Selection: Selecting the assets to trade, such as Bitcoin, Ethereum, etc.
  • Alpha Creation: The set of rules the algorithm follows to generate trading signals and decide entry/exit points.
  • Portfolio Construction: Deciding the proportion of the portfolio allocated to each trade.
  • Execution Model: How the algorithm executes trades, such as using market or limit orders.
  • Risk Management: A critical part of the strategy that involves setting risk limits to protect against losses.
Last updated 1 year ago

How To Apply The Strategies In This Library

Apply Strategies

One of the most popular platforms for algo trading is QuantConnect. These algorithms are designed to be used on QuantConnect. You can visit the site here: QuantConnect

Before you can trade live, you'll need to pay for a live trading node on QuantConnect, which costs around $24 a month.

Steps to go live with your strategy:

  1. Write Your Trading Plan: Write the algorithm in the QuantConnect environment. Use an example and modify it to suit your plan.
  2. Test Your Plan: Run a backtest to see how the algorithm would have performed using historical data.
  3. Check the Results: Review the backtest results and ensure they align with your expectations.
  4. Connect Your Trading Account: Link your trading account (e.g., Binance or Coinbase) to QuantConnect.
  5. Start Live Trading: Once your account is linked, go live by clicking "Go Live" in the backtest report.
Last updated 1 year ago

Strategy 1: Candlestick Trading Pattern (Hammer and Hanging Man candles)

Candlestick Trading Pattern

This strategy uses candlestick patterns like Hammer and Hanging Man for trading Bitcoin (BTC). The algorithm will trade based on these patterns' signals, which are commonly used to identify market reversals.

Learn how to implement this strategy using QuantConnect's coding environment. Below is a sample code for the algorithm that uses these candlestick patterns for decision-making.

Last updated 1 year ago

Strategy 2: Stochastic Oscillator and Bollinger Bands

Stochastic Oscillator and Bollinger Bands

This strategy applies Bollinger Bands and the Stochastic Oscillator to Ethereum (ETH). The strategy aims to detect trend reversals and breakouts based on these indicators.

Below is an example of how you would set up and use these indicators for algorithmic trading in QuantConnect:

Last updated 1 year ago

Strategy 3: Diversified Crypto Portfolio Investing with Stochastics & Bollinger Bands

Diversified Crypto Portfolio

This strategy is designed to trade a diversified portfolio of cryptocurrencies based on parameters that we define. The algorithm uses Bollinger Bands and Stochastic Oscillator to manage risk and make investment decisions across a variety of cryptocurrencies.

Last updated 1 year ago

Building Blocks Of Creating an Algo Trading Strategy

The building blocks of a successful Algorithmic Trading Strategy are:

  1. Universe Selection

This is the selection of assets that you want to trade, such as Bitcoin, Ethereum etc.

  1. Alpha Creation

This is essentially the set of rules that you want your Algorithim to follow in order to generate trading signals and enter/exit positions.

  1. Portfolio Construction

This is more important for if you're using a selection of cryptocurrencies as opposed to using only 1 cryptocurrency in your algorithm. This is the proportion of your portfolio that will be Invested by the algo per trade.

  1. Execution Model

This is how your algorithm will execute trades. For example, orders can be market orders - which will execute at the current market price, Limit orders - which will only execute if price reaches a certain level etc.

  1. Risk Management

This is one of the most important considerations for your algorithm. To explore this more please head back to the website: and visit our Risk Management section.

How To Apply The Strategies In This Library

One of the most popular platforms for algo trading is QuantConnect. These algorithms are designed to be used on Quantconnect. You can visit the site here: https://www.quantconnect.com

Before you can trade live, you will need to pay for a live trading node on Quantconnect which is around $24 a month.

How to go live with your strategy:

  1. Write Your Trading Plan: You'll start by writing an algorithm, which is just a set of rules for how you want to trade. You do this in the QuantConnect coding environment, which is like a special word processor for code. If you're new, you can start with an example and change it to fit your plan.

  2. Test Your Plan: Next, you'll run a "backtest." This is like a rehearsal for your algorithm. It tests your rules on old market data to see how they would have worked in the past. You start a backtest by clicking the "Backtest" button.

  3. Check the Results: After the backtest, you'll see a report on how your algorithm did. It shows things like how much money it made or lost, and how risky it was. Make sure you're happy with these results before you move on.

  4. Connect Your Trading Account: To start live trading, you need to tell QuantConnect about your real trading account. You do this in the "Account" section, under "Linked Brokerages". Here, you can add your trading account details. QuantConnect works with many popular trading services, like Binance and Coinbase. They have more specific guidance on their website, however if you want more guidance then get in touch with me.

  5. Start Live Trading: Once your trading account is connected, you're ready to start live trading. You do this by going to your backtest report and clicking on "Go Live".

Strategy 1: Candlestick Trading Pattern (Hammer and Hanging Man candles)

The hammer candlestick pattern is characterized by a small body located at the top of the candle, with a long lower shadow. It resembles a hammer, hence its name. This pattern typically forms after a downtrend and suggests a potential bullish reversal. It indicates that despite initial selling pressure, buyers have stepped in and pushed the price back up. This can be interpreted as a signal of strength and a possible shift in market sentiment.

Similarly, the hanging man candlestick pattern also has a small body located at the top of the candle, but with a long lower shadow. However, the hanging man pattern forms during an uptrend and signals a potential bearish reversal. It suggests that despite initial buying pressure, sellers have emerged and pushed the price back down. This can be seen as a sign of weakness and a possible shift in market sentiment.

The Algorithm:

Initialization: Here, you're setting up the parameters for the algorithm.

The self.SetStartDate(2023, 1, 1) and self.SetEndDate(2023, 7, 23) lines set the time frame for the backtest to the first half of 2023.

self.SetCash(self._cash) sets the initial cash amount to $100,000. This can be changed to whatever you want. I have used $100k just to get a thorough backtesting result.

self.AddCrypto(self.ticker, Resolution.Minute, Market.GDAX,).Symbol adds the Bitcoin/USD trading pair from the GDAX market to the algorithm. This essentially calls the BTC/USD pair from Coinbase, which is known as GDAX on Quantconnect. The resolution can be changed from Minute to Hourly, Daily etc, however because we are using candlesticks, we want to use a short time frame so that the algorithim trades frequently.

The self.CandlestickPatterns.Hammer and self.CandlestickPatterns.HangingMan lines are preparing the algorithm to recognize the Hammer and Hanging Man candlestick patterns.

Risk Management: This section adds risk management to the algorithm.

The TrailingStopRiskManagementModel(0.03) will sell the asset if its price drops by 3% from the highest value since the asset was bought. This is effectively a stop loss, and I have used 3% because Candle patterns tend to produce a lot of false signals so at 3% - losses are minimised.

The MaximumDrawdownPercentPerSecurity(0.05) will stop trading if the portfolio value drops by 5% from the highest value it has ever been.

OnData: This is the core logic of the algorithm. It runs every time new data comes in (in this case, every Minute).

If a Hanging Man pattern is identified, the algorithm will short sell the BTC/USD trading pair using 100% of the portfolio - This is what the -1 represents (self.SetHoldings(self.ticker, -1)).

If a Hammer pattern is identified, the algorithm will buy the BTC/USD trading pair using 100% of the portfolio(self.SetHoldings(self.ticker, 1)).

If the unrealized profit from the current holdings is above 5%, the algorithm will take profit from the trade and close it (self.Liquidate(self.ticker)).

Plotting: The algorithm plots two charts: "Strategy Equity" and "Candlestick Patterns".

The "Strategy Equity" chart shows the growth of the portfolio value and the relative price of BTC/USD.

The "Candlestick Patterns" chart shows when Hammer and Hanging Man patterns have been identified.

Backtesting the performance of the Algorithm:

Strategy 2: Stochastic Oscillator and Bollinger Bands

This algorithm is designed to trade the cryptocurrency Ethereum (ETH) based on Bollinger Bands and Stochastic Oscillator indicators. However it can also be used for any cryptocurrency.

Bollinger Bands are a popular technical analysis tool that consists of a middle band (typically a simple moving average) and two outer bands that represent the standard deviations from the middle band. The purpose of Bollinger Bands is to provide a statistical representation of price volatility. When the price is closer to the outer bands, it suggests higher volatility, while prices near the middle band indicate lower volatility. Traders often use Bollinger Bands to identify potential price reversals, breakouts, and overbought or oversold conditions.

The Stochastic Oscillator is another widely used technical indicator that measures the momentum of price movements. It compares the closing price of an asset to its price range over a given period. The oscillator consists of two lines: %K (fast line) and %D (slow line). The values range from 0 to 100, with readings above 80 considered overbought and readings below 20 considered oversold.

Traders use the Stochastic Oscillator to identify potential trend reversals, divergences, and overbought/oversold conditions. When used together, Bollinger Bands and Stochastic Oscillator provide valuable insights to traders. Bollinger Bands help identify periods of high or low volatility, while the Stochastic Oscillator confirms overbought or oversold conditions. This combination allows traders to seek potential trend reversals when the price reaches the outer bands and the Stochastic Oscillator signals extremes, or to confirm breakouts and trend continuations during periods of low volatility. By leveraging the complementary information from these indicators, traders can enhance their analysis and make more informed trading decisions.

The Algorithim:

Initialization: In this section, you're setting up the parameters for the algorithm.

self.SetStartDate(2016, 6, 18) and self.SetEndDate(2023, 6, 19) set the time frame for the backtest from mid-June 2016 to mid-June 2023.

self.SetCash(self._cash) sets the initial cash amount to $100,000.

self.AddCrypto(self.ticker, Resolution.Daily) adds the Ethereum/USD trading pair to the algorithm.

Set the Technical Indicators (Stochastic & Bollinger Bands):

self.BB(self.ticker, 20, 0.3, MovingAverageType.Simple, Resolution.Daily) sets up a Bollinger Bands indicator with a period of 20 days and a standard deviation of 0.3, calculated on the closing prices of the ETH/USD trading pair.

self.STO(self.ticker, 8, 5, 5, Resolution.Daily) sets up a Stochastic Oscillator with a period of 8 days, smoothing period K of 5, and smoothing period D of 5.

Risk Management: This section adds risk management to the algorithm.

TrailingStopRiskManagementModel(0.06) will sell the asset if its price drops by 6% from the highest value since the asset was bought.

MaximumDrawdownPercentPerSecurity(0.05) will stop trading if the portfolio value drops by 5% from the highest value it has ever been.

OnData: This is the core logic of the algorithm. It runs every time new data comes in (in this case, daily).

If the closing price of the Ethereum/USD pair is above the upper Bollinger Band and the Stochastic Oscillator is above 50, the algorithm will buy the ETH/USD trading pair (self.SetHoldings(self.ticker, 1)).

If the closing price of the Ethereum/USD pair is above the middle Bollinger Band and below the upper Bollinger Band, the algorithm will sell the ETH/USD trading pair (self.Liquidate(self.ticker)).

Plotting: The algorithm plots three charts: "Strategy Equity", "Bollinger", and "Stochastic".

The "Strategy Equity" chart shows the growth of the portfolio value and the relative price of ETH/USD.

The "Bollinger" chart shows the three Bollinger Bands (upper, middle, lower) and the closing price of the ETH/USD trading pair.

The "Stochastic" chart shows the three lines of the Stochastic Oscillator: fast stochastic, stochastic %K, and stochastic %D.

Backtesting the performance of the Algorithm:

The strategy has done extremely well over the 7 year backtesting period. However before using it, you need to backtest it over different time periods to see how it would've performed in the short,medium and long-term.

Strategy 3: Diversified Crypto Portfolio Investing with Stochastics & Bollinger Bands

This strategy is similar to Strategy 2, however strategy 2 is only made to handle 1 Crypto asset. This strategy will create and trade a portfolio of Crypto assets based on parameters that we set.

The Algorithim:

Initialization: In this section, you're setting up the parameters for the algorithm.

self.SetStartDate(2016, 6, 18) and self.SetEndDate(2023, 7, 23) set the time frame for the backtest from mid-June 2016 to mid-June 2023.

self.SetCash(self._cash) sets the initial cash amount to $100,000.

AddUniverse piece of code allows us to add all the Cryptocurrencies from Binance that will meet the parameters that we set later on.

Risk Management: This section adds risk management to the algorithm.

TrailingStopRiskManagementModel(0.03) will sell the asset if its price drops by 3%. This is effectively a stop-loss.

OnData: This is the core logic of the algorithm. It runs every time new data comes in (in this case, daily).

self.Bolband[symbol] = self.BB(symbol, 10, 0.45, MovingAverageType.Simple, Resolution.Daily) sets up a Bollinger Bands indicator with a period of 10 days and a standard deviation of 0.45.

self.sto[symbol] = self.STO(symbol, 8, 5, 5, Resolution.Daily) sets up a Stochastic Oscillator with a period of 8 days, smoothing period K of 5, and smoothing period D of 5.

The code follows this logic:

1) The Algo will buy and hold crypto unless the conditions for a short position are met. Therefore this a bullish Investing strategy more suited for those that want to hold their crypto assets for the long-term and do not mind short-term price fluctuations. The algo Invests equally in all of the assets that meet the $60m trading volume criteria and rebalances daily.

2) If the price of the crypto asset is above the upper Bollinger band & the Stochastics value is greater than 80 then it will trigger a short position using 100% of the portfolio.The algo Invests equally in all of the assets that meet the $60m trading volume criteria and rebalances daily.

If the unrealized profit from the current holdings is above 10%, the algorithm will take profit from the trade and close it (self.Liquidate(self.ticker)).

Plotting: The algorithm plots three charts: "Strategy Equity", "Bollinger", and "Stochastic".

The "Strategy Equity" chart shows the growth of the portfolio value.

The "Bollinger" chart shows the three Bollinger Bands (upper, middle, lower) and the closing price .

The "Stochastic" chart shows the three lines of the Stochastic Oscillator: fast stochastic, stochastic %K, and stochastic %D.

Backtesting the performance of the Algorithm:

Backtesting results

Backtesting metrics

Here is the portfolio of crypto assets that the algorithim selected based of the criteria we set earlier: