Elffuss BraidHub

kikocis/freqtrade public

develop · 12.7 KiBRenderedRawPermalink
1# Plotting
2
3This page explains how to plot prices, indicators and profits.
4
5## Installation / Setup
6
7Plotting modules use the Plotly library. You can install / upgrade this by running the following command:
8
9``` bash
10pip install -U -r requirements-plot.txt
11```
12
13## Plot price and indicators
14
15The `freqtrade plot-dataframe` subcommand shows an interactive graph with three subplots:
16
17* Main plot with candlestics and indicators following price (sma/ema)
18* Volume bars
19* Additional indicators as specified by `--indicators2`
20
21![plot-dataframe](assets/plot-dataframe.png)
22
23Possible arguments:
24
25```
26usage: freqtrade plot-dataframe [-h] [-v] [--logfile FILE] [-V] [-c PATH]
27 [-d PATH] [--userdir PATH] [-s NAME]
28 [--strategy-path PATH] [-p PAIRS [PAIRS ...]]
29 [--indicators1 INDICATORS1 [INDICATORS1 ...]]
30 [--indicators2 INDICATORS2 [INDICATORS2 ...]]
31 [--plot-limit INT] [--db-url PATH]
32 [--trade-source {DB,file}] [--export EXPORT]
33 [--export-filename PATH]
34 [--timerange TIMERANGE] [-i TIMEFRAME]
35 [--no-trades]
36
37optional arguments:
38 -h, --help show this help message and exit
39 -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
40 Limit command to these pairs. Pairs are space-
41 separated.
42 --indicators1 INDICATORS1 [INDICATORS1 ...]
43 Set indicators from your strategy you want in the
44 first row of the graph. Space-separated list. Example:
45 `ema3 ema5`. Default: `['sma', 'ema3', 'ema5']`.
46 --indicators2 INDICATORS2 [INDICATORS2 ...]
47 Set indicators from your strategy you want in the
48 third row of the graph. Space-separated list. Example:
49 `fastd fastk`. Default: `['macd', 'macdsignal']`.
50 --plot-limit INT Specify tick limit for plotting. Notice: too high
51 values cause huge files. Default: 750.
52 --db-url PATH Override trades database URL, this is useful in custom
53 deployments (default: `sqlite:///tradesv3.sqlite` for
54 Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for
55 Dry Run).
56 --trade-source {DB,file}
57 Specify the source for trades (Can be DB or file
58 (backtest file)) Default: file
59 --export EXPORT Export backtest results, argument are: trades.
60 Example: `--export=trades`
61 --export-filename PATH
62 Save backtest results to the file with this filename.
63 Requires `--export` to be set as well. Example:
64 `--export-filename=user_data/backtest_results/backtest
65 _today.json`
66 --timerange TIMERANGE
67 Specify what timerange of data to use.
68 -i TIMEFRAME, --timeframe TIMEFRAME, --ticker-interval TIMEFRAME
69 Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
70 --no-trades Skip using trades from backtesting file and DB.
71
72Common arguments:
73 -v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
74 --logfile FILE Log to the file specified. Special values are:
75 'syslog', 'journald'. See the documentation for more
76 details.
77 -V, --version show program's version number and exit
78 -c PATH, --config PATH
79 Specify configuration file (default:
80 `userdir/config.json` or `config.json` whichever
81 exists). Multiple --config options may be used. Can be
82 set to `-` to read config from stdin.
83 -d PATH, --datadir PATH
84 Path to directory with historical backtesting data.
85 --userdir PATH, --user-data-dir PATH
86 Path to userdata directory.
87
88Strategy arguments:
89 -s NAME, --strategy NAME
90 Specify strategy class name which will be used by the
91 bot.
92 --strategy-path PATH Specify additional strategy lookup path.
93
94```
95
96Example:
97
98``` bash
99freqtrade plot-dataframe -p BTC/ETH
100```
101
102The `-p/--pairs` argument can be used to specify pairs you would like to plot.
103
104!!! Note
105 The `freqtrade plot-dataframe` subcommand generates one plot-file per pair.
106
107Specify custom indicators.
108Use `--indicators1` for the main plot and `--indicators2` for the subplot below (if values are in a different range than prices).
109
110!!! Tip
111 You will almost certainly want to specify a custom strategy! This can be done by adding `-s Classname` / `--strategy ClassName` to the command.
112
113``` bash
114freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --indicators1 sma ema --indicators2 macd
115```
116
117### Further usage examples
118
119To plot multiple pairs, separate them with a space:
120
121``` bash
122freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH XRP/ETH
123```
124
125To plot a timerange (to zoom in)
126
127``` bash
128freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --timerange=20180801-20180805
129```
130
131To plot trades stored in a database use `--db-url` in combination with `--trade-source DB`:
132
133``` bash
134freqtrade plot-dataframe --strategy AwesomeStrategy --db-url sqlite:///tradesv3.dry_run.sqlite -p BTC/ETH --trade-source DB
135```
136
137To plot trades from a backtesting result, use `--export-filename <filename>`
138
139``` bash
140freqtrade plot-dataframe --strategy AwesomeStrategy --export-filename user_data/backtest_results/backtest-result.json -p BTC/ETH
141```
142
143### Plot dataframe basics
144
145![plot-dataframe2](assets/plot-dataframe2.png)
146
147The `plot-dataframe` subcommand requires backtesting data, a strategy and either a backtesting-results file or a database, containing trades corresponding to the strategy.
148
149The resulting plot will have the following elements:
150
151* Green triangles: Buy signals from the strategy. (Note: not every buy signal generates a trade, compare to cyan circles.)
152* Red triangles: Sell signals from the strategy. (Also, not every sell signal terminates a trade, compare to red and green squares.)
153* Cyan circles: Trade entry points.
154* Red squares: Trade exit points for trades with loss or 0% profit.
155* Green squares: Trade exit points for profitable trades.
156* Indicators with values corresponding to the candle scale (e.g. SMA/EMA), as specified with `--indicators1`.
157* Volume (bar chart at the bottom of the main chart).
158* Indicators with values in different scales (e.g. MACD, RSI) below the volume bars, as specified with `--indicators2`.
159
160!!! Note "Bollinger Bands"
161 Bollinger bands are automatically added to the plot if the columns `bb_lowerband` and `bb_upperband` exist, and are painted as a light blue area spanning from the lower band to the upper band.
162
163#### Advanced plot configuration
164
165An advanced plot configuration can be specified in the strategy in the `plot_config` parameter.
166
167Additional features when using plot_config include:
168
169* Specify colors per indicator
170* Specify additional subplots
171* Specify indicator pairs to fill area in between
172
173The sample plot configuration below specifies fixed colors for the indicators. Otherwise consecutive plots may produce different colorschemes each time, making comparisons difficult.
174It also allows multiple subplots to display both MACD and RSI at the same time.
175
176Sample configuration with inline comments explaining the process:
177
178``` python
179 plot_config = {
180 'main_plot': {
181 # Configuration for main plot indicators.
182 # Specifies `ema10` to be red, and `ema50` to be a shade of gray
183 'ema10': {'color': 'red'},
184 'ema50': {'color': '#CCCCCC'},
185 # By omitting color, a random color is selected.
186 'sar': {},
187 # fill area between senkou_a and senkou_b
188 'senkou_a': {
189 'color': 'green', #optional
190 'fill_to': 'senkou_b',
191 'fill_label': 'Ichimoku Cloud', #optional
192 'fill_color': 'rgba(255,76,46,0.2)', #optional
193 },
194 # plot senkou_b, too. Not only the area to it.
195 'senkou_b': {}
196 },
197 'subplots': {
198 # Create subplot MACD
199 "MACD": {
200 'macd': {'color': 'blue', 'fill_to': 'macdhist'},
201 'macdsignal': {'color': 'orange'}
202 },
203 # Additional subplot RSI
204 "RSI": {
205 'rsi': {'color': 'red'}
206 }
207 }
208 }
209
210```
211
212!!! Note
213 The above configuration assumes that `ema10`, `ema50`, `senkou_a`, `senkou_b`,
214 `macd`, `macdsignal`, `macdhist` and `rsi` are columns in the DataFrame created by the strategy.
215
216## Plot profit
217
218![plot-profit](assets/plot-profit.png)
219
220The `plot-profit` subcommand shows an interactive graph with three plots:
221
222* Average closing price for all pairs.
223* The summarized profit made by backtesting.
224Note that this is not the real-world profit, but more of an estimate.
225* Profit for each individual pair.
226
227The first graph is good to get a grip of how the overall market progresses.
228
229The second graph will show if your algorithm works or doesn't.
230Perhaps you want an algorithm that steadily makes small profits, or one that acts less often, but makes big swings.
231This graph will also highlight the start (and end) of the Max drawdown period.
232
233The third graph can be useful to spot outliers, events in pairs that cause profit spikes.
234
235Possible options for the `freqtrade plot-profit` subcommand:
236
237```
238usage: freqtrade plot-profit [-h] [-v] [--logfile FILE] [-V] [-c PATH]
239 [-d PATH] [--userdir PATH] [-s NAME]
240 [--strategy-path PATH] [-p PAIRS [PAIRS ...]]
241 [--timerange TIMERANGE] [--export EXPORT]
242 [--export-filename PATH] [--db-url PATH]
243 [--trade-source {DB,file}] [-i TIMEFRAME]
244
245optional arguments:
246 -h, --help show this help message and exit
247 -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
248 Limit command to these pairs. Pairs are space-
249 separated.
250 --timerange TIMERANGE
251 Specify what timerange of data to use.
252 --export EXPORT Export backtest results, argument are: trades.
253 Example: `--export=trades`
254 --export-filename PATH
255 Save backtest results to the file with this filename.
256 Requires `--export` to be set as well. Example:
257 `--export-filename=user_data/backtest_results/backtest
258 _today.json`
259 --db-url PATH Override trades database URL, this is useful in custom
260 deployments (default: `sqlite:///tradesv3.sqlite` for
261 Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for
262 Dry Run).
263 --trade-source {DB,file}
264 Specify the source for trades (Can be DB or file
265 (backtest file)) Default: file
266 -i TIMEFRAME, --timeframe TIMEFRAME, --ticker-interval TIMEFRAME
267 Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
268
269Common arguments:
270 -v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
271 --logfile FILE Log to the file specified. Special values are:
272 'syslog', 'journald'. See the documentation for more
273 details.
274 -V, --version show program's version number and exit
275 -c PATH, --config PATH
276 Specify configuration file (default:
277 `userdir/config.json` or `config.json` whichever
278 exists). Multiple --config options may be used. Can be
279 set to `-` to read config from stdin.
280 -d PATH, --datadir PATH
281 Path to directory with historical backtesting data.
282 --userdir PATH, --user-data-dir PATH
283 Path to userdata directory.
284
285Strategy arguments:
286 -s NAME, --strategy NAME
287 Specify strategy class name which will be used by the
288 bot.
289 --strategy-path PATH Specify additional strategy lookup path.
290
291```
292
293The `-p/--pairs` argument, can be used to limit the pairs that are considered for this calculation.
294
295Examples:
296
297Use custom backtest-export file
298
299``` bash
300freqtrade plot-profit -p LTC/BTC --export-filename user_data/backtest_results/backtest-result.json
301```
302
303Use custom database
304
305``` bash
306freqtrade plot-profit -p LTC/BTC --db-url sqlite:///tradesv3.sqlite --trade-source DB
307```
308
309``` bash
310freqtrade --datadir user_data/data/binance_save/ plot-profit -p LTC/BTC
311```