[Tutorial] Improve your freqtrade strategy with machine learning

Introduction

In the previous article, we’ve made our first personalized strategy on freqtrade. Now it’s time to see if the strategy is profitable and if it’s possible to improve it through hyperopt and machine learning.

Prerequisite

  • Basic knowledge in Python.
  • A good understanding of how freqtrade works (see documentation).

Backtest

Before starting to optimize our strategy, we need to see if it would have been profitable by the past. The process to do this with freqtrade is as follows :

  • Give a pairlist to freqtrade
  • Download data from this pairlist
  • Backtester

Place yourself in the freqtrade main folder and modify the previously created config.json file. It’s in this file that we will give the pairlist on wich the bot will work as well as the timeframe.

Fichier Config.json

For this example, I’ve chosen a one hour timeframe and selected about fifty pairs. The more pair you have in your list, the more details you’ll have on the backtest and data as well to improve your strategy.

Let’s download the data of these pairs with the following command :

freqtrade download-data -t 1h --timerange=20210101-

-t : define the timeframe for the data. (5m,1h,4h,1d).

--timerange= : Download data from 2021/01/01 until today.

We’re now ready for our first backtest !

freqtrade backtesting -s MyStrategy --timerange=20210601-20210630

Here are the bot’s results for June of 2021 :

Backtesting the strategy
Backtesting the strategy

The strategy is loosing money during June. The first sell reason is because of the stop loss, maybe too close, maybe too far, Our ROI table can also be optimized to take more profits.

Let’s see how to automate the research for optimization of our stop loss and ROI table thanks to hyperopt included in freqtrade.

What is Hyperopt ?

Hyperopt is a freqtrade’s tool that will allow us to automate the research for optimal parameters for our strategy. It is applicable on technical indicators variables but also on sell, buy and stop loss variables. It’s a very powerful tool when it’s mastered and it’s really worth your time. Hyperopt will rely on the data we have downloaded before to find the best parameters, this is why it’s important to have a lot of data.
Be aware that hyperopt takes time and it’s resource hungry. Don’t hesitate to rent a VPS to do this.

Freqtrade’s Hyperopt example

We’re ready, let’s optimize our stop loss and our ROI with the following command :

freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi stoploss --strategy MyStrategy -e 100

Hyperopt has different calculation methods depending on your strategy, modes dedicated to scalping, Sharpe ratio, Sortino ration. Be sure to chose the right one according to your strategy.

-e defines how many evaluations hyperopt will do, the more you have, the more the results will be precise. Beyond 500-1000 there will usually no longer be any changes in the results.

Hyperopt in action
Hyperopt in action

Hyperopt work is now done, we can see that it transformed our losing strategy into a winning one (since 2021-01-01) simply by modifying our ROI table and our Stop Loss. Now we just have to modify our strategy with the values provided by hyperopt and do a new backtest to see if our strategy has been improved during the month of June.

Backtest after Hyperopt
Backtest after Hyperopt

Here’s the result, our strategy is still losing but we passed from -25.55% to -11.96% !

You now have a great example of how powerful hyperopt is, all you have to do is refine your strategy automatically. Happy Trading !

[Tutorial] Improve your freqtrade strategy with machine learning Read More »

3 technical indicators that indicated to sell at the Bitcoin top

A few days ago, @cryptomonk asked on his Twitter account which technical indicators could have convinced traders to sell at the Bitcoin top in April 2021. Here is a selection of the best answers.

The RSI (Relative Strength Index) indicator

RSI divergences on high time units are particularly reliable and there was no exception during the bitcoin bull run earlier this year. From the first peak on February 21, 2021, a divergence of the RSI was visible in daily. The other two peaks, on March 13, 2021 and April 13, 2021, accentuated the divergence. In the end it was a very long bearish divergence of the RSI that we could see building up little by little over several months. The price of Bitcoin was then above $56,000.

Daily RSI chart for the BTC/USDT pair
Daily RSI for the BTC/USD pair (source: TradingView)

The MACD (Moving Average Convergence Divergence) indicator

The MACD is constructed from exponential moving averages and has two lines, the MACD and the signal line. An upward crossing of the MACD with the signal line means that we have a buy signal, and a downward crossing means that we have a sell signal. And this is exactly what was observed during the candle of the week of April 19, 2021. The price of Bitcoin was then above $48,000.

MACD chart in weekly for the BTC/USD pair
The MACD in weekly for the BTC/USD pair (source: TradingView)

The Pi Cycle Top indicator

The Pi Cycle Top is a technical indicator much less known than the two previous ones. But it has the merit of having indicated the highest points of the last 3 big bitcoin bull runs! It consists of two lines, a yellow one corresponding to a MA111, and a green one corresponding to 2MA350. It is a very long term indicator that can only be used in daily trading. An upward crossing of the yellow line with the green line indicates a sell signal. The price of Bitcoin was then over $60,000!

Pi Cycle Indicator daily chart for the BTC/USD pair
The Pi Cycle Indicator in daily on the BTC/USD pair (source: lookintobitcoin.com)

And you, which technical indicators pushed you to sell at the top of bitcoin prices? Which ones prevented you from doing so? Share them in comments so everyone can be better armed during the next bull run 😉

3 technical indicators that indicated to sell at the Bitcoin top Read More »

How to create your API keys on Coinbase Pro?

In this tutorial, we’ll see how to create API keys on Coinbase Pro to connect your Coinbase account to third-party services. These may be bitcoin trading bots like Botcrypto, but also tools related to taxation or viewing your assets.

What’s an API?

An API is a programming interface that allows you to “plug in” to an application to exchange data.

In our case, the API allows you to access a trading platform and perform various actions. It’s possible to restrict access to a third party via an API key. Example: Allow to view the funds in your Coinbase Pro account but prevent withdrawals.

How to create API keys on Coinbase Pro?

You must first create a Coinbase account and then go to Coinbase Pro.

Once connected to Coinbase Pro, click on the top right menu, then on API. You are now in front of your list of API keys.

List of Coinbase Pro API keys
List of Coinbase Pro API keys

Click on + New Api Key to open the key creation form, where you will be asked to fill in several fields.

Key creation form
Key creation form

You must choose which of your portfolios will be the target of this API key. If you have only one, leave Default Portfolio as answer.

da17ed4842a99f523ca1f24da550c854.png (668×163)

Adding a name to your key is optional but I recommend you to do it. In my case I will name it “tuto”. It’s useful to find your way around if you have several API keys.

Then check which permissions you assign to this API key. In the context of trading bots I will give him the permission to “View” to see the amount of assets in the portfolio and “Trade” to authorize trading actions (open position/buy/sell). I don’t give the “Transfer” permission because I don’t want the service I use to automate my trading to have the possibility to withdraw my money from my accounts.

A PassPhrase has been automatically generated and you can change it or keep it as is. If you don’t know what a PassPhrase is, leave the original one.

The last field is IP Whitelist if you want to restrict the use of this key to a list of IPs for more security.

Click on “Create API key” to finalize the creation of the API key.

You will surely get an authentication request via SMS or on your two factor authentication application.

Once this is done you should get a validation message for the creation of the key.

Keep carefully the private key API Secret provided. It will not be possible to retrieve it after this.

You have now succesfully created an API key!

To use this key on a service you will be asked for a public and private key. The public key is the one displayed on the card of an API key as on the previous screenshot 7ce2d5fe2ad78d9a4688d0f5af509ac6 and the private key is the API Secret you saved preciously before.

How to create your API keys on Coinbase Pro? Read More »

Everything you need to know about backtests

When you discover trading bots, you immediately want to know what the results will be. Even if it is not possible to guarantee results, we can still use tools to try to predict the behavior of a strategy. In this article, we will present backtests, one of the most well-known tools!

What is a backtest ?

A backtest is a test into the past. When we backtest a trading bot, we will test the behavior of the trading bot on the data of the last 3 days, the last 6 months, even the last 3 years with virtual funds. So there is no risk. A backtest allows us to answer the question “What would my trading bot have done if I had launched it 3 days ago, 6 months ago, 3 years ago“.

Here is an example of a backtest running on the Botcrypto platform, with the vortex-bull strategy that you can import for free from the strategy store. I have configured the backtest to test the strategy over the whole year 2020 on the bitcoin/euro pair on the Kraken trading platform. You can see at a glance the different moments when the backtest bought and sold.

Example of a backtest with the vortex-bull strategy on Botcrypto
Example of a backtest with the vortex-bull strategy on Botcrypto

Why you need to do backtests ?

Backtests provide a lot of information on the effectiveness of a strategy, and answer a number of questions:

  • Has the strategy been properly configured?
  • Is it effective during the test period?
  • What are its characteristics during the test period?

You can usually see many statistics and details of all orders. Here are the details of the previous backtest. There can be global statistics, such as profits made or success rate. You can also see the details of all orders, including the fees taken (virtually) by the exchange.

The detailed interface of the results of a backtest on Botcrypto
The detailed interface of the results of a backtest on Botcrypto

This allows you to check whether the strategy is effective during the test period. Did it take losing trades? If so, how to avoid them? Is it sensitive to fees? With this information, you can modify the strategy to improve your results.

What are the limits of backtests?

First of all, it should not be forgotten that a backtest only tests a strategy over a given period of time. The results are therefore not universal, and if your backtest took place in an uptrend, it does not give any interesting information for a downtrend. Therefore, just because a backtest of your trading bot has made +300% in the last 6 months, does not mean that your trading robot will make +300% in the next 6 months. In fact, you simply have to remember that past results are no guarantee of future results.

Moreover, backtests never completely correspond to what would have happened in reality, because they depend on factors that cannot be taken into account such as the order execution time or the spread (the price difference between the buy and sell price). All software that performs backtesting is therefore obliged to make shortcuts and simplifications. The backtest shows how everything works in theory.

These various limitations do not prevent backtests from being very useful to get an overview of the functioning and potential of a strategy.

How to make backtests?

A backtest simply consists in analyzing each candle of a given period with its strategy. Nothing prevents you from analyzing the charts by hand on TradingView to replicate how your strategy works. But most trading bots, whether ready for use, customizable or installable, allow you to do backtests almost instantaneously. This saves you a lot of time.

Obviously, if you want to backtest your own strategies, you would have to go through platforms that allow you to design strategies, such as our Botcrypto platform where no technical knowledge is required, or Freqtrade where we have written an installation and configuration tutorial.

Our tips for setting up the best backtests

Finally, here are some tips to configure the best backtests :

  • Reproduce the backtests with the conditions closest to your trading conditions to get the most relevant results. If you can set the initial backtest funds, set a realistic amount. If you can configure the fee taken by the platform, configure that as well.
  • Perform multiple backtests in different market conditions. If you’re looking to build a strategy that takes advantage of Bitcoin’s volatility, don’t settle for just one backtest. Instead, try to run several backtests, on different trends, over different periods of time, to get the most representative results possible.
  • When building a strategy, change only one parameter at a time between each backtest. This will make it easier to understand the results of the backtests.
  • And if you are satisfied with the result of your strategy, then save it, with a copy for example. This will prevent you from losing your progress in the search process.

Everything you need to know about backtests Read More »

[Tutorial] Your first trading bot with Zenbot

Introduction

Zenbot is a free and open source bitcoin and crypto trading bot. It is used in command line and relies on Node.js and MongoDB. It is a serious competitor of Freqtrade that we have already mentioned. It is used on the command line and is therefore rather reserved for confirmed users. To create trading bots without technical knowledge, visit Botcrypto!

Prerequisites

This tutorial has been realized on a Ubuntu 20.04 server.

We will need Node.js, MongoDB and git.

  • To install the various prerequisites, run the following command:

sudo apt update && sudo apt install git && sudo apt install nodejs && sudo apt install npm && sudo apt-get install build-essential mongodb

Zenbot’s installation

  • First, we will clone the git repository by executing the command below:

git clone https://github.com/deviavir/zenbot.git

  • Once the download is complete, we will go to the zenbot folder:

cd zenbot

  • Then we will install the dependencies with the following two commands:

npm install

sudo npm link

Zenbot’s configuration

Zenbot can be configured in different ways. We will create a configuration file based on the example provided.

  • Execute this command to create your conf.js configuration file.

cp conf-sample.js conf.js

You can if you want check the different possible configurations of Zenbot by opening this file but for this tutorial we will keep the basic settings.

Zenbot’s usage

We will see how to do a backtest, a test in the past.

First you can use the command ./zenbot.sh list-selector to see all available pairs.

  • To perform a backtest we will need the data of a market. We will retrieve the BTC/EUR market of Coinbase Pro over 1 day with this command: ./zenbot.sh backfill gdax.BTC-EUR –days 1.

Once the data is downloaded (this can take time), we can perform our backtest. But we will have to choose which strategy to use.

You can access the list of all preconfigured Zenbot strategies by executing the following command: ./zenbot.sh list-strategies.

For this tutorial, we will test the trend_ema strategy based on exponential moving averages.

  • ./zenbot.sh sim gdax.BTC-EUR –strategy trend_ema

After running the backtest, an HTML file starting with “sim_result_gdax.BTC-EUR” was written to Zenbot’s simulations folder. You can open it in your browser to observe the results and the behavior of your strategy with a chart and some information about the trades of the backtest. This visualization is very interesting. Mine has 4 winning trades against 6 losing trades.

Results of my backtest with Zenbot
Results of my backtest with Zenbot

With Zenbot, you can also test your strategies in real time on the market in a fictitious way.

By executing this command ./zenbot.sh trade --paper --strategy trend_ema gdax.BTC-EUR I simulate the execution of the trend_ema strategy in the BTC-EUR market of Coinbase Pro. This method is called paper trading since it is equivalent to simulating the execution of the strategy on paper.

Running the strategy simulation on Zenbot
Running the strategy simulation on Zenbot

Your initiation to Zenbot is now over! You have discovered how to create a backtest and a real-time simulation. In a future article, we will see how to create your own strategy to customize actions. And in the meantime, don’t hesitate to read our guide on trading bots to become an expert!

[Tutorial] Your first trading bot with Zenbot Read More »

[Tutorial] Create your own trading bot strategy with Freqtrade

Introduction

In our last article, we saw how to create our first trading bot with Freqtrade, but his results were not satisfactory. We will now discover how to build our own customized strategy.

Prerequisite

  • A full installation of Freqtrade, see our article.
  • Basics of technical analysis.
  • Basics in the python computer language.

Creation of a new strategy on Freqtrade

The strategies usable by Freqtrade are stored in the freqtrade/user_data/strategies folder and are python (.py) files.

To start, move to a terminal in the /freqtrade folder and activate its virtual environment with this command :

source .env/bin/activate;

Then create a new strategy called MyStrategy.

freqtrade new-strategy --strategy MyStrategy

After executing this command, a MyStrategy.py file was created in /freqtrade/user_data/strategies. It is this file that we will customize throughout this article. The final file is available at the end of the article.

Configuration of the strategy on Freqtrade

Configuring strategy settings

Open the MyStrategy.py file with a text editor. In the class, we will specify parameters that our strategy will have to respect.

We start by defining the minimal_roi, ROI meaning return on investment, which allows us to define to sell our assets at any moment of the strategy if a percentage of profit is reached independently from the rest of the strategy. For this tutorial, I have chosen a minimal_roi that at any moment of the strategy will engage a sale if the profits exceed 50%. Furthermore, if the trade has been open for more than 40 minutes, then a sale will be issued if the profits exceed 20%.

minimal_roi = {
  "40": 0.2,
  "0": 0.5
}

We are also going to set up a stop loss, to avoid having too big losses.

stoploss = -0.15

With this stop loss, if one of my trades registers a loss of more than 15%, a sell order will be issued.

We will then choose a unit of time for our bot this way (here, 5 minutes).

timeframe = '5m'
Addition of technical indicators to the strategy

To add technical indicators to the strategy, we will modify the populate_indicators function. In this tutorial, I will use the Relative Strength Index, a technical indicator that we have already discussed many times.

dataframe['rsi'] = ta.RSI(dataframe)

After adding the indicator (you can of course add more), I end this function with a dataframe return.

return dataframe
Addition of conditions of buy/sell

To add a buy condition, we need to modify the function named populate_buy_trend and then add our condition inside as well as a return of the dataframe like this.

dataframe.loc[
(
(dataframe['rsi'] < 30)
),
'buy'] = 1

return dataframe

In this example, I decide that a buy order is sent if the ROI is less than 30.

It works the same way for the sell condition. I decide that a sell order is issued when the ROI is greater than 70.

dataframe.loc[
(
(dataframe['rsi'] > 70)
),
'sell'] = 1

return dataframe

There you go! All that remains is to test our strategy. If you don’t know how to do it, I redirect you to our tutorial on how to use Freqtrade, where we presented how it works in general. This strategy is not intended to be implemented with your funds. It is very simple, and its main interest is to show you how to build your own strategy with Freqtrade. You now have all the cards in hand to create and customize your trading bots with Freqtrade! The next step is to increase the results of your strategy with an incredible freqtrade feature, Hyperopt. Happy trading!

[Tutorial] Create your own trading bot strategy with Freqtrade Read More »

Botcrypto Plugin

This article is about the API https://plugin.botcrypto.io designed to manage wallets and bots at scale on your botcrypto account.

Why a “plugin”?

This plugin API allow you to to use Botcrypto services without using the botcrypto.io website.

Therefore we offer new way to use Botcrypto.

Indeed, with this plugin you can easily add new wallets (“portfolios”) and create new bots. So for example you can automatically start a new bot when a new pair is available.

Moreover, the ability to manage wallets & bots at scale through an API offer new perspectives. You can image to do the trading of all your family on Botcrypto quite easily. 😉

How it works?

We develop and maintain the service at https://plugin.botrypto.io. You will find a documentation with the available endpoints for each version.

Each action, like “create a portfolio”, is processed like on https://botcrypto.io. So you will retrieve on the website all wallets & bots created using the plugin API.

It is not possible to manager your strategies (“automates”) yet. So you must have already a strategy on botcrypto.io to be able to create new bots. Also, it is not possible to create demo portfolio.

Disclaimer

Same restriction as Botcrypto applies and deny of service may imply your account to be ban. If your account is ban, then you also lose access to the website.

Professional are invited to contact us: support@botcrypto.io.

Please join our Discord to be updated: https://discord.gg/8xDp3fa

Botcrypto Plugin Read More »

Comparison of the best free and open source crypto trading bots

In this article, I will compare different open source crypto trading bots. Open source trading bots have several advantages. They are particularly reliable because anyone can check and correct their code. They also have many different features. They are very complete products that have nothing to envy to commercial solutions, even though they are available for free. Pretty interesting, isn’t it? The main drawback is related to the interface and the use. Generally speaking, you need fairly advanced technical knowledge to understand and deploy them.

You’ve heard about trading bots, but you’re still not sure what they are and how they work? Then go ahead and read our ultimate guide to trading bots.

For each project, the title corresponds to a link to the bot’s GitHub repository.

Zenbot

Zenbot is a command line crypto trading bot. It uses node.js and MongoDB to operate. Zenbot supports Windows/Linux /MacOS 10 (or via Docker).

Zenbot supports a large number of exchanges and offers the way via a plugin to add even more to the list. It has most of the normal and advanced features that you can ask a trading bot for.

Active developmentyes
Easy to installyes
Easy to useyes
Backtestsyes
Manual orderyes
Graphical interfaceno
Webhooksyes

Hummingbot

Hummingbot is software that allows you to create and execute customizable trading strategies on Windows/Linux/MacOS.

Hummingbot has a documentation and an academy allowing a fast and complete learning of the tool. Its installation couldn’t be easier.

Active developmentyes
Easy to installyes
Easy to useyes
Backtestsno
Manual orderno
Graphical interfaceno
Webhooksno

Gekko

Gekko is a platform for automating trading strategies in the cryptocurrency markets and can be used on the most popular operating systems (Windows, Linux and MacOS).

Gekko has a web interface which makes it easier to use, but is unfortunately no longer maintained.

Active developmentno
Easy to installno
Easy to useyes
Backtestsyes
Manual orderno
Graphical interfaceyes
Webhooksno

Freqtrade

Freqtrade is an algorithmic crypto trading software developed in python (3.6+) and supported on Windows, Linux and MacOS.

It is designed to support all major exchanges and be controlled by Telegram. It contains tools for backtesting and portfolio management as well as strategy optimization by machine learning. You can find our article on how to create your first trading robot with Freqtrade at this address.

Active developmentyes
Easy to installyes
Easy to useno
Backtestsyes
Manual orderno
Graphical interfaceno
Webhooksyes

So much for this comparison! You now know the advantages and disadvantages of the main open source trading bots for trading bitcoin and ethers. Do you know others? Have you developed your own? Tell us about it!

Comparison of the best free and open source crypto trading bots Read More »

They switched in 2020

They switched in 2020 Read More »

The 5 types of trading bots

When we start to be interested in trading bots, we realize that there are many of them with their own characteristics. In this article we will introduce you to the different categories of trading bots.

There are trading bots with very different characteristics. Explanations.

Open source trading bots

Open source trading bots are free software that you can install and configure for free. They usually offer many features and one of their strong points is customization. On the other hand, you usually need a minimum of technical knowledge to install and configure them. The configuration of the strategies is usually done with code or pseudo code, although in some cases you can download strategies from the Internet. Deployment is also to be taken into account. In general, one avoids deploying this type of software on one’s personal computer, as one would not be able to turn it off and would be dependent on one’s personal environment.

Cost : free (unless deployed on a dedicated server)
Examples : Freqtrade ([Tutorial] Your first trading bot with Freqtrade) , Zenbot, …

The source code of Freqtrade, a trading bot, on GitHub
The source code of Freqtrade, a trading bot, on GitHub

Customizable online trading bots

Many services offer customizable online trading bots. Compared to open source trading bots, you can also customize them, but you don’t have to worry about deploying them. The company takes care of their execution and maintenance in the cloud. Some are distinguished by 100% visual interfaces where you can configure and customize your trading bots without technical knowledge. This is for example what we offer at Botcrypto.

Cost : a subscription (starting at $10 per month in general) or fees

An example of a strategy customizable without technical knowledge on Botcrypto
An example of a strategy customizable without technical knowledge on Botcrypto

Ready for use online trading bots

The trading bots that we call ready for use are among the easiest to handle. Their developers have developed one or more strategies that you don’t usually know and control. Once you set up your trading platform, everything is automatic. There is no need for technical knowledge, but you must have absolute confidence in their developers since you don’t know what the applied strategy is.

Cost : a subscription (starting at $10 per month in general) or fees

Copy trading online trading bots

Copy trading consists in replicating the actions of other traders considered competent. Some companies have replicated this model with trading bots: some traders create trading bots (with or without a visual interface), others replicate these trading bots (but without knowing the behavior of the strategy). It is in fact a mix between the two previous categories, customizable trading bots and ready for use trading bots. You usually have a marketplace, where you can access all available trading bots, which are usually rated by their users.

Cost : a subscription (starting at $10 per month in general) or fees

Scams

Unfortunately, trading bots attract many investors who think they can get regular income easily. That’s why there are many scams in the world of trading bots. Avoid services that promise guaranteed performance, and be very careful!

Cost : everything 🙃

The 5 types of trading bots Read More »