Skip to content

Commit 39b57b9

Browse files
committed
ENH: Add parameter Backtest.plot(plot_trades=)
Closes #647
1 parent d7eaa45 commit 39b57b9

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

backtesting/_plotting.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def plot(*, results: pd.Series,
166166
indicators: List[_Indicator],
167167
filename='', plot_width=None,
168168
plot_equity=True, plot_return=False, plot_pl=True,
169-
plot_volume=True, plot_drawdown=False,
169+
plot_volume=True, plot_drawdown=False, plot_trades=True,
170170
smooth_equity=False, relative_equity=True,
171171
superimpose=True, resample=True,
172172
reverse_indicators=True,
@@ -609,7 +609,8 @@ def __eq__(self, other):
609609
_plot_superimposed_ohlc()
610610

611611
ohlc_bars = _plot_ohlc()
612-
_plot_ohlc_trades()
612+
if plot_trades:
613+
_plot_ohlc_trades()
613614
indicator_figs = _plot_indicators()
614615
if reverse_indicators:
615616
indicator_figs = indicator_figs[::-1]

backtesting/backtesting.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ def _mp_task(backtest_uuid, batch_index):
15541554

15551555
def plot(self, *, results: pd.Series = None, filename=None, plot_width=None,
15561556
plot_equity=True, plot_return=False, plot_pl=True,
1557-
plot_volume=True, plot_drawdown=False,
1557+
plot_volume=True, plot_drawdown=False, plot_trades=True,
15581558
smooth_equity=False, relative_equity=True,
15591559
superimpose: Union[bool, str] = True,
15601560
resample=True, reverse_indicators=False,
@@ -1593,6 +1593,9 @@ def plot(self, *, results: pd.Series = None, filename=None, plot_width=None,
15931593
If `plot_drawdown` is `True`, the resulting plot will contain
15941594
a separate drawdown graph section.
15951595
1596+
If `plot_trades` is `True`, the stretches between trade entries
1597+
and trade exits are marked by hash-marked tractor beams.
1598+
15961599
If `smooth_equity` is `True`, the equity graph will be
15971600
interpolated between fixed points at trade closing times,
15981601
unaffected by any interim asset volatility.
@@ -1651,6 +1654,7 @@ def plot(self, *, results: pd.Series = None, filename=None, plot_width=None,
16511654
plot_pl=plot_pl,
16521655
plot_volume=plot_volume,
16531656
plot_drawdown=plot_drawdown,
1657+
plot_trades=plot_trades,
16541658
smooth_equity=smooth_equity,
16551659
relative_equity=relative_equity,
16561660
superimpose=superimpose,

backtesting/test/_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ def test_params(self):
650650
plot_return=True,
651651
plot_pl=False,
652652
plot_drawdown=True,
653+
plot_trades=False,
653654
superimpose=False,
654655
resample='1W',
655656
smooth_equity=False,

0 commit comments

Comments
 (0)