Elffuss BraidHub

kikocis/freqtrade public

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