Unlock 4450% Profit with Algorithm Trading on Cryptocurrency: A Freqtrade Case Study

Introduction to algorithmic trading and its benefits

What algorithmic trading is and how it can be used in the context of crypto futures trading

Algorithmic trading, also known as automated or black-box trading, refers to the use of computer programs to execute trades automatically based on predefined rules or algorithms. These algorithms can be designed to analyze market conditions, identify trading opportunities, and execute trades in a rapid and systematic way that may be difficult or impossible for a human trader to do manually.

In the context of crypto futures trading, algorithmic trading can be used to execute trades on futures contracts for various cryptocurrencies. The algorithms used to trade crypto futures can be based on a wide range of factors, such as technical indicators, fundamental analysis, news events, or even artificial intelligence.

Some of the benefits of using algorithmic trading for crypto futures include:

Speed: Algorithmic trading allows for trades to be executed much faster than manual trading, which can be particularly useful in fast-moving markets.

Consistency: Algorithms can be designed to follow a strict set of rules, which can help to ensure that trades are executed consistently and without emotional bias.

Scalability: Algorithmic trading can be used to trade a large number of contracts simultaneously, which can be difficult or impossible to do manually.

Improved risk management: Algorithms can be designed to incorporate risk management rules, such as stop-loss orders, which can help to mitigate potential losses.

Overall, algorithmic trading can be a powerful tool for traders who want to take advantage of opportunities in the crypto futures market in a more automated and systematic way. However, it’s important to carefully design and test trading algorithms to ensure that they are effective and appropriate for the market conditions.

Introduction to the freqtrade platform

Freqtrade is an open-source platform for algorithmic crypto trading. It is designed to allow users to easily create and backtest trading strategies, and then execute them on a live exchange. Freqtrade is written in Python and is built on top of the ccxt library, which provides access to a wide range of cryptocurrency exchanges.

Here are some key features of the freqtrade platform:

  1. Strategy optimization: Freqtrade includes a feature called “Hyperopt” that allows users to optimize their trading strategies by searching for the optimal combination of parameters.
  2. Backtesting: Freqtrade includes a backtesting feature that allows users to simulate trades using historical data. This can be useful for evaluating the potential performance of a trading strategy before using it in live trading.
  3. Live trading: Freqtrade also includes a live trading feature that allows users to execute trades on a real exchange. This can be useful for testing and validating trading strategies in real-time market conditions.
  4. Customization: Freqtrade is designed to be highly customizable, allowing users to create and modify their own trading strategies using a wide range of indicators and rules.
  5. Exchange support: Freqtrade is built on top of the ccxt library, which provides access to a wide range of cryptocurrency exchanges. This allows users to trade on multiple exchanges using the same platform.
  6. Community support: Freqtrade has an active community of users who contribute to the development of the platform and provide support to one another. This can be a useful resource for users who have questions or need help with the platform.
  7. Documentation: Freqtrade has extensive documentation that provides users with information on how to use the platform and its various features.

Overall, these features make freqtrade a powerful and flexible tool for traders who want to automate their trading strategies and take advantage of opportunities in the crypto market.

However, it’s important to note that algorithmic trading carries inherent risks, and users should carefully evaluate the potential risks and rewards before using the platform.

What is Short Trading and Long Trading in Futures Market

In the futures market, “short” and “long” refer to the direction of a trade. A short trade is one in which the trader sells a futures contract, while a long trade is one in which the trader buys a futures contract.

When a trader is “short” a futures contract, they are essentially betting that the price of the underlying asset will decline. To enter a short position, the trader must first borrow the underlying asset from someone else and then sell it on the market. If the price of the asset does indeed go down, the trader can then buy it back at the lower price, return it to the original owner, and pocket the difference as profit.

On the other hand, if a trader is “long” a futures contract, they are betting that the price of the underlying asset will rise. To enter a long position, the trader simply buys a futures contract, with the hope that they will be able to sell it for a higher price in the future. If the price does indeed go up, the trader can then sell the contract at the higher price and make a profit.

It’s important to note that both short and long positions involve some level of risk. If the price of the underlying asset moves in the opposite direction of the trader’s prediction, they can incur losses. As such, it’s important for traders to carefully consider the potential risks and rewards of both short and long positions before entering into a trade.

How Leverage works and Factors to consider while using Leverage during Trades

In the context of futures trading, leverage refers to the ability to control a large value of an asset using a smaller amount of capital. This is typically done through the use of margin, which allows traders to open positions with a smaller upfront investment than would be required to buy or sell the underlying asset outright.

For example, let’s say a trader wants to enter a long position on a futures contract for a particular asset, but the contract has a value of $100,000. If the trader has only $10,000 in capital, they may not have enough money to buy the contract outright. However, if the exchange allows for a 10:1 leverage ratio, the trader could open a position by putting up just $10,000 as margin, and the exchange would lend them the remaining $90,000 to complete the trade.

Using leverage can allow traders to take on larger positions than they would be able to afford without it, which can potentially increase the potential profits (or losses) of a trade. However, leverage also increases the risk of a trade, as the potential losses can also be magnified.

There are a few factors that traders should consider when deciding whether and how to use leverage:

  1. Risk appetite: Traders with a higher risk appetite may be more comfortable using larger amounts of leverage, while those who are more risk-averse may prefer to use less leverage or none at all.
  2. Trading strategy: Different trading strategies may be more or less suitable for leveraging, depending on the level of risk involved and the trader’s goals.
  3. Market conditions: The level of leverage that is appropriate for a trade may also depend on the current market conditions, such as the level of volatility or the overall trend of the market.
  4. Trading capital: Traders should also consider their available capital when deciding how much leverage to use, as they will need to have sufficient margin to cover any potential losses.

In general, it’s important for traders to carefully evaluate the potential risks and rewards of using leverage and to use it responsibly, as it can significantly impact the outcome of a trade.

Setting up freqtrade for crypto futures trading

  1. There are lot of tutorials about how to connect Freqtrade using docker in a containerized environment. You can refer to any of the many Youtube tutorials on the same.
  2. Here, Our main agenda is to show case the backtest and forward test results of the algorithm trading on freqtrade, so, I will focus on that more.
  3. If there is a lot of demand and requests in comments for a tutorial on how to setup freqtrade and run your own strategies if requested, I will add that in forth coming article. Thank you

Resources:

or

or

I’m giving reference only.

Backtesting a trading strategy with freqtrade

Backtesting is the process of simulating trades using historical market data to evaluate the performance of a trading strategy. Freqtrade includes a backtesting feature that allows users to backtest their trading strategies by specifying a range of dates and a set of market data to use in the simulation.

To backtest a trading strategy with freqtrade, you will need to follow these steps:

  1. Create a configuration file: Freqtrade requires a configuration file to specify the details of your crypto futures exchange account and your desired trading parameters. To create a configuration file, copy the sample configuration file provided in the freqtrade repository to a new file called “config.json”. Then, edit the file to specify your exchange credentials and desired trading parameters.
  2. Prepare your market data: Freqtrade requires a set of market data to use in the backtest. This data should be in the form of a CSV file with columns for the date, open price, high price, low price, close price, and volume of the asset being traded. You can obtain this data from a variety of sources, such as a cryptocurrency exchange or a market data provider.
  3. Run the backtest: Once you have your configuration file and market data ready, you can run the backtest by executing the following command:
freqtrade backtesting --config config.json --strategy MyStrategy --datadir data/

Replace “MyStrategy” with the name of your strategy function and “data/” with the directory where your market data is stored. This will run the backtest using the settings specified in your configuration file and the market data provided.

  1. Review the results: Once the backtest is complete, freqtrade will generate a report with information on the performance of your strategy. This report will include metrics such as the profit/loss, the number of trades executed, and the win/loss ratio of the strategy. You can use this information to evaluate the performance of your strategy and make any necessary adjustments.

By investing 1000 USDT, (1 USD approximately equal to 1 USDT with 1–2% variance)

for a period of 703 days (from January 1st 2021 to December 8th 2022)

with maximum open trades at any given point of time being 4

maximum stake in each trade entry being around 150 USDT,

has given a Profit of 4453% Profit return on investment (ROI).

The Absolute Draw-down mentioned from results is at — 6.84%

Daily Win to Lose Ratio is at 518 days of WIN, 188 Days loss and 0 Days of Draw

Average Daily profit is at6.33% per day

Daily Average Trades is 44 approximate

Market Returns Have been (if you buy and hold Bitcoin (BTCUSDT) for the above mentioned period the returns are mentioned here, instead of trading) — 48.32%

Forward testing a trading strategy with freqtrade

Forward testing is the process of executing a trading strategy on live market data to evaluate its performance in real-time market conditions. Freqtrade includes a live trading feature that allows users to forward test their trading strategies by executing trades on a real exchange.

To forward test a trading strategy with freqtrade, you will need to follow these steps:

  1. Create a configuration file: Freqtrade requires a configuration file to specify the details of your crypto futures exchange account and your desired trading parameters. To create a configuration file, copy the sample configuration file provided in the freqtrade repository to a new file called “config.json”. Then, edit the file to specify your exchange credentials and desired trading parameters.
  2. Enable live trading: In order to execute trades on a real exchange, you will need to set the “dry_run” option in your configuration file to “False”. This will enable live trading and allow freqtrade to place orders on the exchange.
  3. Run freqtrade: Once you have your configuration file set up, you can start the live trading feature by executing the following command:
freqtrade live --config config.json

This will start freqtrade using the settings specified in your configuration file and begin executing trades on the exchange.

  1. Monitor the trades: As freqtrade executes trades, it will log the details of each trade to the console. You can use this information to monitor the performance of your strategy in real-time and make any necessary adjustments.
  2. Review the results: Once you have finished forward testing your strategy, you can review the overall performance by looking at the profit/loss and other metrics generated by freqtrade. This will allow you to evaluate the performance of your strategy and make any necessary adjustments.

If you set the “dry_run” option in your configuration file to “True” and run freqtrade with this configuration, the platform will simulate trades without actually executing them on the exchange. This is known as “dry run” mode.

There are a few advantages to using dry run mode when testing a trading strategy:

  1. It allows you to test your strategy without risking real funds: Because the trades are not executed on the exchange, you will not be at risk of losing any money if your strategy performs poorly. This can be useful for testing and fine-tuning your strategy without incurring any real losses.
  2. It can save time: Dry run mode allows you to quickly test your strategy and see how it would have performed under different market conditions. This can be more efficient than waiting for trades to execute on the exchange and can allow you to iterate more quickly on your strategy development.
  3. It can help you debug your strategy: If you encounter any errors or issues when testing your strategy, dry run mode can make it easier to identify and troubleshoot them. Because the trades are not being executed on the exchange, you can more easily see what is happening behind the scenes and debug any issues that arise.

Overall, dry run mode can be a useful tool for testing and developing trading strategies without incurring real losses or spending a lot of time waiting for trades to execute.

Trading results for 1 week of running bot on dry run mode
Individual trades profit and loss, overall performance of each asset, daily profit/loss returns and Bot performance overall are given here

Individual trades profit and loss, overall performance of each cryptocurrency asset, daily profit/loss returns and Bot performance overall are given here.

We can pause, resume, stop bot from running and the dashboard provides individual login credentials to secure.

People who invest in bots can hold the assets in their personal wallet without sending them to the 2nd party. You provide us a API key which will have rights to trade but won’t have any rights to withdraw the holding money. (This creates security, safety of assets and avoid any cyber attacks as a whole)

People who like to create their own bot and start running trades for gaining profits can also initiate the process through their personal account from any exchange, as freqtrade is connected with CCXT which has access to over 70+ crypto trading platform, it becomes easy for anyone across the world/globe to run the strategy and get amazing results.

Can Check Live Trades and Results on Telegram 24/7:

telegram integration with freqtrade for live trade results, analysis of stats, profit, daily performance, live enter exit trades and lot more

We can setup telegram bot with our freqtrade startegy easily by providing “chat_id” and “bot token” from telegram to our “config.json” file. The setup can help us in monitoring, controlling all our trades without need to open web portal.

Strategy I used Here:

I have used total of 5 key indicators in which 3 are special indicators that I have developed myself for the strategy, namely

Coral Trend Indicator, Chandelier Exit and STC Indicator. The more common indicator used is EMA, ADX.

Combined with volume indicator.

Coral Trend Indicator:

The “Coral Trend Indicator” is a trend-following indicator that uses a combination of exponential moving averages (EMAs) and the Commodity Channel Index (CCI) to identify trends and potential reversal points

This code imports the necessary libraries (pandas and numpy) and defines a function called coral_trend() that takes a DataFrame of cryptocurrency data (with a “close” column) and the EMA period, CCI period, and CCI threshold as inputs. The function first calculates the fast and slow exponential moving averages (EMAs) of the cryptocurrency and stores them in new columns called “ema_fast” and “ema_slow”, respectively. It then calculates the Commodity Channel Index (CCI) of the cryptocurrency and stores it in a new column called “cci”.

The function then determines the trend based on the EMAs and CCI, and stores it in a new column called “coral_trend”.

The coral_trend() function determines the trend by using the np.where() function to set the value of the “coral_trend” column based on the following conditions:

If the fast EMA is greater than the slow EMA and the CCI is less than the negative CCI threshold, then the trend is set to 1 (indicating an uptrend).

If the fast EMA is less than the slow EMA and the CCI is greater than the positive CCI threshold, then the trend is set to -1 (indicating a downtrend).

Otherwise, the trend is set to 0 (indicating no trend or a neutral market).

The coral_trend() function then returns the modified DataFrame with the “coral_trend” column added.

Chandelier Exit:

The “Chandelier Exit” technical indicator, also known as the “ATR Trailing Stop”, is a volatility-based stop loss indicator that adjusts the stop loss level based on the average true range (ATR) of a cryptocurrency.

This code imports the necessary libraries (pandas and numpy) and defines a function called chandelier_exit() that takes a DataFrame of cryptocurrency data (with columns for “high”, “low”, and “close”) and the ATR period and ATR multiplier as inputs. The function first calculates the ATR of the cryptocurrency and stores it in a new column called “atr”. It then calculates the Chandelier Exit (ATR Trailing Stop) by subtracting the ATR multiplied by the ATR multiplier from the high price and stores it in a new column called “chandelier_exit”.

STC Indicator:

The stc_indicator() function takes a DataFrame of cryptocurrency data (with a “close” column) and the MACD fast period, MACD slow period, MACD signal period, Stochastic Oscillator K period, and Stochastic Oscillator D period as inputs. It then calculates the MACD and the Stochastic Oscillator of the cryptocurrency and stores them in new columns called “macd” and “stoch_k”, respectively. It also calculates the MACD signal line and the Stochastic Oscillator D line

The stc_indicator() function then determines the trend based on the MACD and Stochastic Oscillator using the np.where() function. The trend is stored in a new column called “stc_trend”. If the MACD is greater than the MACD signal line and the Stochastic Oscillator K is greater than the Stochastic Oscillator D, then the trend is set to 1 (indicating an uptrend). If the MACD is less than the MACD signal line and the Stochastic Oscillator K is less than the Stochastic Oscillator D, then the trend is set to -1 (indicating a downtrend). Otherwise, the trend is set to 0 (indicating no trend or a neutral market).

Tips for improving the performance of a trading strategy with freqtrade

Here are a few tips for improving the performance of a trading strategy with freqtrade:

  1. Use historical data to evaluate your strategy: Before using your strategy in live trading, it’s important to test it using a range of historical market data to see how it performs under different market conditions. Freqtrade includes a backtesting feature that allows you to do this by simulating trades using historical data. By testing your strategy on a variety of data, you can get a better sense of its strengths and weaknesses and make any necessary adjustments.
  2. Optimize your strategy’s parameters: Many trading strategies have a set of parameters that can be adjusted to optimize their performance. Freqtrade includes a feature called “Hyperopt” that allows you to optimize your strategy’s parameters by searching for the combination that produces the best results. By optimizing your strategy’s parameters, you can improve its performance and increase the chances of success in live trading.
  3. Test your strategy in different market conditions: Different market conditions can have a big impact on the performance of a trading strategy. To get a better understanding of how your strategy will perform in different conditions, it’s a good idea to test it in a variety of markets, including both bull and bear markets. This will give you a sense of how your strategy behaves under different circumstances and allow you to make any necessary adjustments.
  4. Monitor your trades and adjust your strategy as needed: As you use your strategy in live trading, it’s important to monitor the performance of your trades and adjust your strategy as needed. This can help you identify any problems or weaknesses in your strategy and make adjustments to improve its performance. Some things you might want to consider when monitoring your trades include:

. The win/loss ratio: This is the percentage of trades that are profitable versus those that are unprofitable. A high win/loss ratio is generally a good sign, but it’s important to keep in mind that past performance is no guarantee of future results.

· The profit/loss: This is the overall gain or loss from your trades. It’s important to pay attention to this metric to see how your strategy is performing over time.

· The drawdown: This is the maximum loss from a series of trades. A high drawdown can indicate that your strategy is taking on too much risk, so it’s important to keep an eye on this metric and adjust your risk management techniques as needed.

By monitoring your trades and adjusting your strategy as needed, you can improve the performance of your strategy and increase your chances of success in the market.

5. Usage of different time period candle sticks and advantages: Candlestick charts are a type of chart that is commonly used in technical analysis to visualize the price action of an asset over time. Each candlestick on the chart represents a specific time period, and the chart is composed of a series of these candlesticks. The time period for each candlestick can vary, with common periods being 1 minute, 5 minutes, 15 minutes, 30 minutes, 1 hour, 4 hours, and 1 day.

The choice of time period for the candlesticks can have a big impact on the appearance and interpretation of the chart. For example, a chart with 1-minute candlesticks will show a lot of detail and may be more suited for short-term trading, while a chart with 4-hour candlesticks will show less detail and may be more suited for longer-term trading.

There are a few advantages to using different time periods for candlesticks:

  1. It allows you to see different time frames: By using different time periods, you can view the same asset at different time frames and get a sense of how it is performing over different time horizons. This can be useful for traders who are looking to trade at different scales, such as scalping, day trading, or swing trading.
  2. It can help you identify trends: Different time periods can reveal different trends in the market. For example, a chart with 1-minute candlesticks may show a lot of short-term fluctuations, while a chart with 4-hour candlesticks may show longer-term trends. By looking at different time periods, you can get a better sense of the overall direction of the market and identify trends that may not be apparent on other time frames.
  3. It can help you manage risk: By using different time periods, you can tailor your risk management to the time frame you are trading. For example, if you are trading at a short-term time frame, you may want to use a tighter stop loss to protect against rapid price movements, while if you are trading at a longer-term time frame, you may be able to use a wider stop loss without increasing your risk.

While doing forward testing, it is crucial to monitor results for every 100 trades. How many profit to loss trades happened, what is winning %, what is the maximum draw down that happened. While creating a strategy, total Maximum Number of trades and Maximum amount to enter a trade has to be clear. Also, test your strategy on multiple timeframes from 1m, 5m, 15m, 30m, 1h, 4h, 12h, 1d time frames. This will give you overall idea of how your strategy works at different time intervals. Keep optimzing your strategy till you get profits for 500+ trades, also run dry run tests for 2 months before comfirming if your strategy is profitable or not.

Overall, using different time periods for candlesticks can be a useful tool for traders who want to analyze and trade the market at different scales. It’s important to experiment with different time periods and find the one that works best for your trading style and goals.

Conclusion

  1. Freqtrade is an amazing platform to do cryptocurrency algorithm trading which can run for 24/7, 365 days with multiple assets or chosen limited assets as configured by the user.
  2. We can setup number of trades limit, amount to enter a trade, stop-loss, take profit, trailing stop-loss, strategy to enter trades and exit them, can do both spot trading and futures trading, can use leverage and lot more features.
  3. People who are interested to build own bot or who would like to invest in our pre-built cryptocurrency bots can contact me on patreon or other given social networks given by me below.
  4. Algorithm trading can be profitable and less stress free if proper setup and trading strategies are built. There is no 1 gurantee trading strategy that will work wonderful during all market conditions, so we have to create minimum of 2–3 trading bots that can sustain any market condition. (up trend market or down trend market or side way trend market).
  5. In conclusion, algorithmic trading on cryptocurrency using the freqtrade platform can be an effective way to generate profit in the market. By setting up freqtrade with the right configuration and strategy, traders can automate their trades and take advantage of market movements to generate consistent returns. As we have seen in this case study, it is possible to achieve a profit of 4450% using algorithmic trading with freqtrade. However, it’s important to keep in mind that past performance is no guarantee of future results and that trading carries inherent risks. By carefully testing and monitoring their strategies, traders can increase their chances of success and make informed decisions about their trading activities.

Thank you Readers.

Regards,

Puranam Pradeep Picasso

Linkedin — https://www.linkedin.com/in/puranampradeeppicasso/

Patreon — https://patreon.com/pppicasso

Facebook — https://www.facebook.com/puranam.p.picasso/

Twitter — https://twitter.com/picasso_999

--

--

Puranam Pradeep Picasso - ImbueDesk Profile

Algorithmic Trader, AI/ML & Crypto Enthusiast, Certified Blockchain Architect, Certified Lean Six SIgma Green Belt, Certified SCRUM Master and Entrepreneur