freqtrade_origin/docs/bot-optimization.md

153 lines
5.5 KiB
Markdown
Raw Normal View History

2018-01-02 02:17:10 +00:00
# Bot Optimization
This page explains where to customize your strategies, and add new
indicators.
2018-01-02 02:17:10 +00:00
## Table of Contents
2018-01-18 07:06:37 +00:00
- [Install a custom strategy file](#install-a-custom-strategy-file)
- [Customize your strategy](#change-your-strategy)
2018-01-02 02:17:10 +00:00
- [Add more Indicator](#add-more-indicator)
2018-01-18 07:06:37 +00:00
- [Where is the default strategy](#where-is-the-default-strategy)
Since the version `0.16.0` the bot allows using custom strategy file.
## Install a custom strategy file
This is very simple. Copy paste your strategy file into the folder
`user_data/strategies`.
2018-03-25 14:42:20 +00:00
Let assume you have a class called `AwesomeStrategy` in the file `awesome-strategy.py`:
2018-01-18 07:06:37 +00:00
1. Move your file into `user_data/strategies` (you should have `user_data/strategies/awesome-strategy.py`
2018-03-25 14:42:20 +00:00
2. Start the bot with the param `--strategy AwesomeStrategy` (the parameter is the class name)
2018-01-18 07:06:37 +00:00
```bash
2018-03-25 14:42:20 +00:00
python3 ./freqtrade/main.py --strategy AwesomeStrategy
2018-01-18 07:06:37 +00:00
```
2018-01-02 02:17:10 +00:00
## Change your strategy
2018-01-18 07:06:37 +00:00
The bot includes a default strategy file. However, we recommend you to
use your own file to not have to lose your parameters every time the default
2018-01-18 07:06:37 +00:00
strategy file will be updated on Github. Put your custom strategy file
into the folder `user_data/strategies`.
2018-01-02 02:17:10 +00:00
2018-01-18 07:06:37 +00:00
A strategy file contains all the information needed to build a good strategy:
- Buy strategy rules
- Sell strategy rules
- Minimal ROI recommended
- Stoploss recommended
- Hyperopt parameter
2018-01-02 02:17:10 +00:00
2018-03-24 21:28:42 +00:00
The bot also include a sample strategy called `TestStrategy` you can update: `user_data/strategies/test_strategy.py`.
You can test it with the parameter: `--strategy TestStrategy`
2018-01-18 07:06:37 +00:00
```bash
2018-03-24 21:28:42 +00:00
python3 ./freqtrade/main.py --strategy AwesomeStrategy
2018-01-18 07:06:37 +00:00
```
2018-03-27 16:39:49 +00:00
### Specify custom strategy location
If you want to use a strategy from a different folder you can pass `--strategy-path`
```bash
python3 ./freqtrade/main.py --strategy AwesomeStrategy --strategy-path /some/folder
```
2018-01-18 07:06:37 +00:00
**For the following section we will use the [user_data/strategies/test_strategy.py](https://github.com/gcarq/freqtrade/blob/develop/user_data/strategies/test_strategy.py)
file as reference.**
### Buy strategy
Edit the method `populate_buy_trend()` into your strategy file to
update your buy strategy.
Sample from `user_data/strategies/test_strategy.py`:
2018-01-02 02:17:10 +00:00
```python
2018-01-18 07:06:37 +00:00
def populate_buy_trend(self, dataframe: DataFrame) -> DataFrame:
2018-01-02 02:17:10 +00:00
"""
Based on TA indicators, populates the buy signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
dataframe.loc[
(
(dataframe['adx'] > 30) &
2018-01-18 07:06:37 +00:00
(dataframe['tema'] <= dataframe['blower']) &
(dataframe['tema'] > dataframe['tema'].shift(1))
2018-01-02 02:17:10 +00:00
),
'buy'] = 1
return dataframe
```
### Sell strategy
2018-01-18 07:06:37 +00:00
Edit the method `populate_sell_trend()` into your strategy file to
update your sell strategy.
2018-01-02 02:17:10 +00:00
2018-01-18 07:06:37 +00:00
Sample from `user_data/strategies/test_strategy.py`:
2018-01-02 02:17:10 +00:00
```python
2018-01-18 07:06:37 +00:00
def populate_sell_trend(self, dataframe: DataFrame) -> DataFrame:
2018-01-02 02:17:10 +00:00
"""
Based on TA indicators, populates the sell signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
dataframe.loc[
(
(dataframe['adx'] > 70) &
2018-01-18 07:06:37 +00:00
(dataframe['tema'] > dataframe['blower']) &
(dataframe['tema'] < dataframe['tema'].shift(1))
2018-01-02 02:17:10 +00:00
),
'sell'] = 1
return dataframe
```
## Add more Indicator
2018-01-18 07:06:37 +00:00
As you have seen, buy and sell strategies need indicators. You can add
more indicators by extending the list contained in
the method `populate_indicators()` from your strategy file.
2018-01-02 02:17:10 +00:00
Sample:
```python
def populate_indicators(dataframe: DataFrame) -> DataFrame:
"""
Adds several different TA indicators to the given DataFrame
"""
dataframe['sar'] = ta.SAR(dataframe)
dataframe['adx'] = ta.ADX(dataframe)
stoch = ta.STOCHF(dataframe)
dataframe['fastd'] = stoch['fastd']
dataframe['fastk'] = stoch['fastk']
dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband']
dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)
dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
dataframe['mfi'] = ta.MFI(dataframe)
dataframe['rsi'] = ta.RSI(dataframe)
dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)
dataframe['ao'] = awesome_oscillator(dataframe)
macd = ta.MACD(dataframe)
dataframe['macd'] = macd['macd']
dataframe['macdsignal'] = macd['macdsignal']
dataframe['macdhist'] = macd['macdhist']
hilbert = ta.HT_SINE(dataframe)
dataframe['htsine'] = hilbert['sine']
dataframe['htleadsine'] = hilbert['leadsine']
dataframe['plus_dm'] = ta.PLUS_DM(dataframe)
dataframe['plus_di'] = ta.PLUS_DI(dataframe)
dataframe['minus_dm'] = ta.MINUS_DM(dataframe)
dataframe['minus_di'] = ta.MINUS_DI(dataframe)
return dataframe
```
2018-01-18 07:06:37 +00:00
**Want more indicators example?**
Look into the [user_data/strategies/test_strategy.py](https://github.com/gcarq/freqtrade/blob/develop/user_data/strategies/test_strategy.py).
2018-01-20 08:18:55 +00:00
Then uncomment indicators you need.
2018-01-18 07:06:37 +00:00
### Where is the default strategy?
The default buy strategy is located in the file
[freqtrade/default_strategy.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/strategy/default_strategy.py).
2018-01-02 02:17:10 +00:00
## Next step
Now you have a perfect strategy you probably want to backtesting it.
2018-01-03 07:59:14 +00:00
Your next step is to learn [How to use the Backtesting](https://github.com/gcarq/freqtrade/blob/develop/docs/backtesting.md).